Skip to content

Commit 4563203

Browse files
TomAugspurgerPingviinituutti
authored andcommitted
PERF: Use Categorical.equals in CategoricalIndex.equals (pandas-dev#24023)
1 parent 1710d82 commit 4563203

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

doc/source/whatsnew/v0.24.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,7 @@ Performance Improvements
12131213
The speed increase is both when indexing by label (using .loc) and position(.iloc) (:issue:`20395`)
12141214
Slicing a monotonically increasing :class:`CategoricalIndex` itself (i.e. ``ci[1000:2000]``)
12151215
shows similar speed improvements as above (:issue:`21659`)
1216+
- Improved performance of :meth:`CategoricalIndex.equals` when comparing to another :class:`CategoricalIndex` (:issue:`24023`)
12161217
- Improved performance of :func:`Series.describe` in case of numeric dtpyes (:issue:`21274`)
12171218
- Improved performance of :func:`pandas.core.groupby.GroupBy.rank` when dealing with tied rankings (:issue:`21237`)
12181219
- Improved performance of :func:`DataFrame.set_index` with columns consisting of :class:`Period` objects (:issue:`21582`, :issue:`21606`)

pandas/core/indexes/category.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
is_scalar)
1414
from pandas.core.dtypes.dtypes import CategoricalDtype
1515
from pandas.core.dtypes.generic import ABCCategorical, ABCSeries
16-
from pandas.core.dtypes.missing import array_equivalent, isna
16+
from pandas.core.dtypes.missing import isna
1717

1818
from pandas.core import accessor
1919
from pandas.core.algorithms import take_1d
@@ -283,7 +283,9 @@ def equals(self, other):
283283

284284
try:
285285
other = self._is_dtype_compat(other)
286-
return array_equivalent(self._data, other)
286+
if isinstance(other, type(self)):
287+
other = other._data
288+
return self._data.equals(other)
287289
except (TypeError, ValueError):
288290
pass
289291

0 commit comments

Comments
 (0)