File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -326,16 +326,18 @@ def __contains__(self, key):
326326 hash (key )
327327 if isna (key ):
328328 return self .isna ().any ()
329- elif self . categories . _defer_to_indexing : # e.g. Interval values
329+ try :
330330 loc = self .categories .get_loc (key )
331- return np .isin (self .codes , loc ).any ()
332- elif key in self .categories :
333- return self .categories .get_loc (key ) in self ._engine
334- else :
331+ except KeyError :
335332 return False
333+ if is_scalar (loc ):
334+ return loc in self ._engine
335+ else : # if self.categories is IntervalIndex, loc is an array
336+ return any (loc_ in self ._engine for loc_ in loc )
336337
337338 @Appender (_index_shared_docs ['contains' ] % _index_doc_kwargs )
338339 def contains (self , key ):
340+ hash (key )
339341 return key in self
340342
341343 def __array__ (self , dtype = None ):
You can’t perform that action at this time.
0 commit comments