Skip to content
Merged
Prev Previous commit
Next Next commit
Actually validate order before use in spline
  • Loading branch information
nmusolino committed Feb 9, 2019
commit 5bd3d4d6d5c796663b1cb1f99bdc9440ae6a085b
4 changes: 2 additions & 2 deletions pandas/core/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ def _interpolate_scipy_wrapper(x, y, new_x, method, fill_value=None,
bounds_error=bounds_error)
new_y = terp(new_x)
elif method == 'spline':
# GH #10633
if not order:
# GH #10633, #24014
if order is None or not (0 < order):
raise ValueError("order needs to be specified and greater than 0")
terp = interpolate.UnivariateSpline(x, y, k=order, **kwargs)
new_y = terp(new_x)
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/series/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1336,8 +1336,9 @@ def test_spline_error(self):
s.interpolate(method='spline')

msg = "order needs to be specified and greater than 0"
with pytest.raises(ValueError, match=msg):
s.interpolate(method='spline', order=0)
for invalid_order in [-1, -1., 0, 0., np.nan]:
with pytest.raises(ValueError, match=msg):
s.interpolate(method='spline', order=invalid_order)

def test_interp_timedelta64(self):
# GH 6424
Expand Down