Skip to content

Commit

Permalink
REGR: Arrow backed objects not propagating exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl committed Sep 2, 2023
1 parent ac8d34d commit c6f42ca
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.1.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Fixed regressions
- Fixed regression in :meth:`.GroupBy.get_group` raising for ``axis=1`` (:issue:`54858`)
- Fixed regression in :meth:`DataFrame.__setitem__` raising ``AssertionError`` when setting a :class:`Series` with a partial :class:`MultiIndex` (:issue:`54875`)
- Fixed regression in :meth:`Series.value_counts` raising for numeric data if ``bins`` was specified (:issue:`54857`)
- Fixed regression in comparison operations for PyArrow backed columns not propagating exceptions correctly (:issue:`54944`)
- Fixed regression when comparing a :class:`Series` with ``datetime64`` dtype with ``None`` (:issue:`54870`)

.. ---------------------------------------------------------------------------
Expand Down
16 changes: 9 additions & 7 deletions pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,20 +626,22 @@ def __setstate__(self, state) -> None:

def _cmp_method(self, other, op):
pc_func = ARROW_CMP_FUNCS[op.__name__]
try:
if isinstance(other, (ArrowExtensionArray, np.ndarray, list, BaseMaskedArray)):
result = pc_func(self._pa_array, self._box_pa(other))
except (pa.lib.ArrowNotImplementedError, pa.lib.ArrowInvalid):
if is_scalar(other):
elif is_scalar(other):
try:
result = pc_func(self._pa_array, self._box_pa(other))
except (pa.lib.ArrowNotImplementedError, pa.lib.ArrowInvalid):
mask = isna(self) | isna(other)
valid = ~mask
result = np.zeros(len(self), dtype="bool")
result[valid] = op(np.array(self)[valid], other)
result = pa.array(result, type=pa.bool_())
result = pc.if_else(valid, result, None)
else:
raise NotImplementedError(
f"{op.__name__} not implemented for {type(other)}"
)
else:
raise NotImplementedError(
f"{op.__name__} not implemented for {type(other)}"
)
return ArrowExtensionArray(result)

def _evaluate_op_method(self, other, op, arrow_funcs):
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3016,6 +3016,14 @@ def test_duration_fillna_numpy(pa_type):
tm.assert_series_equal(result, expected)


def test_comparison_not_propagating_arrow_error():
# GH#54944
a = pd.Series([1 << 63], dtype="uint64[pyarrow]")
b = pd.Series([None], dtype="int64[pyarrow]")
with pytest.raises(pa.lib.ArrowInvalid, match="Integer value"):
a < b


def test_factorize_chunked_dictionary():
# GH 54844
pa_array = pa.chunked_array(
Expand Down

0 comments on commit c6f42ca

Please sign in to comment.