Skip to content

Commit

Permalink
BUG: eq not implemented for categorical and arrow backed strings (#55364
Browse files Browse the repository at this point in the history
)
  • Loading branch information
phofl authored Oct 3, 2023
1 parent 59616c5 commit 7df4211
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.1.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Fixed regressions

Bug fixes
~~~~~~~~~
- Fixed bug in :meth:`Categorical.equals` if other has arrow backed string dtype (:issue:`55364`)
- Fixed bug in :meth:`DataFrame.idxmin` and :meth:`DataFrame.idxmax` raising for arrow dtypes (:issue:`55368`)
- Fixed bug in :meth:`DataFrame.resample` not respecting ``closed`` and ``label`` arguments for :class:`~pandas.tseries.offsets.BusinessDay` (:issue:`55282`)
- Fixed bug in :meth:`DataFrame.resample` where bin edges were not correct for :class:`~pandas.tseries.offsets.BusinessDay` (:issue:`55281`)
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
infer_dtype_from_scalar,
)
from pandas.core.dtypes.common import (
CategoricalDtype,
is_array_like,
is_bool_dtype,
is_integer,
Expand Down Expand Up @@ -631,7 +632,9 @@ def __setstate__(self, state) -> None:

def _cmp_method(self, other, op):
pc_func = ARROW_CMP_FUNCS[op.__name__]
if isinstance(other, (ArrowExtensionArray, np.ndarray, list, BaseMaskedArray)):
if isinstance(
other, (ArrowExtensionArray, np.ndarray, list, BaseMaskedArray)
) or isinstance(getattr(other, "dtype", None), CategoricalDtype):
result = pc_func(self._pa_array, self._box_pa(other))
elif is_scalar(other):
try:
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/indexes/categorical/test_equals.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,9 @@ def test_equals_multiindex(self):
ci = mi.to_flat_index().astype("category")

assert not ci.equals(mi)

def test_equals_string_dtype(self, any_string_dtype):
# GH#55364
idx = CategoricalIndex(list("abc"), name="B")
other = Index(["a", "b", "c"], name="B", dtype=any_string_dtype)
assert idx.equals(other)

0 comments on commit 7df4211

Please sign in to comment.