Skip to content

Commit a6f4d05

Browse files
ivanovmgKevin D Smith
authored and
Kevin D Smith
committed
CLN: clean-up test on addition of series/frames (pandas-dev#37238)
1 parent 74e69be commit a6f4d05

File tree

1 file changed

+37
-23
lines changed

1 file changed

+37
-23
lines changed

pandas/tests/arithmetic/test_numeric.py

+37-23
Original file line numberDiff line numberDiff line change
@@ -808,31 +808,45 @@ class TestAdditionSubtraction:
808808
# __add__, __sub__, __radd__, __rsub__, __iadd__, __isub__
809809
# for non-timestamp/timedelta/period dtypes
810810

811-
# TODO: This came from series.test.test_operators, needs cleanup
812-
def test_arith_ops_df_compat(self):
811+
@pytest.mark.parametrize(
812+
"first, second, expected",
813+
[
814+
(
815+
pd.Series([1, 2, 3], index=list("ABC"), name="x"),
816+
pd.Series([2, 2, 2], index=list("ABD"), name="x"),
817+
pd.Series([3.0, 4.0, np.nan, np.nan], index=list("ABCD"), name="x"),
818+
),
819+
(
820+
pd.Series([1, 2, 3], index=list("ABC"), name="x"),
821+
pd.Series([2, 2, 2, 2], index=list("ABCD"), name="x"),
822+
pd.Series([3, 4, 5, np.nan], index=list("ABCD"), name="x"),
823+
),
824+
],
825+
)
826+
def test_add_series(self, first, second, expected):
813827
# GH#1134
814-
s1 = pd.Series([1, 2, 3], index=list("ABC"), name="x")
815-
s2 = pd.Series([2, 2, 2], index=list("ABD"), name="x")
816-
817-
exp = pd.Series([3.0, 4.0, np.nan, np.nan], index=list("ABCD"), name="x")
818-
tm.assert_series_equal(s1 + s2, exp)
819-
tm.assert_series_equal(s2 + s1, exp)
820-
821-
exp = pd.DataFrame({"x": [3.0, 4.0, np.nan, np.nan]}, index=list("ABCD"))
822-
tm.assert_frame_equal(s1.to_frame() + s2.to_frame(), exp)
823-
tm.assert_frame_equal(s2.to_frame() + s1.to_frame(), exp)
828+
tm.assert_series_equal(first + second, expected)
829+
tm.assert_series_equal(second + first, expected)
824830

825-
# different length
826-
s3 = pd.Series([1, 2, 3], index=list("ABC"), name="x")
827-
s4 = pd.Series([2, 2, 2, 2], index=list("ABCD"), name="x")
828-
829-
exp = pd.Series([3, 4, 5, np.nan], index=list("ABCD"), name="x")
830-
tm.assert_series_equal(s3 + s4, exp)
831-
tm.assert_series_equal(s4 + s3, exp)
832-
833-
exp = pd.DataFrame({"x": [3, 4, 5, np.nan]}, index=list("ABCD"))
834-
tm.assert_frame_equal(s3.to_frame() + s4.to_frame(), exp)
835-
tm.assert_frame_equal(s4.to_frame() + s3.to_frame(), exp)
831+
@pytest.mark.parametrize(
832+
"first, second, expected",
833+
[
834+
(
835+
pd.DataFrame({"x": [1, 2, 3]}, index=list("ABC")),
836+
pd.DataFrame({"x": [2, 2, 2]}, index=list("ABD")),
837+
pd.DataFrame({"x": [3.0, 4.0, np.nan, np.nan]}, index=list("ABCD")),
838+
),
839+
(
840+
pd.DataFrame({"x": [1, 2, 3]}, index=list("ABC")),
841+
pd.DataFrame({"x": [2, 2, 2, 2]}, index=list("ABCD")),
842+
pd.DataFrame({"x": [3, 4, 5, np.nan]}, index=list("ABCD")),
843+
),
844+
],
845+
)
846+
def test_add_frames(self, first, second, expected):
847+
# GH#1134
848+
tm.assert_frame_equal(first + second, expected)
849+
tm.assert_frame_equal(second + first, expected)
836850

837851
# TODO: This came from series.test.test_operators, needs cleanup
838852
def test_series_frame_radd_bug(self):

0 commit comments

Comments
 (0)