Skip to content

Commit

Permalink
Merge pull request #2554 from quantopian/datashape-is-slow
Browse files Browse the repository at this point in the history
PERF: Avoid slow exception repr in blaze.
  • Loading branch information
Scott Sanderson committed Oct 4, 2019
2 parents bd3f577 + a825662 commit f0e34f8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion zipline/pipeline/loaders/blaze/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,13 @@ def _get_metadata(field, expr, metadata_expr, no_metadata_rule):
return metadata_expr

try:
return expr._child['_'.join(((expr._name or ''), field))]
# The error produced by expr[field_name] when field_name doesn't exist
# is very expensive. Avoid that cost by doing the check ourselves.
field_name = '_'.join(((expr._name or ''), field))
child = expr._child
if field_name not in child.fields:
raise AttributeError(field_name)
return child[field_name]
except (ValueError, AttributeError):
if no_metadata_rule == 'raise':
raise ValueError(
Expand Down

0 comments on commit f0e34f8

Please sign in to comment.