def test_cum_append_feat_indicator(): tencent = get_1m_tencent() stock = StockDataFrame(tencent.iloc[:19], date_col=TIME_KEY, time_frame='5m').cumulate() ma = stock['ma:2'][-1] assert ma == stock.iloc[-2:]['close'].sum() / 2 stock = stock.cum_append(tencent.iloc[19:20]) assert stock._stock_columns_info_map['ma:2,close'].size == len(stock) - 1 new_ma = stock['ma:2'][-1] assert ma != new_ma stock = StockDataFrame(stock, time_frame='15m') assert stock._stock_columns_info_map['ma:2,close'].size == len(stock) stock = stock.cum_append(tencent.iloc[20:21]) assert stock._stock_columns_info_map['ma:2,close'].size == len(stock) - 1 stock = stock.cumulate() # Time frame changed, so info map should not be inherited assert 'ma:2,close' not in stock._stock_columns_info_map
def test_cum_append_from_empty(tencent): stock = StockDataFrame(date_col=TIME_KEY, time_frame='5m') for i in range(LENGTH): stock_new = stock.cum_append(tencent.iloc[i:i + 1]) assert isinstance(stock, StockDataFrame) expect_cumulated(tencent, stock, i) expect_cumulated(tencent, stock_new, i + 1) expect_cumulated( tencent, StockDataFrame(date_col=TIME_KEY, time_frame='5m').cum_append(tencent.iloc[:i + 1]), i + 1) stock = stock_new