Skip to content

REF: de-duplicate test_add_series_with_extension_array #54412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pandas/tests/extension/base/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions pandas/tests/extension/json/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 4 additions & 26 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions pandas/tests/extension/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 0 additions & 7 deletions pandas/tests/extension/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions pandas/tests/extension/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down