@@ -640,21 +640,23 @@ def _lookup_symbol_fuzzy(self, symbol, as_of_date):
640
640
options = set (options ),
641
641
)
642
642
643
- options = []
643
+ options = {}
644
644
for start , end , sid , sym in owners :
645
645
if start <= as_of_date < end :
646
646
# see which fuzzy symbols were owned on the asof date.
647
- options . append (( sid , sym ))
647
+ options [ sid ] = sym
648
648
649
649
if not options :
650
650
# no equity owned the fuzzy symbol on the date requested
651
- SymbolNotFound (symbol = symbol )
651
+ raise SymbolNotFound (symbol = symbol )
652
652
653
+ sid_keys = list (options .keys ())
654
+ # If there was only one owner, or there is a fuzzy and non-fuzzy which
655
+ # map to the same sid, return it.
653
656
if len (options ) == 1 :
654
- # there was only one owner, return it
655
- return self .retrieve_asset (options [0 ][0 ])
657
+ return self .retrieve_asset (sid_keys [0 ])
656
658
657
- for sid , sym in options :
659
+ for sid , sym in options . items () :
658
660
if sym == symbol :
659
661
# look for an exact match on the asof date
660
662
return self .retrieve_asset (sid )
@@ -663,10 +665,7 @@ def _lookup_symbol_fuzzy(self, symbol, as_of_date):
663
665
# there are no exact matches
664
666
raise MultipleSymbolsFound (
665
667
symbol = symbol ,
666
- options = set (map (
667
- compose (self .retrieve_asset , itemgetter (0 )),
668
- options ,
669
- )),
668
+ options = [self .retrieve_asset (s ) for s in sid_keys ],
670
669
)
671
670
672
671
def lookup_symbol (self , symbol , as_of_date , fuzzy = False ):
@@ -703,6 +702,10 @@ def lookup_symbol(self, symbol, as_of_date, fuzzy=False):
703
702
there are multiple candidates for the given ``symbol`` on the
704
703
``as_of_date``.
705
704
"""
705
+ if symbol is None :
706
+ raise TypeError ("Cannot lookup asset for symbol of None for "
707
+ "as of date %s." % as_of_date )
708
+
706
709
if fuzzy :
707
710
return self ._lookup_symbol_fuzzy (symbol , as_of_date )
708
711
return self ._lookup_symbol_strict (symbol , as_of_date )
0 commit comments