MAINT: Removes default_none from lookup_symbol

This commit is contained in:
jfkirk
2015-09-16 14:55:42 -04:00
parent c446e7f62a
commit 082bc4f906
4 changed files with 25 additions and 32 deletions
+12 -12
View File
@@ -309,10 +309,13 @@ class AssetFinderTestCase(TestCase):
# we do it twice to catch caching bugs
for i in range(2):
self.assertIsNone(finder.lookup_symbol('test', as_of))
self.assertIsNone(finder.lookup_symbol('test1', as_of))
with self.assertRaises(SymbolNotFound):
finder.lookup_symbol('test', as_of)
with self.assertRaises(SymbolNotFound):
finder.lookup_symbol('test1', as_of)
# '@' is not a supported delimiter
self.assertIsNone(finder.lookup_symbol('test@1', as_of))
with self.assertRaises(SymbolNotFound):
finder.lookup_symbol('test@1', as_of)
# Adding an unnecessary fuzzy shouldn't matter.
for fuzzy_char in ['-', '/', '_', '.']:
@@ -333,8 +336,10 @@ class AssetFinderTestCase(TestCase):
# Try combos of looking up PRTYHRD with and without a time or fuzzy
# Both non-fuzzys get no result
self.assertIsNone(finder.lookup_symbol('PRTYHRD', None))
self.assertIsNone(finder.lookup_symbol('PRTYHRD', dt))
with self.assertRaises(SymbolNotFound):
finder.lookup_symbol('PRTYHRD', None)
with self.assertRaises(SymbolNotFound):
finder.lookup_symbol('PRTYHRD', dt)
# Both fuzzys work
self.assertEqual(0, finder.lookup_symbol('PRTYHRD', None, fuzzy=True))
self.assertEqual(0, finder.lookup_symbol('PRTYHRD', dt, fuzzy=True))
@@ -379,8 +384,7 @@ class AssetFinderTestCase(TestCase):
finder = AssetFinder(self.env.engine)
for _ in range(2): # Run checks twice to test for caching bugs.
with self.assertRaises(SymbolNotFound):
finder.lookup_symbol('non_existing', dates[0],
default_None=False)
finder.lookup_symbol('non_existing', dates[0])
with self.assertRaises(MultipleSymbolsFound):
finder.lookup_symbol('existing', None)
@@ -388,11 +392,7 @@ class AssetFinderTestCase(TestCase):
for i, date in enumerate(dates):
# Verify that we correctly resolve multiple symbols using
# the supplied date
result = finder.lookup_symbol(
'existing',
date,
default_None=False,
)
result = finder.lookup_symbol('existing', date)
self.assertEqual(result.symbol, 'EXISTING')
self.assertEqual(result.sid, i)
-1
View File
@@ -752,7 +752,6 @@ class TradingAlgorithm(object):
return self.asset_finder.lookup_symbol(
symbol_str,
as_of_date=_lookup_date,
default_None=False,
)
@api_method
+5 -14
View File
@@ -261,16 +261,14 @@ class AssetFinder(object):
self._future_cache[sid] = future
return future
def lookup_symbol(self, symbol, as_of_date, default_None=True,
fuzzy=False):
def lookup_symbol(self, symbol, as_of_date, fuzzy=False):
"""
Return matching Equity of name symbol in database.
If multiple Equities are found and as_of_date is not set,
raises MultipleSymbolsFound.
If no Equity was active at as_of_date raises SymbolNotFound, or None
if default_None is true.
If no Equity was active at as_of_date raises SymbolNotFound.
"""
# Format inputs
@@ -337,10 +335,7 @@ class AssetFinder(object):
if sid is not None:
return self._retrieve_equity(sid)
if default_None:
return None
else:
raise SymbolNotFound(symbol=symbol)
raise SymbolNotFound(symbol=symbol)
else:
# If this is a fuzzy look-up, check if there is exactly one match
@@ -359,10 +354,7 @@ class AssetFinder(object):
if len(sids) == 1:
return self._retrieve_equity(sids[0]['sid'])
elif not sids:
if default_None:
return None
else:
raise SymbolNotFound(symbol=symbol)
raise SymbolNotFound(symbol=symbol)
else:
raise MultipleSymbolsFound(
symbol=symbol,
@@ -477,8 +469,7 @@ class AssetFinder(object):
elif isinstance(asset_convertible, string_types):
try:
matches.append(
self.lookup_symbol(asset_convertible, as_of_date,
default_None=False)
self.lookup_symbol(asset_convertible, as_of_date)
)
except SymbolNotFound:
missing.append(asset_convertible)
+8 -5
View File
@@ -6,6 +6,8 @@ import pandas as pd
import pytz
import zipline
from zipline.errors import SymbolNotFound
DATE_FORMAT = "%Y%m%d"
zipline_dir = os.path.dirname(zipline.__file__)
@@ -70,12 +72,13 @@ class SecurityList(object):
def update_current(self, effective_date, symbols, change_func):
for symbol in symbols:
asset = self.asset_finder.lookup_symbol(
symbol,
as_of_date=effective_date
)
try:
asset = self.asset_finder.lookup_symbol(
symbol,
as_of_date=effective_date
)
# Pass if no Asset exists for the symbol
if asset is None:
except SymbolNotFound:
continue
change_func(asset.sid)