From 082bc4f906372ed5f1308e2e4c51e16ad7bf7c0f Mon Sep 17 00:00:00 2001 From: jfkirk Date: Wed, 16 Sep 2015 14:55:42 -0400 Subject: [PATCH] MAINT: Removes default_none from lookup_symbol --- tests/test_assets.py | 24 ++++++++++++------------ zipline/algorithm.py | 1 - zipline/assets/assets.py | 19 +++++-------------- zipline/utils/security_list.py | 13 ++++++++----- 4 files changed, 25 insertions(+), 32 deletions(-) diff --git a/tests/test_assets.py b/tests/test_assets.py index 3915c4ee..fb567053 100644 --- a/tests/test_assets.py +++ b/tests/test_assets.py @@ -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) diff --git a/zipline/algorithm.py b/zipline/algorithm.py index 76caa6fe..274643d8 100644 --- a/zipline/algorithm.py +++ b/zipline/algorithm.py @@ -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 diff --git a/zipline/assets/assets.py b/zipline/assets/assets.py index 097d12bd..f8efb1db 100644 --- a/zipline/assets/assets.py +++ b/zipline/assets/assets.py @@ -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) diff --git a/zipline/utils/security_list.py b/zipline/utils/security_list.py index 47590d17..50368b59 100644 --- a/zipline/utils/security_list.py +++ b/zipline/utils/security_list.py @@ -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)