Skip to content

Commit 0191caf

Browse files
Backport PR #55364 on branch 2.1.x (BUG: eq not implemented for categorical and arrow backed strings) (#55381)
Backport PR #55364: BUG: eq not implemented for categorical and arrow backed strings Co-authored-by: Patrick Hoefler <61934744+phofl@users.noreply.github.com>
1 parent 2201408 commit 0191caf

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
@@ -21,6 +21,7 @@ Fixed regressions
2121

2222
Bug fixes
2323
~~~~~~~~~
24+
- Fixed bug in :meth:`Categorical.equals` if other has arrow backed string dtype (:issue:`55364`)
2425
- Fixed bug in :meth:`DataFrame.idxmin` and :meth:`DataFrame.idxmax` raising for arrow dtypes (:issue:`55368`)
2526
- Fixed bug in :meth:`Index.insert` raising when inserting ``None`` into :class:`Index` with ``dtype="string[pyarrow_numpy]"`` (:issue:`55365`)
2627
-

pandas/core/arrays/arrow/array.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
from pandas.core.dtypes.cast import infer_dtype_from_scalar
3434
from pandas.core.dtypes.common import (
35+
CategoricalDtype,
3536
is_array_like,
3637
is_bool_dtype,
3738
is_integer,
@@ -628,7 +629,9 @@ def __setstate__(self, state) -> None:
628629

629630
def _cmp_method(self, other, op):
630631
pc_func = ARROW_CMP_FUNCS[op.__name__]
631-
if isinstance(other, (ArrowExtensionArray, np.ndarray, list, BaseMaskedArray)):
632+
if isinstance(
633+
other, (ArrowExtensionArray, np.ndarray, list, BaseMaskedArray)
634+
) or isinstance(getattr(other, "dtype", None), CategoricalDtype):
632635
result = pc_func(self._pa_array, self._box_pa(other))
633636
elif is_scalar(other):
634637
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)