Skip to content

Commit 7acebe4

Browse files
Backport PR pandas-dev#54952 on branch 2.1.x (REGR: Arrow backed objects not propagating exceptions) (pandas-dev#55209)
Backport PR pandas-dev#54952: REGR: Arrow backed objects not propagating exceptions Co-authored-by: Patrick Hoefler <[email protected]>
1 parent 1ae73af commit 7acebe4

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

doc/source/whatsnew/v2.1.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Fixed regressions
2626
- Fixed regression in :meth:`Series.drop_duplicates` for PyArrow strings (:issue:`54904`)
2727
- Fixed regression in :meth:`Series.interpolate` raising when ``fill_value`` was given (:issue:`54920`)
2828
- Fixed regression in :meth:`Series.value_counts` raising for numeric data if ``bins`` was specified (:issue:`54857`)
29+
- Fixed regression in comparison operations for PyArrow backed columns not propagating exceptions correctly (:issue:`54944`)
2930
- Fixed regression when comparing a :class:`Series` with ``datetime64`` dtype with ``None`` (:issue:`54870`)
3031

3132
.. ---------------------------------------------------------------------------

pandas/core/arrays/arrow/array.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -627,20 +627,22 @@ def __setstate__(self, state) -> None:
627627

628628
def _cmp_method(self, other, op):
629629
pc_func = ARROW_CMP_FUNCS[op.__name__]
630-
try:
630+
if isinstance(other, (ArrowExtensionArray, np.ndarray, list, BaseMaskedArray)):
631631
result = pc_func(self._pa_array, self._box_pa(other))
632-
except (pa.lib.ArrowNotImplementedError, pa.lib.ArrowInvalid):
633-
if is_scalar(other):
632+
elif is_scalar(other):
633+
try:
634+
result = pc_func(self._pa_array, self._box_pa(other))
635+
except (pa.lib.ArrowNotImplementedError, pa.lib.ArrowInvalid):
634636
mask = isna(self) | isna(other)
635637
valid = ~mask
636638
result = np.zeros(len(self), dtype="bool")
637639
result[valid] = op(np.array(self)[valid], other)
638640
result = pa.array(result, type=pa.bool_())
639641
result = pc.if_else(valid, result, None)
640-
else:
641-
raise NotImplementedError(
642-
f"{op.__name__} not implemented for {type(other)}"
643-
)
642+
else:
643+
raise NotImplementedError(
644+
f"{op.__name__} not implemented for {type(other)}"
645+
)
644646
return ArrowExtensionArray(result)
645647

646648
def _evaluate_op_method(self, other, op, arrow_funcs):

pandas/tests/extension/test_arrow.py

+8
Original file line numberDiff line numberDiff line change
@@ -3072,6 +3072,14 @@ def test_duration_fillna_numpy(pa_type):
30723072
tm.assert_series_equal(result, expected)
30733073

30743074

3075+
def test_comparison_not_propagating_arrow_error():
3076+
# GH#54944
3077+
a = pd.Series([1 << 63], dtype="uint64[pyarrow]")
3078+
b = pd.Series([None], dtype="int64[pyarrow]")
3079+
with pytest.raises(pa.lib.ArrowInvalid, match="Integer value"):
3080+
a < b
3081+
3082+
30753083
def test_factorize_chunked_dictionary():
30763084
# GH 54844
30773085
pa_array = pa.chunked_array(

0 commit comments

Comments
 (0)