17
17
from pandas .core .generic import NDFrame
18
18
from pandas .core .indexers import validate_indices
19
19
from pandas .core .indexing import _maybe_numeric_slice , _non_reducing_slice
20
- from pandas .tests .indexing .common import Base , _mklbl
20
+ from pandas .tests .indexing .common import _mklbl
21
21
22
22
# ------------------------------------------------------------------------
23
23
# Indexing test cases
24
24
25
25
26
- class TestFancy ( Base ) :
26
+ class TestFancy :
27
27
""" pure get/set item & fancy indexing """
28
28
29
29
def test_setitem_ndarray_1d (self ):
@@ -750,7 +750,7 @@ def test_index_type_coercion(self):
750
750
assert s2 .index .is_object ()
751
751
752
752
753
- class TestMisc ( Base ) :
753
+ class TestMisc :
754
754
def test_float_index_to_mixed (self ):
755
755
df = DataFrame ({0.0 : np .random .rand (10 ), 1.0 : np .random .rand (10 )})
756
756
df ["a" ] = 10
@@ -875,21 +875,21 @@ def test_indexing_dtypes_on_empty(self):
875
875
assert df2 .loc [:, "a" ].dtype == np .int64
876
876
tm .assert_series_equal (df2 .loc [:, "a" ], df2 .iloc [:, 0 ])
877
877
878
- def test_range_in_series_indexing (self ):
878
+ @pytest .mark .parametrize ("size" , [5 , 999999 , 1000000 ])
879
+ def test_range_in_series_indexing (self , size ):
879
880
# range can cause an indexing error
880
881
# GH 11652
881
- for x in [5 , 999999 , 1000000 ]:
882
- s = Series (index = range (x ), dtype = np .float64 )
883
- s .loc [range (1 )] = 42
884
- tm .assert_series_equal (s .loc [range (1 )], Series (42.0 , index = [0 ]))
882
+ s = Series (index = range (size ), dtype = np .float64 )
883
+ s .loc [range (1 )] = 42
884
+ tm .assert_series_equal (s .loc [range (1 )], Series (42.0 , index = [0 ]))
885
885
886
- s .loc [range (2 )] = 43
887
- tm .assert_series_equal (s .loc [range (2 )], Series (43.0 , index = [0 , 1 ]))
886
+ s .loc [range (2 )] = 43
887
+ tm .assert_series_equal (s .loc [range (2 )], Series (43.0 , index = [0 , 1 ]))
888
888
889
- def test_non_reducing_slice ( self ):
890
- df = DataFrame ([[ 0 , 1 ], [ 2 , 3 ]])
891
-
892
- slices = [
889
+ @ pytest . mark . parametrize (
890
+ "slc" ,
891
+ [
892
+ # FIXME: dont leave commented-out
893
893
# pd.IndexSlice[:, :],
894
894
pd .IndexSlice [:, 1 ],
895
895
pd .IndexSlice [1 , :],
@@ -902,10 +902,13 @@ def test_non_reducing_slice(self):
902
902
[0 , 1 ],
903
903
np .array ([0 , 1 ]),
904
904
Series ([0 , 1 ]),
905
- ]
906
- for slice_ in slices :
907
- tslice_ = _non_reducing_slice (slice_ )
908
- assert isinstance (df .loc [tslice_ ], DataFrame )
905
+ ],
906
+ )
907
+ def test_non_reducing_slice (self , slc ):
908
+ df = DataFrame ([[0 , 1 ], [2 , 3 ]])
909
+
910
+ tslice_ = _non_reducing_slice (slc )
911
+ assert isinstance (df .loc [tslice_ ], DataFrame )
909
912
910
913
def test_list_slice (self ):
911
914
# like dataframe getitem
@@ -965,37 +968,37 @@ class TestSeriesNoneCoercion:
965
968
(["foo" , "bar" , "baz" ], [None , "bar" , "baz" ]),
966
969
]
967
970
968
- def test_coercion_with_setitem ( self ):
969
- for start_data , expected_result in self . EXPECTED_RESULTS :
970
- start_series = Series (start_data )
971
- start_series [0 ] = None
971
+ @ pytest . mark . parametrize ( "start_data,expected_result" , EXPECTED_RESULTS )
972
+ def test_coercion_with_setitem ( self , start_data , expected_result ) :
973
+ start_series = Series (start_data )
974
+ start_series [0 ] = None
972
975
973
- expected_series = Series (expected_result )
974
- tm .assert_series_equal (start_series , expected_series )
976
+ expected_series = Series (expected_result )
977
+ tm .assert_series_equal (start_series , expected_series )
975
978
976
- def test_coercion_with_loc_setitem ( self ):
977
- for start_data , expected_result in self . EXPECTED_RESULTS :
978
- start_series = Series (start_data )
979
- start_series .loc [0 ] = None
979
+ @ pytest . mark . parametrize ( "start_data,expected_result" , EXPECTED_RESULTS )
980
+ def test_coercion_with_loc_setitem ( self , start_data , expected_result ) :
981
+ start_series = Series (start_data )
982
+ start_series .loc [0 ] = None
980
983
981
- expected_series = Series (expected_result )
982
- tm .assert_series_equal (start_series , expected_series )
984
+ expected_series = Series (expected_result )
985
+ tm .assert_series_equal (start_series , expected_series )
983
986
984
- def test_coercion_with_setitem_and_series ( self ):
985
- for start_data , expected_result in self . EXPECTED_RESULTS :
986
- start_series = Series (start_data )
987
- start_series [start_series == start_series [0 ]] = None
987
+ @ pytest . mark . parametrize ( "start_data,expected_result" , EXPECTED_RESULTS )
988
+ def test_coercion_with_setitem_and_series ( self , start_data , expected_result ) :
989
+ start_series = Series (start_data )
990
+ start_series [start_series == start_series [0 ]] = None
988
991
989
- expected_series = Series (expected_result )
990
- tm .assert_series_equal (start_series , expected_series )
992
+ expected_series = Series (expected_result )
993
+ tm .assert_series_equal (start_series , expected_series )
991
994
992
- def test_coercion_with_loc_and_series ( self ):
993
- for start_data , expected_result in self . EXPECTED_RESULTS :
994
- start_series = Series (start_data )
995
- start_series .loc [start_series == start_series [0 ]] = None
995
+ @ pytest . mark . parametrize ( "start_data,expected_result" , EXPECTED_RESULTS )
996
+ def test_coercion_with_loc_and_series ( self , start_data , expected_result ) :
997
+ start_series = Series (start_data )
998
+ start_series .loc [start_series == start_series [0 ]] = None
996
999
997
- expected_series = Series (expected_result )
998
- tm .assert_series_equal (start_series , expected_series )
1000
+ expected_series = Series (expected_result )
1001
+ tm .assert_series_equal (start_series , expected_series )
999
1002
1000
1003
1001
1004
class TestDataframeNoneCoercion :
@@ -1012,31 +1015,35 @@ class TestDataframeNoneCoercion:
1012
1015
(["foo" , "bar" , "baz" ], [None , "bar" , "baz" ]),
1013
1016
]
1014
1017
1015
- def test_coercion_with_loc (self ):
1016
- for start_data , expected_result in self .EXPECTED_SINGLE_ROW_RESULTS :
1017
- start_dataframe = DataFrame ({"foo" : start_data })
1018
- start_dataframe .loc [0 , ["foo" ]] = None
1018
+ @pytest .mark .parametrize ("expected" , EXPECTED_SINGLE_ROW_RESULTS )
1019
+ def test_coercion_with_loc (self , expected ):
1020
+ start_data , expected_result = expected
1021
+
1022
+ start_dataframe = DataFrame ({"foo" : start_data })
1023
+ start_dataframe .loc [0 , ["foo" ]] = None
1024
+
1025
+ expected_dataframe = DataFrame ({"foo" : expected_result })
1026
+ tm .assert_frame_equal (start_dataframe , expected_dataframe )
1027
+
1028
+ @pytest .mark .parametrize ("expected" , EXPECTED_SINGLE_ROW_RESULTS )
1029
+ def test_coercion_with_setitem_and_dataframe (self , expected ):
1030
+ start_data , expected_result = expected
1019
1031
1020
- expected_dataframe = DataFrame ({"foo" : expected_result })
1021
- tm . assert_frame_equal ( start_dataframe , expected_dataframe )
1032
+ start_dataframe = DataFrame ({"foo" : start_data })
1033
+ start_dataframe [ start_dataframe [ "foo" ] == start_dataframe [ "foo" ][ 0 ]] = None
1022
1034
1023
- def test_coercion_with_setitem_and_dataframe (self ):
1024
- for start_data , expected_result in self .EXPECTED_SINGLE_ROW_RESULTS :
1025
- start_dataframe = DataFrame ({"foo" : start_data })
1026
- start_dataframe [start_dataframe ["foo" ] == start_dataframe ["foo" ][0 ]] = None
1035
+ expected_dataframe = DataFrame ({"foo" : expected_result })
1036
+ tm .assert_frame_equal (start_dataframe , expected_dataframe )
1027
1037
1028
- expected_dataframe = DataFrame ({"foo" : expected_result })
1029
- tm .assert_frame_equal (start_dataframe , expected_dataframe )
1038
+ @pytest .mark .parametrize ("expected" , EXPECTED_SINGLE_ROW_RESULTS )
1039
+ def test_none_coercion_loc_and_dataframe (self , expected ):
1040
+ start_data , expected_result = expected
1030
1041
1031
- def test_none_coercion_loc_and_dataframe (self ):
1032
- for start_data , expected_result in self .EXPECTED_SINGLE_ROW_RESULTS :
1033
- start_dataframe = DataFrame ({"foo" : start_data })
1034
- start_dataframe .loc [
1035
- start_dataframe ["foo" ] == start_dataframe ["foo" ][0 ]
1036
- ] = None
1042
+ start_dataframe = DataFrame ({"foo" : start_data })
1043
+ start_dataframe .loc [start_dataframe ["foo" ] == start_dataframe ["foo" ][0 ]] = None
1037
1044
1038
- expected_dataframe = DataFrame ({"foo" : expected_result })
1039
- tm .assert_frame_equal (start_dataframe , expected_dataframe )
1045
+ expected_dataframe = DataFrame ({"foo" : expected_result })
1046
+ tm .assert_frame_equal (start_dataframe , expected_dataframe )
1040
1047
1041
1048
def test_none_coercion_mixed_dtypes (self ):
1042
1049
start_dataframe = DataFrame (
0 commit comments