File tree 1 file changed +7
-5
lines changed
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):
326
326
hash (key )
327
327
if isna (key ):
328
328
return self .isna ().any ()
329
- elif self . categories . _defer_to_indexing : # e.g. Interval values
329
+ try :
330
330
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 :
335
332
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 )
336
337
337
338
@Appender (_index_shared_docs ['contains' ] % _index_doc_kwargs )
338
339
def contains (self , key ):
340
+ hash (key )
339
341
return key in self
340
342
341
343
def __array__ (self , dtype = None ):
You can’t perform that action at this time.
0 commit comments