Skip to content

Commit d3f94a4

Browse files
PERF: Categorical getitem perf (#30747)
Convert to an array earlier on. Closes #30744
1 parent 10ac3ea commit d3f94a4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pandas/core/arrays/categorical.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
)
4040
from pandas.core.dtypes.dtypes import CategoricalDtype
4141
from pandas.core.dtypes.generic import ABCIndexClass, ABCSeries
42-
from pandas.core.dtypes.inference import is_hashable
42+
from pandas.core.dtypes.inference import is_array_like, is_hashable
4343
from pandas.core.dtypes.missing import isna, notna
4444

4545
from pandas.core import ops
@@ -1998,7 +1998,10 @@ def __getitem__(self, key):
19981998
else:
19991999
return self.categories[i]
20002000

2001-
elif com.is_bool_indexer(key):
2001+
if is_list_like(key) and not is_array_like(key):
2002+
key = np.asarray(key)
2003+
2004+
if com.is_bool_indexer(key):
20022005
key = check_bool_array_indexer(self, key)
20032006

20042007
return self._constructor(

0 commit comments

Comments
 (0)