8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 14b8ab7 commit 0fea48bCopy full SHA for 0fea48b
pandas/core/indexes/category.py
@@ -326,13 +326,14 @@ def __contains__(self, key):
326
hash(key)
327
if isna(key):
328
return self.isna().any()
329
- elif self.categories._defer_to_indexing: # e.g. Interval values
+ try:
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:
+ except KeyError:
335
return False
+ if is_scalar(loc):
+ return loc in self._engine
+ else: # if self.categories is IntervalIndex, loc is an array
336
+ return any(loc_ in self._engine for loc_ in loc)
337
338
@Appender(_index_shared_docs['contains'] % _index_doc_kwargs)
339
def contains(self, key):
0 commit comments