@@ -24,12 +24,17 @@ class TestGetLoc:
24
24
@pytest .mark .parametrize ("method" , [None , "pad" , "backfill" , "nearest" ])
25
25
def test_get_loc (self , method ):
26
26
index = Index ([0 , 1 , 2 ])
27
- assert index .get_loc (1 , method = method ) == 1
27
+ warn = None if method is None else FutureWarning
28
+
29
+ with tm .assert_produces_warning (warn , match = "deprecated" ):
30
+ assert index .get_loc (1 , method = method ) == 1
28
31
29
32
if method :
30
- assert index .get_loc (1 , method = method , tolerance = 0 ) == 1
33
+ with tm .assert_produces_warning (warn , match = "deprecated" ):
34
+ assert index .get_loc (1 , method = method , tolerance = 0 ) == 1
31
35
32
36
@pytest .mark .parametrize ("method" , [None , "pad" , "backfill" , "nearest" ])
37
+ @pytest .mark .filterwarnings ("ignore:Passing method:FutureWarning" )
33
38
def test_get_loc_raises_bad_label (self , method ):
34
39
index = Index ([0 , 1 , 2 ])
35
40
if method :
@@ -43,6 +48,7 @@ def test_get_loc_raises_bad_label(self, method):
43
48
@pytest .mark .parametrize (
44
49
"method,loc" , [("pad" , 1 ), ("backfill" , 2 ), ("nearest" , 1 )]
45
50
)
51
+ @pytest .mark .filterwarnings ("ignore:Passing method:FutureWarning" )
46
52
def test_get_loc_tolerance (self , method , loc ):
47
53
index = Index ([0 , 1 , 2 ])
48
54
assert index .get_loc (1.1 , method ) == loc
@@ -52,12 +58,14 @@ def test_get_loc_tolerance(self, method, loc):
52
58
def test_get_loc_outside_tolerance_raises (self , method ):
53
59
index = Index ([0 , 1 , 2 ])
54
60
with pytest .raises (KeyError , match = "1.1" ):
55
- index .get_loc (1.1 , method , tolerance = 0.05 )
61
+ with tm .assert_produces_warning (FutureWarning , match = "deprecated" ):
62
+ index .get_loc (1.1 , method , tolerance = 0.05 )
56
63
57
64
def test_get_loc_bad_tolerance_raises (self ):
58
65
index = Index ([0 , 1 , 2 ])
59
66
with pytest .raises (ValueError , match = "must be numeric" ):
60
- index .get_loc (1.1 , "nearest" , tolerance = "invalid" )
67
+ with tm .assert_produces_warning (FutureWarning , match = "deprecated" ):
68
+ index .get_loc (1.1 , "nearest" , tolerance = "invalid" )
61
69
62
70
def test_get_loc_tolerance_no_method_raises (self ):
63
71
index = Index ([0 , 1 , 2 ])
@@ -67,8 +75,10 @@ def test_get_loc_tolerance_no_method_raises(self):
67
75
def test_get_loc_raises_missized_tolerance (self ):
68
76
index = Index ([0 , 1 , 2 ])
69
77
with pytest .raises (ValueError , match = "tolerance size must match" ):
70
- index .get_loc (1.1 , "nearest" , tolerance = [1 , 1 ])
78
+ with tm .assert_produces_warning (FutureWarning , match = "deprecated" ):
79
+ index .get_loc (1.1 , "nearest" , tolerance = [1 , 1 ])
71
80
81
+ @pytest .mark .filterwarnings ("ignore:Passing method:FutureWarning" )
72
82
def test_get_loc_float64 (self ):
73
83
idx = Float64Index ([0.0 , 1.0 , 2.0 ])
74
84
for method in [None , "pad" , "backfill" , "nearest" ]:
@@ -139,7 +149,8 @@ def test_get_loc_float_index_nan_with_method(self, vals, method):
139
149
# GH#39382
140
150
idx = Index (vals )
141
151
with pytest .raises (KeyError , match = "nan" ):
142
- idx .get_loc (np .nan , method = method )
152
+ with tm .assert_produces_warning (FutureWarning , match = "deprecated" ):
153
+ idx .get_loc (np .nan , method = method )
143
154
144
155
145
156
class TestGetIndexer :
0 commit comments