Skip to content

Commit d3ba3ab

Browse files
TST (string dtype): fix invalid comparison error message and update test (pandas-dev#60176)
(cherry picked from commit 9ec4a91)
1 parent ce56f2e commit d3ba3ab

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

pandas/core/arrays/arrow/array.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ def _cmp_method(self, other, op):
728728
try:
729729
result[valid] = op(np_array[valid], other)
730730
except TypeError:
731-
result = ops.invalid_comparison(np_array, other, op)
731+
result = ops.invalid_comparison(self, other, op)
732732
result = pa.array(result, type=pa.bool_())
733733
result = pc.if_else(valid, result, None)
734734
else:

pandas/tests/frame/test_arithmetic.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
from pandas._config import using_string_dtype
1515

16-
from pandas.compat import HAS_PYARROW
1716
import pandas.util._test_decorators as td
1817

1918
import pandas as pd
@@ -1563,17 +1562,19 @@ def test_comparisons(self, simple_frame, float_frame, func):
15631562
with pytest.raises(ValueError, match=msg):
15641563
func(simple_frame, simple_frame[:2])
15651564

1566-
@pytest.mark.xfail(
1567-
using_string_dtype() and HAS_PYARROW, reason="TODO(infer_string)"
1568-
)
15691565
def test_strings_to_numbers_comparisons_raises(self, compare_operators_no_eq_ne):
15701566
# GH 11565
15711567
df = DataFrame(
15721568
{x: {"x": "foo", "y": "bar", "z": "baz"} for x in ["a", "b", "c"]}
15731569
)
15741570

15751571
f = getattr(operator, compare_operators_no_eq_ne)
1576-
msg = "'[<>]=?' not supported between instances of 'str' and 'int'"
1572+
msg = "|".join(
1573+
[
1574+
"'[<>]=?' not supported between instances of 'str' and 'int'",
1575+
"Invalid comparison between dtype=str and int",
1576+
]
1577+
)
15771578
with pytest.raises(TypeError, match=msg):
15781579
f(df, 0)
15791580

0 commit comments

Comments
 (0)