Skip to content

Commit 525e2ed

Browse files
phoflcbpygit
authored andcommitted
BUG: __eq__ raising for new arrow string dtype for incompatible objects (pandas-dev#56245)
1 parent 8e4f050 commit 525e2ed

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

doc/source/whatsnew/v2.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ Strings
691691
- Bug in :meth:`Series.str.replace` when ``n < 0`` for :class:`ArrowDtype` with ``pyarrow.string`` (:issue:`56404`)
692692
- Bug in :meth:`Series.str.startswith` and :meth:`Series.str.endswith` with arguments of type ``tuple[str, ...]`` for :class:`ArrowDtype` with ``pyarrow.string`` dtype (:issue:`56579`)
693693
- Bug in :meth:`Series.str.startswith` and :meth:`Series.str.endswith` with arguments of type ``tuple[str, ...]`` for ``string[pyarrow]`` (:issue:`54942`)
694+
- Bug in comparison operations for ``dtype="string[pyarrow_numpy]"`` raising if dtypes can't be compared (:issue:`56008`)
694695

695696
Interval
696697
^^^^^^^^

pandas/core/arrays/string_arrow.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
BaseStringArray,
4242
StringDtype,
4343
)
44+
from pandas.core.ops import invalid_comparison
4445
from pandas.core.strings.object_array import ObjectStringArrayMixin
4546

4647
if not pa_version_under10p1:
@@ -676,7 +677,10 @@ def _convert_int_dtype(self, result):
676677
return result
677678

678679
def _cmp_method(self, other, op):
679-
result = super()._cmp_method(other, op)
680+
try:
681+
result = super()._cmp_method(other, op)
682+
except pa.ArrowNotImplementedError:
683+
return invalid_comparison(self, other, op)
680684
if op == operator.ne:
681685
return result.to_numpy(np.bool_, na_value=True)
682686
else:

pandas/tests/series/test_logical_ops.py

+16
Original file line numberDiff line numberDiff line change
@@ -530,3 +530,19 @@ def test_int_dtype_different_index_not_bool(self):
530530

531531
result = ser1 ^ ser2
532532
tm.assert_series_equal(result, expected)
533+
534+
def test_pyarrow_numpy_string_invalid(self):
535+
# GH#56008
536+
pytest.importorskip("pyarrow")
537+
ser = Series([False, True])
538+
ser2 = Series(["a", "b"], dtype="string[pyarrow_numpy]")
539+
result = ser == ser2
540+
expected = Series(False, index=ser.index)
541+
tm.assert_series_equal(result, expected)
542+
543+
result = ser != ser2
544+
expected = Series(True, index=ser.index)
545+
tm.assert_series_equal(result, expected)
546+
547+
with pytest.raises(TypeError, match="Invalid comparison"):
548+
ser > ser2

0 commit comments

Comments
 (0)