@@ -271,7 +271,6 @@ def test_comparison_flex_basic(self):
271
271
tm .assert_series_equal (left .gt (right ), left > right )
272
272
tm .assert_series_equal (left .ge (right ), left >= right )
273
273
274
- # axis
275
274
for axis in [0 , None , "index" ]:
276
275
tm .assert_series_equal (left .eq (right , axis = axis ), left == right )
277
276
tm .assert_series_equal (left .ne (right , axis = axis ), left != right )
@@ -280,7 +279,6 @@ def test_comparison_flex_basic(self):
280
279
tm .assert_series_equal (left .gt (right , axis = axis ), left > right )
281
280
tm .assert_series_equal (left .ge (right , axis = axis ), left >= right )
282
281
283
- #
284
282
msg = "No axis named 1 for object type"
285
283
for op in ["eq" , "ne" , "le" , "le" , "gt" , "ge" ]:
286
284
with pytest .raises (ValueError , match = msg ):
@@ -553,68 +551,83 @@ def test_comparison_tuples(self):
553
551
expected = Series ([True , False ])
554
552
tm .assert_series_equal (result , expected )
555
553
556
- def test_comparison_operators_with_nas (self ):
554
+ def test_comparison_operators_with_nas (self , all_compare_operators ):
555
+ op = all_compare_operators
557
556
ser = Series (bdate_range ("1/1/2000" , periods = 10 ), dtype = object )
558
557
ser [::2 ] = np .nan
559
558
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 )
564
560
565
- f = getattr ( operator , op )
566
- result = f ( ser , val )
561
+ # test that comparisons work
562
+ val = ser [ 5 ]
567
563
568
- expected = f (ser .dropna (), val ).reindex (ser .index )
564
+ result = f (ser , val )
565
+ expected = f (ser .dropna (), val ).reindex (ser .index )
569
566
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 )
574
571
575
- tm .assert_series_equal (result , expected )
572
+ tm .assert_series_equal (result , expected )
576
573
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)
582
578
583
579
def test_ne (self ):
584
580
ts = Series ([3 , 4 , 5 , 6 , 7 ], [3 , 4 , 5 , 6 , 7 ], dtype = float )
585
581
expected = [True , True , False , True , True ]
586
582
assert tm .equalContents (ts .index != 5 , expected )
587
583
assert tm .equalContents (~ (ts .index == 5 ), expected )
588
584
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 ):
590
599
# 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
602
605
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
605
610
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
608
615
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 ()
612
621
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 ()
615
626
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 ()
618
631
619
632
def test_compare_series_interval_keyword (self ):
620
633
# GH#25338
0 commit comments