コード例 #1
0
def test_append_meta(tencent: DataFrame):
    stock = StockDataFrame(tencent.iloc[:1], date_col=TIME_KEY)

    stock = stock.append(tencent)

    assert isinstance(stock, StockDataFrame)
    assert stock._cumulator._date_col == TIME_KEY
コード例 #2
0
def test_empty_df_append(tencent: DataFrame):
    stock = StockDataFrame(date_col=TIME_KEY)

    stock = stock.append(tencent)

    assert isinstance(stock, StockDataFrame)
    assert stock._cumulator._date_col == TIME_KEY
コード例 #3
0
def check_append_no_time_key(head, new, ctor_twice=False, **kwargs):
    stock = StockDataFrame(head, date_col=TIME_KEY, copy=True)

    if ctor_twice:
        stock = StockDataFrame(stock)

    # Should not raise if new contains no TIME_KEY
    stock = stock.append(new, **kwargs)

    assert isinstance(stock, StockDataFrame)
    assert not isinstance(stock.iloc[-1].name, Timestamp)

    if not ctor_twice:
        check_append_no_time_key(head, new, ctor_twice=True, **kwargs)
コード例 #4
0
def check_append(head, new, ctor_twice=False):
    stock = StockDataFrame(head, date_col=TIME_KEY, copy=True)

    if ctor_twice:
        stock = StockDataFrame(stock)

    stock = stock.append(new)

    assert isinstance(stock, StockDataFrame)
    assert TIME_KEY not in stock.columns
    assert isinstance(stock.iloc[-1].name, Timestamp)

    if not ctor_twice:
        check_append(head, new, ctor_twice=True)
コード例 #5
0
def test_drop(stock: StockDataFrame):
    origin = StockDataFrame(stock)

    stock['boll']

    name = stock.directive_stringify('boll')

    assert str(
        stock._stock_columns_info_map[name]
    ) == '<ColumnInfo boll:20,close, size:100, period:20>'  # noqa: E501

    last_boll = stock.iloc[-1][name]
    origin_last = stock.iloc[-1]

    last_index = len(origin) - 1

    stock = stock.drop([last_index])

    stock = stock.append(origin_last)
    stock['boll']

    assert stock.iloc[-1][name] == last_boll

    stock = stock.drop([last_index])

    new_last = origin_last.copy()
    new_last['open'] = 30
    new_last['high'] = 30
    new_last['low'] = 30
    new_last['close'] = 30

    stock = stock.append(new_last)

    stock['boll']

    assert stock.iloc[-1][name] != last_boll
コード例 #6
0
def test_append_invalid_type(tencent: DataFrame):
    stock = StockDataFrame(tencent, date_col=TIME_KEY, copy=True)

    with pytest.raises(TypeError, match='int'):
        stock.append(1)

    with pytest.raises(TypeError, match="list of <class 'int'>"):
        stock.append([1])

    with pytest.raises(TypeError, match="list of <class 'list'>"):
        stock.append([[]])
コード例 #7
0
def test_ma(stock):
    stock.alias('Open', 'open')

    ma = stock['ma:2']

    stock = StockDataFrame(stock)

    list_ma0 = [3.5, 4.5, 5.5, 6.5, 7.5]

    assert np.isnan(ma[0])
    assert list(ma[1:]) == list_ma0

    new = get_stock_update()

    stock = stock.append(new, ignore_index=True)
    assert isinstance(stock, StockDataFrame)

    ma2 = stock.exec('ma:2')

    assert np.isnan(ma2[0])

    assert list(ma2[1:]) == [*list_ma0, 8.5]
    assert stock['Open'][0] == 2