@@ -1064,19 +1064,32 @@ def test_interp_limit(self):
1064
1064
# GH 9217, make sure limit is an int and greater than 0
1065
1065
methods = ['linear' , 'time' , 'index' , 'values' , 'nearest' , 'zero' ,
1066
1066
'slinear' , 'quadratic' , 'cubic' , 'barycentric' , 'krogh' ,
1067
- 'polynomial' , 'spline' , 'piecewise_polynomial' , None ,
1067
+ 'polynomial' , 'spline' , 'piecewise_polynomial' ,
1068
1068
'from_derivatives' , 'pchip' , 'akima' ]
1069
1069
s = pd .Series ([1 , 2 , np .nan , np .nan , 5 ])
1070
1070
msg = (r"Limit must be greater than 0|"
1071
1071
"time-weighted interpolation only works on Series or"
1072
1072
r" DataFrames with a DatetimeIndex|"
1073
- r"invalid method '(polynomial|spline|None)' to interpolate |"
1074
- "Limit must be an integer " )
1073
+ r"Limit must be an integer |"
1074
+ r"You must specify the order of the spline " )
1075
1075
for limit in [- 1 , 0 , 1. , 2. ]:
1076
1076
for method in methods :
1077
1077
with pytest .raises (ValueError , match = msg ):
1078
1078
s .interpolate (limit = limit , method = method )
1079
1079
1080
+ def test_interp_invalid_method (self ):
1081
+ s = Series ([1 , 3 , np .nan , 12 , np .nan , 25 ])
1082
+
1083
+ invalid_methods = [None , 'nonexistent_method' ]
1084
+ for method in invalid_methods :
1085
+ msg = "method must be one of.*\\ . Got '{}' instead" .format (method )
1086
+ with pytest .raises (ValueError , match = msg ):
1087
+ s .interpolate (method = method )
1088
+ # When an invalid method and invalid limit (such as -1) are
1089
+ # provided, the error message reflects the invalid method.
1090
+ with pytest .raises (ValueError , match = msg ):
1091
+ s .interpolate (method = method , limit = - 1 )
1092
+
1080
1093
def test_interp_limit_forward (self ):
1081
1094
s = Series ([1 , 3 , np .nan , np .nan , np .nan , 11 ])
1082
1095
@@ -1277,7 +1290,7 @@ def test_interp_limit_no_nans(self):
1277
1290
@pytest .mark .parametrize ("method" , ['polynomial' , 'spline' ])
1278
1291
def test_no_order (self , method ):
1279
1292
s = Series ([0 , 1 , np .nan , 3 ])
1280
- msg = "invalid method '{}' to interpolate" . format ( method )
1293
+ msg = "You must specify the order of the spline or polynomial"
1281
1294
with pytest .raises (ValueError , match = msg ):
1282
1295
s .interpolate (method = method )
1283
1296
@@ -1315,10 +1328,10 @@ def test_spline_interpolation(self):
1315
1328
1316
1329
@td .skip_if_no_scipy
1317
1330
def test_spline_error (self ):
1318
- # see gh -10633
1331
+ # see GH -10633, GH-24014
1319
1332
s = pd .Series (np .arange (10 ) ** 2 )
1320
1333
s [np .random .randint (0 , 9 , 3 )] = np .nan
1321
- msg = "invalid method ' spline' to interpolate "
1334
+ msg = "You must specify the order of the spline or polynomial "
1322
1335
with pytest .raises (ValueError , match = msg ):
1323
1336
s .interpolate (method = 'spline' )
1324
1337
0 commit comments