mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-12 06:17:21 +08:00
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:
+15
-4
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user