@@ -515,55 +515,52 @@ def _assert_where_conversion(
515
515
res = target .where (cond , values )
516
516
self ._assert (res , expected , expected_dtype )
517
517
518
- @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ], ids = ["series" , "index" ])
519
518
@pytest .mark .parametrize (
520
519
"fill_val,exp_dtype" ,
521
520
[(1 , np .object ), (1.1 , np .object ), (1 + 1j , np .object ), (True , np .object )],
522
521
)
523
- def test_where_object (self , klass , fill_val , exp_dtype ):
524
- obj = klass (list ("abcd" ))
522
+ def test_where_object (self , index_or_series , fill_val , exp_dtype ):
523
+ obj = index_or_series (list ("abcd" ))
525
524
assert obj .dtype == np .object
526
- cond = klass ([True , False , True , False ])
525
+ cond = index_or_series ([True , False , True , False ])
527
526
528
- if fill_val is True and klass is pd .Series :
527
+ if fill_val is True and index_or_series is pd .Series :
529
528
ret_val = 1
530
529
else :
531
530
ret_val = fill_val
532
531
533
- exp = klass (["a" , ret_val , "c" , ret_val ])
532
+ exp = index_or_series (["a" , ret_val , "c" , ret_val ])
534
533
self ._assert_where_conversion (obj , cond , fill_val , exp , exp_dtype )
535
534
536
535
if fill_val is True :
537
- values = klass ([True , False , True , True ])
536
+ values = index_or_series ([True , False , True , True ])
538
537
else :
539
- values = klass (fill_val * x for x in [5 , 6 , 7 , 8 ])
538
+ values = index_or_series (fill_val * x for x in [5 , 6 , 7 , 8 ])
540
539
541
- exp = klass (["a" , values [1 ], "c" , values [3 ]])
540
+ exp = index_or_series (["a" , values [1 ], "c" , values [3 ]])
542
541
self ._assert_where_conversion (obj , cond , values , exp , exp_dtype )
543
542
544
- @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ], ids = ["series" , "index" ])
545
543
@pytest .mark .parametrize (
546
544
"fill_val,exp_dtype" ,
547
545
[(1 , np .int64 ), (1.1 , np .float64 ), (1 + 1j , np .complex128 ), (True , np .object )],
548
546
)
549
- def test_where_int64 (self , klass , fill_val , exp_dtype ):
550
- if klass is pd .Index and exp_dtype is np .complex128 :
547
+ def test_where_int64 (self , index_or_series , fill_val , exp_dtype ):
548
+ if index_or_series is pd .Index and exp_dtype is np .complex128 :
551
549
pytest .skip ("Complex Index not supported" )
552
- obj = klass ([1 , 2 , 3 , 4 ])
550
+ obj = index_or_series ([1 , 2 , 3 , 4 ])
553
551
assert obj .dtype == np .int64
554
- cond = klass ([True , False , True , False ])
552
+ cond = index_or_series ([True , False , True , False ])
555
553
556
- exp = klass ([1 , fill_val , 3 , fill_val ])
554
+ exp = index_or_series ([1 , fill_val , 3 , fill_val ])
557
555
self ._assert_where_conversion (obj , cond , fill_val , exp , exp_dtype )
558
556
559
557
if fill_val is True :
560
- values = klass ([True , False , True , True ])
558
+ values = index_or_series ([True , False , True , True ])
561
559
else :
562
- values = klass (x * fill_val for x in [5 , 6 , 7 , 8 ])
563
- exp = klass ([1 , values [1 ], 3 , values [3 ]])
560
+ values = index_or_series (x * fill_val for x in [5 , 6 , 7 , 8 ])
561
+ exp = index_or_series ([1 , values [1 ], 3 , values [3 ]])
564
562
self ._assert_where_conversion (obj , cond , values , exp , exp_dtype )
565
563
566
- @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ], ids = ["series" , "index" ])
567
564
@pytest .mark .parametrize (
568
565
"fill_val, exp_dtype" ,
569
566
[
@@ -573,21 +570,21 @@ def test_where_int64(self, klass, fill_val, exp_dtype):
573
570
(True , np .object ),
574
571
],
575
572
)
576
- def test_where_float64 (self , klass , fill_val , exp_dtype ):
577
- if klass is pd .Index and exp_dtype is np .complex128 :
573
+ def test_where_float64 (self , index_or_series , fill_val , exp_dtype ):
574
+ if index_or_series is pd .Index and exp_dtype is np .complex128 :
578
575
pytest .skip ("Complex Index not supported" )
579
- obj = klass ([1.1 , 2.2 , 3.3 , 4.4 ])
576
+ obj = index_or_series ([1.1 , 2.2 , 3.3 , 4.4 ])
580
577
assert obj .dtype == np .float64
581
- cond = klass ([True , False , True , False ])
578
+ cond = index_or_series ([True , False , True , False ])
582
579
583
- exp = klass ([1.1 , fill_val , 3.3 , fill_val ])
580
+ exp = index_or_series ([1.1 , fill_val , 3.3 , fill_val ])
584
581
self ._assert_where_conversion (obj , cond , fill_val , exp , exp_dtype )
585
582
586
583
if fill_val is True :
587
- values = klass ([True , False , True , True ])
584
+ values = index_or_series ([True , False , True , True ])
588
585
else :
589
- values = klass (x * fill_val for x in [5 , 6 , 7 , 8 ])
590
- exp = klass ([1.1 , values [1 ], 3.3 , values [3 ]])
586
+ values = index_or_series (x * fill_val for x in [5 , 6 , 7 , 8 ])
587
+ exp = index_or_series ([1.1 , values [1 ], 3.3 , values [3 ]])
591
588
self ._assert_where_conversion (obj , cond , values , exp , exp_dtype )
592
589
593
590
@pytest .mark .parametrize (
@@ -783,19 +780,17 @@ def _assert_fillna_conversion(self, original, value, expected, expected_dtype):
783
780
res = target .fillna (value )
784
781
self ._assert (res , expected , expected_dtype )
785
782
786
- @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ], ids = ["series" , "index" ])
787
783
@pytest .mark .parametrize (
788
784
"fill_val, fill_dtype" ,
789
785
[(1 , np .object ), (1.1 , np .object ), (1 + 1j , np .object ), (True , np .object )],
790
786
)
791
- def test_fillna_object (self , klass , fill_val , fill_dtype ):
792
- obj = klass (["a" , np .nan , "c" , "d" ])
787
+ def test_fillna_object (self , index_or_series , fill_val , fill_dtype ):
788
+ obj = index_or_series (["a" , np .nan , "c" , "d" ])
793
789
assert obj .dtype == np .object
794
790
795
- exp = klass (["a" , fill_val , "c" , "d" ])
791
+ exp = index_or_series (["a" , fill_val , "c" , "d" ])
796
792
self ._assert_fillna_conversion (obj , fill_val , exp , fill_dtype )
797
793
798
- @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ], ids = ["series" , "index" ])
799
794
@pytest .mark .parametrize (
800
795
"fill_val,fill_dtype" ,
801
796
[
@@ -805,15 +800,15 @@ def test_fillna_object(self, klass, fill_val, fill_dtype):
805
800
(True , np .object ),
806
801
],
807
802
)
808
- def test_fillna_float64 (self , klass , fill_val , fill_dtype ):
809
- obj = klass ([1.1 , np .nan , 3.3 , 4.4 ])
803
+ def test_fillna_float64 (self , index_or_series , fill_val , fill_dtype ):
804
+ obj = index_or_series ([1.1 , np .nan , 3.3 , 4.4 ])
810
805
assert obj .dtype == np .float64
811
806
812
- exp = klass ([1.1 , fill_val , 3.3 , 4.4 ])
807
+ exp = index_or_series ([1.1 , fill_val , 3.3 , 4.4 ])
813
808
# float + complex -> we don't support a complex Index
814
809
# complex for Series,
815
810
# object for Index
816
- if fill_dtype == np .complex128 and klass == pd .Index :
811
+ if fill_dtype == np .complex128 and index_or_series == pd .Index :
817
812
fill_dtype = np .object
818
813
self ._assert_fillna_conversion (obj , fill_val , exp , fill_dtype )
819
814
@@ -833,7 +828,6 @@ def test_fillna_series_complex128(self, fill_val, fill_dtype):
833
828
exp = pd .Series ([1 + 1j , fill_val , 3 + 3j , 4 + 4j ])
834
829
self ._assert_fillna_conversion (obj , fill_val , exp , fill_dtype )
835
830
836
- @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ], ids = ["series" , "index" ])
837
831
@pytest .mark .parametrize (
838
832
"fill_val,fill_dtype" ,
839
833
[
@@ -844,8 +838,8 @@ def test_fillna_series_complex128(self, fill_val, fill_dtype):
844
838
],
845
839
ids = ["datetime64" , "datetime64tz" , "object" , "object" ],
846
840
)
847
- def test_fillna_datetime (self , klass , fill_val , fill_dtype ):
848
- obj = klass (
841
+ def test_fillna_datetime (self , index_or_series , fill_val , fill_dtype ):
842
+ obj = index_or_series (
849
843
[
850
844
pd .Timestamp ("2011-01-01" ),
851
845
pd .NaT ,
@@ -855,7 +849,7 @@ def test_fillna_datetime(self, klass, fill_val, fill_dtype):
855
849
)
856
850
assert obj .dtype == "datetime64[ns]"
857
851
858
- exp = klass (
852
+ exp = index_or_series (
859
853
[
860
854
pd .Timestamp ("2011-01-01" ),
861
855
fill_val ,
@@ -865,7 +859,6 @@ def test_fillna_datetime(self, klass, fill_val, fill_dtype):
865
859
)
866
860
self ._assert_fillna_conversion (obj , fill_val , exp , fill_dtype )
867
861
868
- @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ])
869
862
@pytest .mark .parametrize (
870
863
"fill_val,fill_dtype" ,
871
864
[
@@ -876,10 +869,10 @@ def test_fillna_datetime(self, klass, fill_val, fill_dtype):
876
869
("x" , np .object ),
877
870
],
878
871
)
879
- def test_fillna_datetime64tz (self , klass , fill_val , fill_dtype ):
872
+ def test_fillna_datetime64tz (self , index_or_series , fill_val , fill_dtype ):
880
873
tz = "US/Eastern"
881
874
882
- obj = klass (
875
+ obj = index_or_series (
883
876
[
884
877
pd .Timestamp ("2011-01-01" , tz = tz ),
885
878
pd .NaT ,
@@ -889,7 +882,7 @@ def test_fillna_datetime64tz(self, klass, fill_val, fill_dtype):
889
882
)
890
883
assert obj .dtype == "datetime64[ns, US/Eastern]"
891
884
892
- exp = klass (
885
+ exp = index_or_series (
893
886
[
894
887
pd .Timestamp ("2011-01-01" , tz = tz ),
895
888
fill_val ,
0 commit comments