Skip to content

Commit

Permalink
ENH: Allow AssetDBWriterFromList to consume Assets
Browse files Browse the repository at this point in the history
  • Loading branch information
StewartDouglas authored and jfkirk committed Sep 10, 2015
1 parent aa110dd commit 1d958bd
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions zipline/assets/asset_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sqlalchemy as sa

from zipline.errors import SidAssignmentError
from zipline.assets._assets import Asset

# Define a namedtuple for use with the load_data and _load_data methods
AssetData = namedtuple('AssetData', 'equities futures exchanges root_symbols')
Expand Down Expand Up @@ -540,7 +541,12 @@ def _load_data(self):
for output, data in [(_equities, self._equities),
(_futures, self._futures), ]:
for identifier in data:
if hasattr(identifier, '__int__'):
if isinstance(identifier, Asset):
sid = identifier.sid
metadata = identifier.to_dict()
metadata['asset_type'] = identifier.__class__.__name__
output[sid] = metadata
elif hasattr(identifier, '__int__'):
output[identifier.__int__()] = {'symbol': None}
else:
if self.allow_sid_assignment:
Expand All @@ -566,12 +572,13 @@ def _load_data(self):
{'root_symbol': identifier}
root_symbol_counter += 1

# Convert dictionaries to pandas.DataFrames
# 2) Convert dictionaries to pandas.DataFrames.
_equities = pd.DataFrame.from_dict(_equities, orient='index')
_futures = pd.DataFrame.from_dict(_futures, orient='index')
_exchanges = pd.DataFrame.from_dict(_exchanges, orient='index')
_root_symbols = pd.DataFrame.from_dict(_root_symbols, orient='index')

# 3) Return the data inside a named tuple.
return AssetData(equities=_equities,
futures=_futures,
exchanges=_exchanges,
Expand Down

0 comments on commit 1d958bd

Please sign in to comment.