BUG: Various bug fixes to assets.py

Bug fixes include:
	- Do not call float on tuples
	- Correct indentation
	- Do not call value() on int
	- Use fuzzy correctly
	- Use symbol for lookup
	- Ensure we raise Error
This commit is contained in:
Stewart Douglas
2015-08-13 22:58:04 -04:00
committed by jfkirk
parent 16488d9053
commit 9d313ab877
2 changed files with 20 additions and 20 deletions
+1 -1
View File
@@ -562,7 +562,7 @@ class AssetDBWriterFromList(AssetDBWriter):
output[id_counter] = {'symbol': identifier}
id_counter += 1
else:
SidAssignmentError(identifier=identifier)
raise SidAssignmentError(identifier=identifier)
exchange_counter = 0
for identifier in self._exchanges:
+19 -19
View File
@@ -294,7 +294,7 @@ class AssetFinder(object):
else:
sids = sa.select((equities_cols.sid,)).where(
equities_cols.symbol == sid,
equities_cols.symbol == symbol,
).execute().fetchall()
if len(sids) == 1:
return self._retrieve_equity(sids[0]['sid'])
@@ -309,7 +309,7 @@ class AssetFinder(object):
))
)
def lookup_symbol(self, symbol, as_of_date, fuzzy=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
@@ -318,15 +318,18 @@ class AssetFinder(object):
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 is None:
if not fuzzy:
try:
return self.lookup_symbol_resolve_multiple(symbol, as_of_date)
except SymbolNotFound:
return None
fuzzy = symbol.replace(self.fuzzy_char, '')
equities_cols = self.equities.c
candidates = sa.select((equities_cols.sid,)).where(
(equities_cols.fuzzy == fuzzy) &
@@ -402,20 +405,19 @@ class AssetFinder(object):
as_of_date = as_of_date.value
if knowledge_date is pd.NaT:
# If knowledge_date is NaT, default to using as_of_date
knowledge_date = as_of_date.value
knowledge_date = as_of_date
else:
knowledge_date = knowledge_date.value
sids = list(map(
itemgetter('sid'),
sa.select((fc_cols.sid,)).where(
(fc_cols.root_symbol == root_symbol) &
(fc_cols.notice_date >= as_of_date) &
(fc_cols.start_date <= knowledge_date),
).order_by(
fc_cols.notice_date.asc(),
).execute().fetchall()
))
sids = list(map(
itemgetter('sid'),
sa.select((fc_cols.sid,)).where(
(fc_cols.root_symbol == root_symbol) &
(fc_cols.notice_date > as_of_date) &
(fc_cols.start_date <= knowledge_date),
).order_by(
fc_cols.notice_date.asc(),
).execute().fetchall()
))
if not sids:
# Check if root symbol exists.
@@ -578,15 +580,13 @@ class AssetFinder(object):
"""
equities_cols = self.equities.c
buf = np.array(
tuple(map(
float,
tuple(
sa.select((
equities_cols.sid,
equities_cols.start_date,
equities_cols.end_date,
)).execute(),
)),
dype='<f8', # use doubles so we get NaNs
), dtype='<f8', # use doubles so we get NaNs
)
lifetimes = np.recarray(
buf=buf,