Skip to content

Commit e581e1e

Browse files
springcoiljreback
authored andcommitted
BUG: 10633 and 10800 fix
1 parent 73dcb95 commit e581e1e

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

doc/source/whatsnew/v0.17.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ Bug Fixes
679679
- Bug in ``to_datetime`` with invalid dates and formats supplied (:issue:`10154`)
680680
- Bug in ``Index.drop_duplicates`` dropping name(s) (:issue:`10115`)
681681
- Bug in ``pd.Series`` when setting a value on an empty ``Series`` whose index has a frequency. (:issue:`10193`)
682+
- Bug in ``pd.Series.interpolate`` with invalid ``order`` keyword values. (:issue:`10633`)
682683
- Bug in ``DataFrame.plot`` raises ``ValueError`` when color name is specified by multiple characters (:issue:`10387`)
683684
- Bug in ``Index`` construction with a mixed list of tuples (:issue:`10697`)
684685
- Bug in ``DataFrame.reset_index`` when index contains `NaT`. (:issue:`10388`)

pandas/core/common.py

+3
Original file line numberDiff line numberDiff line change
@@ -1718,6 +1718,9 @@ def _interpolate_scipy_wrapper(x, y, new_x, method, fill_value=None,
17181718
bounds_error=bounds_error)
17191719
new_y = terp(new_x)
17201720
elif method == 'spline':
1721+
# GH #10633
1722+
if not order:
1723+
raise ValueError("order needs to be specified and greater than 0")
17211724
terp = interpolate.UnivariateSpline(x, y, k=order, **kwargs)
17221725
new_y = terp(new_x)
17231726
else:

pandas/tests/test_generic.py

+24-3
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def test_sample(self):
374374

375375
self._compare(o.sample(frac=0.7,random_state=np.random.RandomState(test)),
376376
o.sample(frac=0.7, random_state=np.random.RandomState(test)))
377-
377+
378378

379379
# Check for error when random_state argument invalid.
380380
with tm.assertRaises(ValueError):
@@ -418,7 +418,7 @@ def test_sample(self):
418418
with tm.assertRaises(ValueError):
419419
bad_weight_series = Series([0,0,0.2])
420420
o.sample(n=4, weights=bad_weight_series)
421-
421+
422422
# Check won't accept negative weights
423423
with tm.assertRaises(ValueError):
424424
bad_weights = [-0.1]*10
@@ -545,7 +545,7 @@ def test_sample(self):
545545
s = Series([1,0,0], index=[3,5,9])
546546
assert_frame_equal(df.loc[[3]], df.sample(1, weights=s))
547547

548-
# Weights have index values to be dropped because not in
548+
# Weights have index values to be dropped because not in
549549
# sampled DataFrame
550550
s2 = Series([0.001,0,10000], index=[3,5,10])
551551
assert_frame_equal(df.loc[[3]], df.sample(1, weights=s2))
@@ -1423,6 +1423,27 @@ def test_spline_smooth(self):
14231423
self.assertNotEqual(s.interpolate(method='spline', order=3, s=0)[5],
14241424
s.interpolate(method='spline', order=3)[5])
14251425

1426+
def test_spline_interpolation(self):
1427+
tm._skip_if_no_scipy()
1428+
1429+
s = Series(np.arange(10)**2)
1430+
s[np.random.randint(0,9,3)] = np.nan
1431+
result1 = s.interpolate(method='spline', order=1)
1432+
expected1 = s.interpolate(method='spline', order=1)
1433+
assert_series_equal(result1, expected1)
1434+
1435+
# GH #10633
1436+
def test_spline_error(self):
1437+
tm._skip_if_no_scipy()
1438+
1439+
s = pd.Series(np.arange(10)**2)
1440+
s[np.random.randint(0,9,3)] = np.nan
1441+
with tm.assertRaises(ValueError):
1442+
s.interpolate(method='spline')
1443+
1444+
with tm.assertRaises(ValueError):
1445+
s.interpolate(method='spline', order=0)
1446+
14261447
def test_metadata_propagation_indiv(self):
14271448

14281449
# groupby

0 commit comments

Comments
 (0)