Skip to content

Commit 245db2d

Browse files
authored
REF: de-duplicate test_add_series_with_extension_array (#54412)
1 parent 0ee072e commit 245db2d

File tree

6 files changed

+15
-53
lines changed

6 files changed

+15
-53
lines changed

pandas/tests/extension/base/ops.py

+11
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,18 @@ def test_divmod_series_array(self, data, data_for_twos):
161161
self._check_divmod_op(other, ops.rdivmod, ser)
162162

163163
def test_add_series_with_extension_array(self, data):
164+
# Check adding an ExtensionArray to a Series of the same dtype matches
165+
# the behavior of adding the arrays directly and then wrapping in a
166+
# Series.
167+
164168
ser = pd.Series(data)
169+
170+
exc = self._get_expected_exception("__add__", ser, data)
171+
if exc is not None:
172+
with pytest.raises(exc):
173+
ser + data
174+
return
175+
165176
result = ser + data
166177
expected = pd.Series(data + data)
167178
tm.assert_series_equal(result, expected)

pandas/tests/extension/json/test_json.py

-5
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,6 @@ def test_arith_frame_with_scalar(self, data, all_arithmetic_operators, request):
313313
request.node.add_marker(mark)
314314
super().test_arith_frame_with_scalar(data, all_arithmetic_operators)
315315

316-
def test_add_series_with_extension_array(self, data):
317-
ser = pd.Series(data)
318-
with pytest.raises(TypeError, match="unsupported"):
319-
ser + data
320-
321316

322317
class TestComparisonOps(BaseJSON, base.BaseComparisonOpsTests):
323318
pass

pandas/tests/extension/test_arrow.py

+4-26
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,9 @@ def _get_expected_exception(
988988
or pa.types.is_integer(pa_dtype)
989989
or pa.types.is_decimal(pa_dtype)
990990
):
991+
# TODO: in many of these cases, e.g. non-duration temporal,
992+
# these will *never* be allowed. Would it make more sense to
993+
# re-raise as TypeError, more consistent with non-pyarrow cases?
991994
exc = pa.ArrowNotImplementedError
992995
else:
993996
exc = None
@@ -1123,32 +1126,7 @@ def test_arith_series_with_array(self, data, all_arithmetic_operators, request):
11231126
def test_add_series_with_extension_array(self, data, request):
11241127
pa_dtype = data.dtype.pyarrow_dtype
11251128

1126-
if pa.types.is_temporal(pa_dtype) and not pa.types.is_duration(pa_dtype):
1127-
# i.e. timestamp, date, time, but not timedelta; these *should*
1128-
# raise when trying to add
1129-
ser = pd.Series(data)
1130-
if pa_version_under7p0:
1131-
msg = "Function add_checked has no kernel matching input types"
1132-
else:
1133-
msg = "Function 'add_checked' has no kernel matching input types"
1134-
with pytest.raises(NotImplementedError, match=msg):
1135-
# TODO: this is a pa.lib.ArrowNotImplementedError, might
1136-
# be better to reraise a TypeError; more consistent with
1137-
# non-pyarrow cases
1138-
ser + data
1139-
1140-
return
1141-
1142-
if (pa_version_under8p0 and pa.types.is_duration(pa_dtype)) or (
1143-
pa.types.is_boolean(pa_dtype)
1144-
):
1145-
request.node.add_marker(
1146-
pytest.mark.xfail(
1147-
raises=NotImplementedError,
1148-
reason=f"add_checked not implemented for {pa_dtype}",
1149-
)
1150-
)
1151-
elif pa_dtype.equals("int8"):
1129+
if pa_dtype.equals("int8"):
11521130
request.node.add_marker(
11531131
pytest.mark.xfail(
11541132
raises=pa.ArrowInvalid,

pandas/tests/extension/test_categorical.py

-5
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,6 @@ def test_arith_series_with_scalar(self, data, all_arithmetic_operators, request)
263263
)
264264
super().test_arith_series_with_scalar(data, op_name)
265265

266-
def test_add_series_with_extension_array(self, data):
267-
ser = pd.Series(data)
268-
with pytest.raises(TypeError, match="cannot perform|unsupported operand"):
269-
ser + data
270-
271266

272267
class TestComparisonOps(base.BaseComparisonOpsTests):
273268
def _compare_other(self, s, data, op, other):

pandas/tests/extension/test_datetime.py

-7
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,6 @@ def _get_expected_exception(self, op_name, obj, other):
136136
return None
137137
return super()._get_expected_exception(op_name, obj, other)
138138

139-
def test_add_series_with_extension_array(self, data):
140-
# Datetime + Datetime not implemented
141-
ser = pd.Series(data)
142-
msg = "cannot add DatetimeArray and DatetimeArray"
143-
with pytest.raises(TypeError, match=msg):
144-
ser + data
145-
146139

147140
class TestCasting(BaseDatetimeTests, base.BaseCastingTests):
148141
pass

pandas/tests/extension/test_period.py

-10
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,6 @@ def _get_expected_exception(self, op_name, obj, other):
117117
return None
118118
return super()._get_expected_exception(op_name, obj, other)
119119

120-
def test_add_series_with_extension_array(self, data):
121-
# we don't implement + for Period
122-
s = pd.Series(data)
123-
msg = (
124-
r"unsupported operand type\(s\) for \+: "
125-
r"\'PeriodArray\' and \'PeriodArray\'"
126-
)
127-
with pytest.raises(TypeError, match=msg):
128-
s + data
129-
130120

131121
class TestCasting(BasePeriodTests, base.BaseCastingTests):
132122
pass

0 commit comments

Comments
 (0)