Skip to content

Commit 7df4211

Browse files
authored
BUG: eq not implemented for categorical and arrow backed strings (#55364)
1 parent 59616c5 commit 7df4211

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

doc/source/whatsnew/v2.1.2.rst

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Fixed regressions
2222

2323
Bug fixes
2424
~~~~~~~~~
25+
- Fixed bug in :meth:`Categorical.equals` if other has arrow backed string dtype (:issue:`55364`)
2526
- Fixed bug in :meth:`DataFrame.idxmin` and :meth:`DataFrame.idxmax` raising for arrow dtypes (:issue:`55368`)
2627
- Fixed bug in :meth:`DataFrame.resample` not respecting ``closed`` and ``label`` arguments for :class:`~pandas.tseries.offsets.BusinessDay` (:issue:`55282`)
2728
- Fixed bug in :meth:`DataFrame.resample` where bin edges were not correct for :class:`~pandas.tseries.offsets.BusinessDay` (:issue:`55281`)

pandas/core/arrays/arrow/array.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
infer_dtype_from_scalar,
3636
)
3737
from pandas.core.dtypes.common import (
38+
CategoricalDtype,
3839
is_array_like,
3940
is_bool_dtype,
4041
is_integer,
@@ -631,7 +632,9 @@ def __setstate__(self, state) -> None:
631632

632633
def _cmp_method(self, other, op):
633634
pc_func = ARROW_CMP_FUNCS[op.__name__]
634-
if isinstance(other, (ArrowExtensionArray, np.ndarray, list, BaseMaskedArray)):
635+
if isinstance(
636+
other, (ArrowExtensionArray, np.ndarray, list, BaseMaskedArray)
637+
) or isinstance(getattr(other, "dtype", None), CategoricalDtype):
635638
result = pc_func(self._pa_array, self._box_pa(other))
636639
elif is_scalar(other):
637640
try:

pandas/tests/indexes/categorical/test_equals.py

+6
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,9 @@ def test_equals_multiindex(self):
8888
ci = mi.to_flat_index().astype("category")
8989

9090
assert not ci.equals(mi)
91+
92+
def test_equals_string_dtype(self, any_string_dtype):
93+
# GH#55364
94+
idx = CategoricalIndex(list("abc"), name="B")
95+
other = Index(["a", "b", "c"], name="B", dtype=any_string_dtype)
96+
assert idx.equals(other)

0 commit comments

Comments
 (0)