Skip to content

Commit b5424b8

Browse files
Joe JevnikScott Sanderson
authored andcommitted
BUG: fix support for non unique sid->exchange mappings.
We now take the most recent.
1 parent e3c9071 commit b5424b8

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

zipline/assets/asset_writer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def _check_symbol_mappings(df, exchanges, asset_exchange):
289289
"""
290290
mappings = df.set_index('sid')[list(mapping_columns)].copy()
291291
mappings['country_code'] = exchanges['country_code'][
292-
asset_exchange[df['sid']]
292+
asset_exchange.loc[df['sid']]
293293
].values
294294
ambigious = {}
295295

@@ -355,10 +355,10 @@ def _split_symbol_mappings(df, exchanges):
355355
mappings['sid'] = mappings.index
356356
mappings.reset_index(drop=True, inplace=True)
357357

358-
asset_exchange = df[['exchange']]
359-
asset_exchange['sid'] = df.index
360-
asset_exchange.drop_duplicates(inplace=True)
361-
asset_exchange = asset_exchange['exchange']
358+
# take the most recent sid->exchange mapping based on end date
359+
asset_exchange = df[
360+
['exchange', 'end_date']
361+
].sort_values('end_date').groupby(level=0)['exchange'].nth(-1)
362362

363363
_check_symbol_mappings(mappings, exchanges, asset_exchange)
364364
return (

0 commit comments

Comments
 (0)