diff --git a/pandas/tests/extension/base/ops.py b/pandas/tests/extension/base/ops.py index 658018a7ac740..83d134161a8fb 100644 --- a/pandas/tests/extension/base/ops.py +++ b/pandas/tests/extension/base/ops.py @@ -161,7 +161,18 @@ def test_divmod_series_array(self, data, data_for_twos): self._check_divmod_op(other, ops.rdivmod, ser) def test_add_series_with_extension_array(self, data): + # Check adding an ExtensionArray to a Series of the same dtype matches + # the behavior of adding the arrays directly and then wrapping in a + # Series. + ser = pd.Series(data) + + exc = self._get_expected_exception("__add__", ser, data) + if exc is not None: + with pytest.raises(exc): + ser + data + return + result = ser + data expected = pd.Series(data + data) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/extension/json/test_json.py b/pandas/tests/extension/json/test_json.py index d5002a8fb91bf..710ba830f5591 100644 --- a/pandas/tests/extension/json/test_json.py +++ b/pandas/tests/extension/json/test_json.py @@ -313,11 +313,6 @@ def test_arith_frame_with_scalar(self, data, all_arithmetic_operators, request): request.node.add_marker(mark) super().test_arith_frame_with_scalar(data, all_arithmetic_operators) - def test_add_series_with_extension_array(self, data): - ser = pd.Series(data) - with pytest.raises(TypeError, match="unsupported"): - ser + data - class TestComparisonOps(BaseJSON, base.BaseComparisonOpsTests): pass diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index 3b54d8e948b14..897b21d2f7a68 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -988,6 +988,9 @@ def _get_expected_exception( or pa.types.is_integer(pa_dtype) or pa.types.is_decimal(pa_dtype) ): + # TODO: in many of these cases, e.g. non-duration temporal, + # these will *never* be allowed. Would it make more sense to + # re-raise as TypeError, more consistent with non-pyarrow cases? exc = pa.ArrowNotImplementedError else: exc = None @@ -1123,32 +1126,7 @@ def test_arith_series_with_array(self, data, all_arithmetic_operators, request): def test_add_series_with_extension_array(self, data, request): pa_dtype = data.dtype.pyarrow_dtype - if pa.types.is_temporal(pa_dtype) and not pa.types.is_duration(pa_dtype): - # i.e. timestamp, date, time, but not timedelta; these *should* - # raise when trying to add - ser = pd.Series(data) - if pa_version_under7p0: - msg = "Function add_checked has no kernel matching input types" - else: - msg = "Function 'add_checked' has no kernel matching input types" - with pytest.raises(NotImplementedError, match=msg): - # TODO: this is a pa.lib.ArrowNotImplementedError, might - # be better to reraise a TypeError; more consistent with - # non-pyarrow cases - ser + data - - return - - if (pa_version_under8p0 and pa.types.is_duration(pa_dtype)) or ( - pa.types.is_boolean(pa_dtype) - ): - request.node.add_marker( - pytest.mark.xfail( - raises=NotImplementedError, - reason=f"add_checked not implemented for {pa_dtype}", - ) - ) - elif pa_dtype.equals("int8"): + if pa_dtype.equals("int8"): request.node.add_marker( pytest.mark.xfail( raises=pa.ArrowInvalid, diff --git a/pandas/tests/extension/test_categorical.py b/pandas/tests/extension/test_categorical.py index 828cdfa538ba5..8ee84c862688b 100644 --- a/pandas/tests/extension/test_categorical.py +++ b/pandas/tests/extension/test_categorical.py @@ -263,11 +263,6 @@ def test_arith_series_with_scalar(self, data, all_arithmetic_operators, request) ) super().test_arith_series_with_scalar(data, op_name) - def test_add_series_with_extension_array(self, data): - ser = pd.Series(data) - with pytest.raises(TypeError, match="cannot perform|unsupported operand"): - ser + data - class TestComparisonOps(base.BaseComparisonOpsTests): def _compare_other(self, s, data, op, other): diff --git a/pandas/tests/extension/test_datetime.py b/pandas/tests/extension/test_datetime.py index 4284b46a230a7..80e75824763b6 100644 --- a/pandas/tests/extension/test_datetime.py +++ b/pandas/tests/extension/test_datetime.py @@ -136,13 +136,6 @@ def _get_expected_exception(self, op_name, obj, other): return None return super()._get_expected_exception(op_name, obj, other) - def test_add_series_with_extension_array(self, data): - # Datetime + Datetime not implemented - ser = pd.Series(data) - msg = "cannot add DatetimeArray and DatetimeArray" - with pytest.raises(TypeError, match=msg): - ser + data - class TestCasting(BaseDatetimeTests, base.BaseCastingTests): pass diff --git a/pandas/tests/extension/test_period.py b/pandas/tests/extension/test_period.py index 26936829d7a34..5afbbe5214a5a 100644 --- a/pandas/tests/extension/test_period.py +++ b/pandas/tests/extension/test_period.py @@ -117,16 +117,6 @@ def _get_expected_exception(self, op_name, obj, other): return None return super()._get_expected_exception(op_name, obj, other) - def test_add_series_with_extension_array(self, data): - # we don't implement + for Period - s = pd.Series(data) - msg = ( - r"unsupported operand type\(s\) for \+: " - r"\'PeriodArray\' and \'PeriodArray\'" - ) - with pytest.raises(TypeError, match=msg): - s + data - class TestCasting(BasePeriodTests, base.BaseCastingTests): pass