Skip to content

Commit 0d4a1c1

Browse files
authored
CLN: Clean test_arithmetic.py (#36390)
1 parent 51558a0 commit 0d4a1c1

File tree

1 file changed

+56
-43
lines changed

1 file changed

+56
-43
lines changed

pandas/tests/series/test_arithmetic.py

+56-43
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ def test_comparison_flex_basic(self):
271271
tm.assert_series_equal(left.gt(right), left > right)
272272
tm.assert_series_equal(left.ge(right), left >= right)
273273

274-
# axis
275274
for axis in [0, None, "index"]:
276275
tm.assert_series_equal(left.eq(right, axis=axis), left == right)
277276
tm.assert_series_equal(left.ne(right, axis=axis), left != right)
@@ -280,7 +279,6 @@ def test_comparison_flex_basic(self):
280279
tm.assert_series_equal(left.gt(right, axis=axis), left > right)
281280
tm.assert_series_equal(left.ge(right, axis=axis), left >= right)
282281

283-
#
284282
msg = "No axis named 1 for object type"
285283
for op in ["eq", "ne", "le", "le", "gt", "ge"]:
286284
with pytest.raises(ValueError, match=msg):
@@ -553,68 +551,83 @@ def test_comparison_tuples(self):
553551
expected = Series([True, False])
554552
tm.assert_series_equal(result, expected)
555553

556-
def test_comparison_operators_with_nas(self):
554+
def test_comparison_operators_with_nas(self, all_compare_operators):
555+
op = all_compare_operators
557556
ser = Series(bdate_range("1/1/2000", periods=10), dtype=object)
558557
ser[::2] = np.nan
559558

560-
# test that comparisons work
561-
ops = ["lt", "le", "gt", "ge", "eq", "ne"]
562-
for op in ops:
563-
val = ser[5]
559+
f = getattr(operator, op)
564560

565-
f = getattr(operator, op)
566-
result = f(ser, val)
561+
# test that comparisons work
562+
val = ser[5]
567563

568-
expected = f(ser.dropna(), val).reindex(ser.index)
564+
result = f(ser, val)
565+
expected = f(ser.dropna(), val).reindex(ser.index)
569566

570-
if op == "ne":
571-
expected = expected.fillna(True).astype(bool)
572-
else:
573-
expected = expected.fillna(False).astype(bool)
567+
if op == "__ne__":
568+
expected = expected.fillna(True).astype(bool)
569+
else:
570+
expected = expected.fillna(False).astype(bool)
574571

575-
tm.assert_series_equal(result, expected)
572+
tm.assert_series_equal(result, expected)
576573

577-
# FIXME: dont leave commented-out
578-
# fffffffuuuuuuuuuuuu
579-
# result = f(val, s)
580-
# expected = f(val, s.dropna()).reindex(s.index)
581-
# tm.assert_series_equal(result, expected)
574+
# FIXME: dont leave commented-out
575+
# result = f(val, ser)
576+
# expected = f(val, ser.dropna()).reindex(ser.index)
577+
# tm.assert_series_equal(result, expected)
582578

583579
def test_ne(self):
584580
ts = Series([3, 4, 5, 6, 7], [3, 4, 5, 6, 7], dtype=float)
585581
expected = [True, True, False, True, True]
586582
assert tm.equalContents(ts.index != 5, expected)
587583
assert tm.equalContents(~(ts.index == 5), expected)
588584

589-
def test_comp_ops_df_compat(self):
585+
@pytest.mark.parametrize(
586+
"left, right",
587+
[
588+
(
589+
pd.Series([1, 2, 3], index=list("ABC"), name="x"),
590+
pd.Series([2, 2, 2], index=list("ABD"), name="x"),
591+
),
592+
(
593+
pd.Series([1, 2, 3], index=list("ABC"), name="x"),
594+
pd.Series([2, 2, 2, 2], index=list("ABCD"), name="x"),
595+
),
596+
],
597+
)
598+
def test_comp_ops_df_compat(self, left, right):
590599
# GH 1134
591-
s1 = pd.Series([1, 2, 3], index=list("ABC"), name="x")
592-
s2 = pd.Series([2, 2, 2], index=list("ABD"), name="x")
593-
594-
s3 = pd.Series([1, 2, 3], index=list("ABC"), name="x")
595-
s4 = pd.Series([2, 2, 2, 2], index=list("ABCD"), name="x")
596-
597-
for left, right in [(s1, s2), (s2, s1), (s3, s4), (s4, s3)]:
598-
599-
msg = "Can only compare identically-labeled Series objects"
600-
with pytest.raises(ValueError, match=msg):
601-
left == right
600+
msg = "Can only compare identically-labeled Series objects"
601+
with pytest.raises(ValueError, match=msg):
602+
left == right
603+
with pytest.raises(ValueError, match=msg):
604+
right == left
602605

603-
with pytest.raises(ValueError, match=msg):
604-
left != right
606+
with pytest.raises(ValueError, match=msg):
607+
left != right
608+
with pytest.raises(ValueError, match=msg):
609+
right != left
605610

606-
with pytest.raises(ValueError, match=msg):
607-
left < right
611+
with pytest.raises(ValueError, match=msg):
612+
left < right
613+
with pytest.raises(ValueError, match=msg):
614+
right < left
608615

609-
msg = "Can only compare identically-labeled DataFrame objects"
610-
with pytest.raises(ValueError, match=msg):
611-
left.to_frame() == right.to_frame()
616+
msg = "Can only compare identically-labeled DataFrame objects"
617+
with pytest.raises(ValueError, match=msg):
618+
left.to_frame() == right.to_frame()
619+
with pytest.raises(ValueError, match=msg):
620+
right.to_frame() == left.to_frame()
612621

613-
with pytest.raises(ValueError, match=msg):
614-
left.to_frame() != right.to_frame()
622+
with pytest.raises(ValueError, match=msg):
623+
left.to_frame() != right.to_frame()
624+
with pytest.raises(ValueError, match=msg):
625+
right.to_frame() != left.to_frame()
615626

616-
with pytest.raises(ValueError, match=msg):
617-
left.to_frame() < right.to_frame()
627+
with pytest.raises(ValueError, match=msg):
628+
left.to_frame() < right.to_frame()
629+
with pytest.raises(ValueError, match=msg):
630+
right.to_frame() < left.to_frame()
618631

619632
def test_compare_series_interval_keyword(self):
620633
# GH#25338

0 commit comments

Comments
 (0)