Skip to content

Commit

Permalink
Merge pull request #1585 from quantopian/pricing-data-associable
Browse files Browse the repository at this point in the history
MAiNT: Add a pricing data shared abc.
  • Loading branch information
ehebert authored Nov 8, 2016
2 parents 44b97be + 5e8faa2 commit b5d4df6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
9 changes: 6 additions & 3 deletions zipline/_protocol.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ from six import iteritems, PY2, string_types
from cpython cimport bool
from collections import Iterable

from zipline.assets import Asset, AssetConvertible, Future
from zipline.assets import (Asset,
AssetConvertible,
PricingDataAssociable,
Future)
from zipline.assets.continuous_futures import ContinuousFuture
from zipline.zipline_warnings import ZiplineDeprecationWarning

Expand Down Expand Up @@ -637,7 +640,7 @@ cdef class BarData:
last market close instead.
"""
if isinstance(fields, string_types):
single_asset = isinstance(assets, AssetConvertible)
single_asset = isinstance(assets, PricingDataAssociable)

if single_asset:
asset_list = [assets]
Expand Down Expand Up @@ -670,7 +673,7 @@ cdef class BarData:
# columns are the assets, indexed by dt.
return df
else:
if isinstance(assets, AssetConvertible):
if isinstance(assets, PricingDataAssociable):
# one asset, multiple fields. for now, just make multiple
# history calls, one per field, then stitch together the
# results. this can definitely be optimized!
Expand Down
2 changes: 2 additions & 0 deletions zipline/assets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .assets import (
AssetFinder,
AssetConvertible,
PricingDataAssociable,
)
from .asset_db_schema import ASSET_DB_VERSION
from .asset_writer import AssetDBWriter
Expand All @@ -35,6 +36,7 @@
'Future',
'AssetFinder',
'AssetConvertible',
'PricingDataAssociable',
'make_asset_array',
'CACHE_FILE_TEMPLATE'
]
14 changes: 13 additions & 1 deletion zipline/assets/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,6 @@ class AssetConvertible(with_metaclass(ABCMeta)):

AssetConvertible.register(Integral)
AssetConvertible.register(Asset)
AssetConvertible.register(ContinuousFuture)
# Use six.string_types for Python2/3 compatibility
for _type in string_types:
AssetConvertible.register(_type)
Expand All @@ -1228,6 +1227,19 @@ class NotAssetConvertible(ValueError):
pass


class PricingDataAssociable(with_metaclass(ABCMeta)):
"""
ABC for types that can be associated with pricing data.
Includes Asset, Future, ContinuousFuture
"""
pass

PricingDataAssociable.register(Asset)
PricingDataAssociable.register(Future)
PricingDataAssociable.register(ContinuousFuture)


def was_active(reference_date_value, asset):
"""
Whether or not `asset` was active at the time corresponding to
Expand Down

0 comments on commit b5d4df6

Please sign in to comment.