Skip to content

Commit be08e23

Browse files
authored
REF: de-duplicate test_combine_add (pandas-dev#54414)
1 parent 861b2fb commit be08e23

File tree

6 files changed

+17
-35
lines changed

6 files changed

+17
-35
lines changed

pandas/tests/extension/base/methods.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,24 @@ def test_combine_add(self, data_repeated):
345345
orig_data1, orig_data2 = data_repeated(2)
346346
s1 = pd.Series(orig_data1)
347347
s2 = pd.Series(orig_data2)
348-
result = s1.combine(s2, lambda x1, x2: x1 + x2)
349-
with np.errstate(over="ignore"):
350-
expected = pd.Series(
351-
orig_data1._from_sequence(
352-
[a + b for (a, b) in zip(list(orig_data1), list(orig_data2))]
348+
349+
# Check if the operation is supported pointwise for our scalars. If not,
350+
# we will expect Series.combine to raise as well.
351+
try:
352+
with np.errstate(over="ignore"):
353+
expected = pd.Series(
354+
orig_data1._from_sequence(
355+
[a + b for (a, b) in zip(list(orig_data1), list(orig_data2))]
356+
)
353357
)
354-
)
358+
except TypeError:
359+
# If the operation is not supported pointwise for our scalars,
360+
# then Series.combine should also raise
361+
with pytest.raises(TypeError):
362+
s1.combine(s2, lambda x1, x2: x1 + x2)
363+
return
364+
365+
result = s1.combine(s2, lambda x1, x2: x1 + x2)
355366
tm.assert_series_equal(result, expected)
356367

357368
val = s1.iloc[0]

pandas/tests/extension/json/test_json.py

-4
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,6 @@ def test_sort_values_missing(
209209
def test_combine_le(self, data_repeated):
210210
super().test_combine_le(data_repeated)
211211

212-
@pytest.mark.xfail(reason="combine for JSONArray not supported")
213-
def test_combine_add(self, data_repeated):
214-
super().test_combine_add(data_repeated)
215-
216212
@pytest.mark.xfail(
217213
reason="combine for JSONArray not supported - "
218214
"may pass depending on random data",

pandas/tests/extension/test_arrow.py

-13
Original file line numberDiff line numberDiff line change
@@ -821,19 +821,6 @@ def test_argreduce_series(
821821

822822
_combine_le_expected_dtype = "bool[pyarrow]"
823823

824-
def test_combine_add(self, data_repeated, request):
825-
pa_dtype = next(data_repeated(1)).dtype.pyarrow_dtype
826-
if pa.types.is_temporal(pa_dtype) and not pa.types.is_duration(pa_dtype):
827-
# analogous to datetime64, these cannot be added
828-
orig_data1, orig_data2 = data_repeated(2)
829-
s1 = pd.Series(orig_data1)
830-
s2 = pd.Series(orig_data2)
831-
with pytest.raises(TypeError):
832-
s1.combine(s2, lambda x1, x2: x1 + x2)
833-
834-
else:
835-
super().test_combine_add(data_repeated)
836-
837824

838825
class TestBaseArithmeticOps(base.BaseArithmeticOpsTests):
839826
divmod_exc = NotImplementedError

pandas/tests/extension/test_datetime.py

-4
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,6 @@ class TestIndex(base.BaseIndexTests):
113113

114114

115115
class TestMethods(BaseDatetimeTests, base.BaseMethodsTests):
116-
def test_combine_add(self, data_repeated):
117-
# Timestamp.__add__(Timestamp) not defined
118-
pass
119-
120116
@pytest.mark.parametrize("na_action", [None, "ignore"])
121117
def test_map(self, data, na_action):
122118
result = data.map(lambda x: x, na_action=na_action)

pandas/tests/extension/test_interval.py

-4
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,6 @@ def test_reduce_series_numeric(self, data, all_numeric_reductions, skipna):
121121

122122

123123
class TestMethods(BaseInterval, base.BaseMethodsTests):
124-
@pytest.mark.xfail(reason="addition is not defined for intervals")
125-
def test_combine_add(self, data_repeated):
126-
super().test_combine_add(data_repeated)
127-
128124
@pytest.mark.xfail(
129125
reason="Raises with incorrect message bc it disallows *all* listlikes "
130126
"instead of just wrong-length listlikes"

pandas/tests/extension/test_period.py

-4
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,6 @@ class TestIndex(base.BaseIndexTests):
9393

9494

9595
class TestMethods(BasePeriodTests, base.BaseMethodsTests):
96-
def test_combine_add(self, data_repeated):
97-
# Period + Period is not defined.
98-
pass
99-
10096
@pytest.mark.parametrize("periods", [1, -2])
10197
def test_diff(self, data, periods):
10298
if is_platform_windows() and np_version_gte1p24:

0 commit comments

Comments
 (0)