def test_columnpanel_groupby(self): """ Test wrapping the panel groupby with ColumnPanelGroupBy """ N = 10000 data = {} data['AAPL'] = tm.fake_ohlc(N) data['AMD'] = tm.fake_ohlc(N) data['INTC'] = tm.fake_ohlc(N) cp = ColumnPanel(data) ds = cp.dataset() ds['log_returns'] = np.log(1+cp.close.pct_change()) ds['close'] = cp.close # make sure to get the panelgroupby grouped = ds.to_panel().downsample('MS', label='left', closed='left') cpgrouped = ColumnPanelGroupBy(grouped) # check if meaned is equal cmean = grouped.mean() test_mean = cpgrouped.process(lambda df: df.mean()) tm.assert_panel_equal(cmean, test_mean) bins = [-1, 0, 1] # 12-19-12 errors. # problem is that downsample returns a PanelGroupBy which doesn't have the # delegate and combine logic. test_tiled = cpgrouped.process(lambda df: df.tile(bins, 'log_returns').mean()) correct = grouped.process( lambda df: ColumnPanelMapper(df).tile(bins, 'log_returns').mean()) # this implicitly checks that inputs are panel4d tm.assert_panel4d_equal(test_tiled, correct)
def test_panel(self): """ Overview test that panel bundle saving works """ with TemporaryDirectory() as td: b.save_panel(panel, td) test = b.load_panel(td) tm.assert_panel_equal(panel, test)
data['AAPL'] = tm.fake_ohlc(N) data['AMD'] = tm.fake_ohlc(N) data['INTC'] = tm.fake_ohlc(N) cp = ColumnPanel(data) ds = cp.dataset() ds['log_returns'] = np.log(1+cp.close.pct_change()) ds['close'] = cp.close # make sure to get the panelgroupby grouped = ds.to_panel().downsample('MS', label='left', closed='left') cpgrouped = ColumnPanelGroupBy(grouped) # check if meaned is equal cmean = grouped.mean() test_mean = cpgrouped.process(lambda df: df.mean()) tm.assert_panel_equal(cmean, test_mean) bins = [-1, 0, 1] # 12-19-12 errors. # problem is that downsample returns a PanelGroupBy which doesn't have the # delegate and combine logic. test_tiled = cpgrouped.process(lambda df: df.tile(bins, 'log_returns').mean()) correct = grouped.process( lambda df: ColumnPanelMapper(df).tile(bins, 'log_returns').mean()) # this implicitly checks that inputs are panel4d tm.assert_panel4d_equal(test_tiled, correct) if __name__ == '__main__': import nose