Skip to content

Commit 314be85

Browse files
committed
Merge branch 'cat_eq_string' into string_dtype_tests
# Conflicts: # doc/source/whatsnew/v2.1.2.rst
2 parents 21a39ca + e07f639 commit 314be85

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

doc/source/whatsnew/v2.1.2.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Bug fixes
2525
- Fixed bug in :meth:`DataFrame.interpolate` raising incorrect error message (:issue:`55347`)
2626
- Fixed bug in :meth:`DataFrame.resample` not respecting ``closed`` and ``label`` arguments for :class:`~pandas.tseries.offsets.BusinessDay` (:issue:`55282`)
2727
- Fixed bug in :meth:`DataFrame.resample` where bin edges were not correct for :class:`~pandas.tseries.offsets.BusinessDay` (:issue:`55281`)
28+
- Fixed bug in :meth:`Categorical.equals` if other has arrow backed string dtype (:issue:`TODO`)
2829
- Fixed bug in :meth:`Series.rank` for ``string[pyarrow_numpy]`` dtype (:issue:`TODO`)
2930

3031
.. ---------------------------------------------------------------------------

pandas/core/arrays/arrow/array.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

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

628629
def _cmp_method(self, other, op):
629630
pc_func = ARROW_CMP_FUNCS[op.__name__]
630-
if isinstance(other, (ArrowExtensionArray, np.ndarray, list, BaseMaskedArray)):
631+
if isinstance(
632+
other, (ArrowExtensionArray, np.ndarray, list, BaseMaskedArray)
633+
) or isinstance(getattr(other, "dtype", None), CategoricalDtype):
631634
result = pc_func(self._pa_array, self._box_pa(other))
632635
elif is_scalar(other):
633636
try:

pandas/tests/indexes/categorical/test_equals.py

Lines changed: 6 additions & 0 deletions
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#
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)