API: DataFrame/Panel sources expect integer sids, not identifiers

This commit modifies the DataFrameSource and DataPanelSource to accept only Int64Indexes on the incoming data and moves the burden of mapping user identifiers to TradingAlgorithm.run().
This commit is contained in:
jfkirk
2015-06-26 16:41:38 -04:00
parent a4ce9712b8
commit 258b5ea2ca
8 changed files with 83 additions and 33 deletions
+15 -4
View File
@@ -39,7 +39,6 @@ from zipline.errors import (
UnsupportedCommissionModel,
UnsupportedOrderParameters,
UnsupportedSlippageModel,
SidNotFound,
)
from zipline.finance.trading import TradingEnvironment
@@ -461,10 +460,22 @@ class TradingAlgorithm(object):
__init__().""", UserWarning)
overwrite_sim_params = False
elif isinstance(source, pd.DataFrame):
# if DataFrame provided, wrap in DataFrameSource
source = DataFrameSource(source)
# if DataFrame provided, map columns to sids and wrap
# in DataFrameSource
copy_frame = source.copy()
copy_frame.columns = self.asset_finder.map_identifier_list_to_sids(
source.columns, source.index[0]
)
source = DataFrameSource(copy_frame)
elif isinstance(source, pd.Panel):
source = DataPanelSource(source)
# If Panel provided, map items to sids and wrap
# in DataPanelSource
copy_panel = source.copy()
copy_panel.items = self.asset_finder.map_identifier_list_to_sids(
source.items, source.major_axis[0]
)
source = DataPanelSource(copy_panel)
if isinstance(source, list):
self.set_sources(source)