From ad54eedeea43b13232dac6b3bab6cdf49d9e3046 Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Tue, 15 Sep 2015 23:57:25 -0400 Subject: [PATCH] Revert "MAINT: AssetFinder now takes fuzzy characters on look-up, not init" This reverts commit c16bc9f8dba5e2579014ddabb2763f9613a0addd. This caused upstream breakage unexpectedly. Postponing until we can synchronize. --- tests/test_assets.py | 6 +++--- zipline/assets/assets.py | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/test_assets.py b/tests/test_assets.py index c4435323..d2efde6d 100644 --- a/tests/test_assets.py +++ b/tests/test_assets.py @@ -303,7 +303,7 @@ class AssetFinderTestCase(TestCase): ] ) self.env.write_data(equities_df=frame) - finder = self.env.asset_finder + finder = AssetFinder(self.env.engine, fuzzy_char='@') asset_0, asset_1, asset_2 = ( finder.retrieve_asset(i) for i in range(3) ) @@ -318,7 +318,7 @@ class AssetFinderTestCase(TestCase): # Adding an unnecessary fuzzy shouldn't matter. self.assertEqual( asset_1, - finder.lookup_symbol('test@1', as_of, fuzzy_char='@') + finder.lookup_symbol('test@1', as_of, fuzzy=True) ) # Shouldn't find this with no fuzzy_str passed. @@ -326,7 +326,7 @@ class AssetFinderTestCase(TestCase): # Should find exact match. self.assertEqual( asset_1, - finder.lookup_symbol('test1', as_of, fuzzy_char='@'), + finder.lookup_symbol('test1', as_of, fuzzy=True), ) def test_lookup_symbol_resolve_multiple(self): diff --git a/zipline/assets/assets.py b/zipline/assets/assets.py index 7f3305b7..94d8077e 100644 --- a/zipline/assets/assets.py +++ b/zipline/assets/assets.py @@ -87,8 +87,9 @@ class AssetFinder(object): # reference to an AssetFinder PERSISTENT_TOKEN = "" - def __init__(self, engine, allow_sid_assignment=True): + def __init__(self, engine, allow_sid_assignment=True, fuzzy_char=None): + self.fuzzy_char = fuzzy_char self.allow_sid_assignment = allow_sid_assignment self.engine = engine @@ -329,26 +330,26 @@ class AssetFinder(object): )) ) - def lookup_symbol(self, symbol, as_of_date, fuzzy_char=None): + def lookup_symbol(self, symbol, as_of_date, fuzzy=False): """ If a fuzzy string is provided, then we try various symbols based on the provided symbol. This is to facilitate mapping from a broker's symbol to ours in cases where mapping to the broker's symbol loses information. For example, if we have CMCS_A, but a broker has CMCSA, - when the broker provides CMCSA, it can also provide fuzzy_char='_', + when the broker provides CMCSA, it can also provide fuzzy='_', so we can find a match by inserting an underscore. """ symbol = symbol.upper() ad_value = pd.Timestamp(normalize_date(as_of_date)).value - if fuzzy_char is None: + if not fuzzy: try: return self.lookup_symbol_resolve_multiple(symbol, as_of_date) except SymbolNotFound: return None - fuzzy = symbol.replace(fuzzy_char, '') + fuzzy = symbol.replace(self.fuzzy_char, '') equities_cols = self.equities.c candidates = sa.select((equities_cols.sid,)).where(