Skip to content

Commit d77b095

Browse files
committed
PERF: Faster CategoricalIndex from categorical
1 parent f11bbf2 commit d77b095

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

doc/source/whatsnew/v0.21.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ Performance Improvements
415415
- Improved performance of instantiating :class:`SparseDataFrame` (:issue:`16773`)
416416
- :attr:`Series.dt` no longer performs frequency inference, yielding a large speedup when accessing the attribute (:issue:`17210`)
417417
- :attr:`Timestamp.microsecond` no longer re-computes on attribute access (:issue:`17331`)
418+
- Improved performance of the :class:`CategoricalIndex` for data that is already categorical dtype (:issue:`17513`)
418419

419420
.. _whatsnew_0210.bug_fixes:
420421

pandas/core/indexes/category.py

+3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ def _create_categorical(self, data, categories=None, ordered=None):
130130
-------
131131
Categorical
132132
"""
133+
if isinstance(data, ABCSeries) and is_categorical_dtype(data):
134+
data = data.values
135+
133136
if not isinstance(data, ABCCategorical):
134137
ordered = False if ordered is None else ordered
135138
from pandas.core.categorical import Categorical

0 commit comments

Comments
 (0)