Revert "MAINT: AssetFinder now takes fuzzy characters on look-up, not init"

This reverts commit c16bc9f8db.  This
caused upstream breakage unexpectedly.  Postponing until we can synchronize.
This commit is contained in:
Scott Sanderson
2015-09-15 23:57:25 -04:00
parent c16bc9f8db
commit ad54eedeea
2 changed files with 9 additions and 8 deletions
+3 -3
View File
@@ -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):
+6 -5
View File
@@ -87,8 +87,9 @@ class AssetFinder(object):
# reference to an AssetFinder
PERSISTENT_TOKEN = "<AssetFinder>"
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(