From 32dfbf306e95a46dae7b7714242bc25681ccaebf Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 28 Sep 2022 10:22:11 -0700 Subject: [PATCH 1/3] BUG: ArrowExtensionArray compared to invalid object not raising --- doc/source/whatsnew/v1.5.1.rst | 2 +- pandas/core/arrays/arrow/array.py | 2 +- pandas/tests/extension/test_arrow.py | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.5.1.rst b/doc/source/whatsnew/v1.5.1.rst index ee66f2f649bc2..a976810725f04 100644 --- a/doc/source/whatsnew/v1.5.1.rst +++ b/doc/source/whatsnew/v1.5.1.rst @@ -90,7 +90,7 @@ Bug fixes - Bug in :func:`assert_index_equal` for extension arrays with non matching ``NA`` raising ``ValueError`` (:issue:`48608`) - Bug in :meth:`DataFrame.pivot_table` raising unexpected ``FutureWarning`` when setting datetime column as index (:issue:`48683`) - Bug in :meth:`DataFrame.sort_values` emitting unnecessary ``FutureWarning`` when called on :class:`DataFrame` with boolean sparse columns (:issue:`48784`) -- +- Bug in :class:`.arrays.ArrowExtensionArray` with a comparison operator to an invalid object would not raise a ``NotImplementedError`` (:issue:`?`) .. --------------------------------------------------------------------------- diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index 03f734730a0f9..31b34e557531c 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -391,7 +391,7 @@ def _cmp_method(self, other, op): result[valid] = op(np.array(self)[valid], other) return BooleanArray(result, mask) else: - return NotImplementedError( + raise NotImplementedError( f"{op.__name__} not implemented for {type(other)}" ) diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index e6bf8569ef007..a6fe96847a076 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -1669,6 +1669,12 @@ def test_compare_array(self, data, comparison_op, na_value, request): with pytest.raises(type(exc)): ser.combine(other, comparison_op) + def test_invalid_other_comp(self, data, comparison_op): + with pytest.raises( + NotImplementedError, match=".* not implemented for " + ): + comparison_op(data, object()) + def test_arrowdtype_construct_from_string_type_with_unsupported_parameters(): with pytest.raises(NotImplementedError, match="Passing pyarrow type"): From 2e69cc9cf408bbfb42948c14175f885ea6f9961c Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 28 Sep 2022 10:24:50 -0700 Subject: [PATCH 2/3] pr number --- doc/source/whatsnew/v1.5.1.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.5.1.rst b/doc/source/whatsnew/v1.5.1.rst index a976810725f04..34b4e2ad76431 100644 --- a/doc/source/whatsnew/v1.5.1.rst +++ b/doc/source/whatsnew/v1.5.1.rst @@ -90,7 +90,7 @@ Bug fixes - Bug in :func:`assert_index_equal` for extension arrays with non matching ``NA`` raising ``ValueError`` (:issue:`48608`) - Bug in :meth:`DataFrame.pivot_table` raising unexpected ``FutureWarning`` when setting datetime column as index (:issue:`48683`) - Bug in :meth:`DataFrame.sort_values` emitting unnecessary ``FutureWarning`` when called on :class:`DataFrame` with boolean sparse columns (:issue:`48784`) -- Bug in :class:`.arrays.ArrowExtensionArray` with a comparison operator to an invalid object would not raise a ``NotImplementedError`` (:issue:`?`) +- Bug in :class:`.arrays.ArrowExtensionArray` with a comparison operator to an invalid object would not raise a ``NotImplementedError`` (:issue:`48833`) .. --------------------------------------------------------------------------- From c715a8808d99b15b2d006b0b9c31f1cbd55f0cec Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Thu, 29 Sep 2022 14:12:16 -0700 Subject: [PATCH 3/3] add gh ref --- pandas/tests/extension/test_arrow.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index a6fe96847a076..0c8221cb73eee 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -1670,6 +1670,7 @@ def test_compare_array(self, data, comparison_op, na_value, request): ser.combine(other, comparison_op) def test_invalid_other_comp(self, data, comparison_op): + # GH 48833 with pytest.raises( NotImplementedError, match=".* not implemented for " ):