Esempio n. 1
0
def test_cumprod():
    for array in arrays:
        s = Stream.source(array, dtype="float")
        w = s.cumprod().rename("w")
        expected = list(pd.Series(array).cumprod())

        assert_op([w], expected)
Esempio n. 2
0
def test_neg():
    s = Stream.source([3, -4, 6, -7, 2, -6], dtype="float")

    s1 = s.neg().rename("s1")
    s2 = (-s).rename("s2")

    assert_op([s1, s2], [-3, 4, -6, 7, -2, 6])
Esempio n. 3
0
def test_float_accessor():

    s = Stream.source([1, 2, 3, 4, 5])

    w = s.float.square().rename("w")

    assert_op([w], [1, 4, 9, 16, 25])
Esempio n. 4
0
def test_log():
    for array in arrays:
        s = Stream.source(array, dtype="float")
        w = s.log().rename("w")
        expected = list(pd.Series(array).apply(np.log))

        assert_op([w], expected)
Esempio n. 5
0
def test_abs():
    s = Stream.source([3, -4, 6, -7, 2, -6], dtype="float")

    s1 = s.abs().rename("s1")
    s2 = abs(s).rename("s2")

    assert_op([s1, s2], [3, 4, 6, 7, 2, 6])
Esempio n. 6
0
def test_expanding_max():
    for array, config in product(arrays, configurations):
        s = Stream.source(array, dtype="float")
        w = s.expanding(**config).max().rename("w")
        expected = list(pd.Series(array).expanding(**config).max())

        assert_op([w], expected)
Esempio n. 7
0
def test_radd():
    # (left, right) : (float, Stream)
    s1 = 1
    s2 = Stream.source([1, 2, 3, 4, 5, 6], dtype="float")

    w = (s1 + s2).rename("w")

    assert_op([w], [2, 3, 4, 5, 6, 7])
Esempio n. 8
0
def test_rsub():
    # (left, right) : (float, Stream)
    s1 = 6
    s2 = Stream.source([1, 2, 3, 4, 5, 6], dtype="float")

    w = (s1 - s2).rename("w")

    assert_op([w], [5, 4, 3, 2, 1, 0])
Esempio n. 9
0
def test_max():

    s1 = Stream.source([-1, 2, -3, 4, -5], dtype="float")
    s2 = Stream.source([-1, 2, 3, 2, 1], dtype="float")

    w = s1.max(s2).rename("w")
    expected = [-1, 2, 3, 4, 1]

    assert_op([w], expected)
Esempio n. 10
0
def test_clamp_min():
    array = [-1, 2, -3, 4, -5]

    s = Stream.source(array, dtype="float")

    w = s.clamp_min(0).rename("w")
    expected = list(pd.Series(array).apply(lambda x: x if x > 0 else 0))

    assert_op([w], expected)
Esempio n. 11
0
def test_ffill():
    array = [-1, np.nan, -3, 4, np.nan]

    s = Stream.source(array, dtype="float")

    w = s.ffill().rename("w")
    expected = list(pd.Series(array).ffill())

    assert_op([w], expected)
Esempio n. 12
0
def test_reduce_prod():

    s1 = Stream.source([1, 2, 3, 4, 5, 6, 7], dtype="float").rename("s1")
    s2 = Stream.source([3, 6, 4, 2, 0, 4, 10], dtype="float").rename("s2")

    w = Stream.reduce([s1, s2]).prod().rename("w")

    expected = [3, 12, 12, 8, 0, 24, 70]

    assert_op([w], expected)
Esempio n. 13
0
def test_reduce_max():

    s1 = Stream.source([1, 2, 3, 4, 5, 6, 7], dtype="float").rename("s1")
    s2 = Stream.source([-3, 6, 4, 2, 0, 4, 10], dtype="float").rename("s2")

    w = Stream.reduce([s1, s2]).max().rename("w")

    expected = [1, 6, 4, 4, 5, 6, 10]

    assert_op([w], expected)
Esempio n. 14
0
def test_rmul():
    expected = [2, 4, 6, 8, 10, 12]

    # (left, right) : (Stream, Stream)
    s = Stream.source([1, 2, 3, 4, 5, 6], dtype="float")

    # (left, right) : (Stream, float)
    w = (2 * s).rename("w")

    assert_op([w], expected)
Esempio n. 15
0
def test_reduce_sum():

    s1 = Stream.source([1, 2, 3, 4, 5, 6, 7], dtype="float").rename("s1")
    s2 = Stream.source([7, 6, 5, 4, 3, 2, 1], dtype="float").rename("s2")

    w = Stream.reduce([s1, s2]).sum().rename("w")

    expected = [8, 8, 8, 8, 8, 8, 8]

    assert_op([w], expected)
Esempio n. 16
0
def test_rdiv():
    expected = [6, 3, 2, 3 / 2, 6 / 5, 1]

    # (left, right) : (Stream, Stream)
    s = Stream.source([2, 4, 6, 8, 10, 12], dtype="float")

    # (left, right) : (Stream, float)
    w = (12 / s).rename("w")

    assert_op([w], expected)
Esempio n. 17
0
def test_ewm_mean():

    array = [1, np.nan, 3, 4, 5, 6, np.nan, 7]

    s = Stream.source(array, dtype="float")

    for config in configurations:
        w = s.ewm(**config).mean().rename("w")
        expected = list(pd.Series(array).ewm(**config).mean())

        assert_op([w], expected)
Esempio n. 18
0
def test_pow():
    array = [1, -2, 3, -4, 5, -6]

    s = Stream.source(array, dtype="float")

    s1 = s.pow(3).rename("s1")
    s2 = (s**3).rename("s2")

    expected = list(pd.Series(array)**3)

    assert_op([s1, s2], expected)
Esempio n. 19
0
def test_cummax():
    for array in arrays:
        s = Stream.source(array, dtype="float")
        w = s.cummax(skipna=True).rename("w")
        expected = list(pd.Series(array).cummax(skipna=True))

        assert_op([w], expected)

    for array in arrays:
        s = Stream.source(array, dtype="float")
        w = s.cummin(skipna=False).rename("w")
        expected = list(pd.Series(array).cummin(skipna=False))

        assert_op([w], expected)
Esempio n. 20
0
def test_diff():

    for array in arrays:
        s = Stream.source(array, dtype="float")
        w = s.diff(periods=1).rename("w")
        expected = list(pd.Series(array).diff(periods=1))

        assert_op([w], expected)

    for array in arrays:
        s = Stream.source(array, dtype="float")
        w = s.diff(periods=2).rename("w")
        expected = list(pd.Series(array).diff(periods=2))

        assert_op([w], expected)
Esempio n. 21
0
def test_div():
    expected = [1, 2, 3, 4, 5, 6]

    # (left, right) : (Stream, Stream)
    s1 = Stream.source([2, 4, 6, 8, 10, 12], dtype="float")
    s2 = Stream.source([2, 2, 2, 2, 2, 2], dtype="float")

    w1 = s1.div(s2).rename("w1")
    w2 = (s1 / s2).rename("w2")

    assert_op([w1, w2], expected)

    # (left, right) : (Stream, float)
    w1 = s1.div(2).rename("w1")
    w2 = (s1 / 2).rename("w2")

    assert_op([w1, w2], expected)
Esempio n. 22
0
def test_sub():
    expected = [0, 1, 2, 3, 4, 5]

    # (left, right) : (Stream, Stream)
    s1 = Stream.source([1, 2, 3, 4, 5, 6], dtype="float")
    s2 = Stream.source([1, 1, 1, 1, 1, 1], dtype="float")

    w1 = s1.sub(s2).rename("w1")
    w2 = (s1 - s2).rename("w2")

    assert_op([w1, w2], expected)

    # (left, right) : (Stream, float)
    w1 = s1.sub(1).rename("w1")
    w2 = (s1 - 1).rename("w2")

    assert_op([w1, w2], expected)
Esempio n. 23
0
def test_pct_change():
    configs = [
        {"periods": 1, "fill_method": None},
        {"periods": 1, "fill_method": "pad"},
        {"periods": 1, "fill_method": "ffill"},
        {"periods": 2, "fill_method": None},
        {"periods": 2, "fill_method": "pad"},
        {"periods": 2, "fill_method": "ffill"},
    ]

    for array, config in product(arrays, configs):

        s = Stream.source(array, dtype="float")
        w = s.pct_change(**config).rename("w")
        expected = list(pd.Series(array).pct_change(**config))

        print(config)
        assert_op([w], expected)
Esempio n. 24
0
def test_add():

    # (left, right) : (Stream, Stream)
    s1 = Stream.source([3, -4, 6, -7, 2, -6], dtype="float")
    s2 = Stream.source([-3, 4, -6, 7, -2, 6], dtype="float")

    w1 = s1.add(s2).rename("w1")
    w2 = (s1 + s2).rename("w2")

    assert_op([w1, w2], 6 * [0])

    # (left, right) : (Stream, float)
    s1 = Stream.source([1, 2, 3, 4, 5, 6], dtype="float")
    s2 = 1

    w1 = s1.add(s2).rename("w1")
    w2 = (s1 + s2).rename("w2")

    assert_op([w1, w2], [2, 3, 4, 5, 6, 7])