Merge pull request #1715 from quantopian/missing-cf-error

Better error message for non-existent root symbol
This commit is contained in:
David Michalowicz
2017-03-16 12:02:15 -04:00
committed by GitHub
2 changed files with 13 additions and 2 deletions
+6
View File
@@ -34,6 +34,7 @@ from zipline.assets.continuous_futures import (
delivery_predicate
)
from zipline.data.minute_bars import FUTURES_MINUTES_PER_DAY
from zipline.errors import SymbolNotFound
from zipline.testing.fixtures import (
WithAssetFinder,
WithCreateBarData,
@@ -417,6 +418,11 @@ class ContinuousFuturesTestCase(WithCreateBarData,
self.assertNotEqual(cf_primary, cf_secondary)
# Assert that the proper exception is raised if the given root symbol
# does not exist.
with self.assertRaises(SymbolNotFound):
self.asset_finder.create_continuous_future('NO', 0, 'calendar')
def test_current_contract(self):
cf_primary = self.asset_finder.create_continuous_future(
'FO', 0, 'calendar')
+7 -2
View File
@@ -996,8 +996,13 @@ class AssetFinder(object):
fields = (fc_cols.exchange,)
return sa.select(fields).where(
fc_cols.root_symbol == root_symbol).execute().fetchone()[0]
exchange = sa.select(fields).where(
fc_cols.root_symbol == root_symbol).execute().scalar()
if exchange is not None:
return exchange
else:
raise SymbolNotFound(symbol=root_symbol)
def get_ordered_contracts(self, root_symbol):
try: