Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: pd.Series.interpolate(method='spline') Errort Msg, #10633 #10880

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/source/whatsnew/v0.17.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -674,11 +674,18 @@ Performance Improvements

Bug Fixes
~~~~~~~~~
<<<<<<< HEAD
- Bug in ``DataFrame.to_html(index=False)`` renders unnecessary ``name`` row (:issue:`10344`)
=======


- Bug in ``DataFrame.to_html(index=False)`` renders unnecessary ``name`` row (:issue:`10344`)
>>>>>>> updating examples and the bug fix
- Bug in ``DataFrame.apply`` when function returns categorical series. (:issue:`9573`)
- Bug in ``to_datetime`` with invalid dates and formats supplied (:issue:`10154`)
- Bug in ``Index.drop_duplicates`` dropping name(s) (:issue:`10115`)
- Bug in ``pd.Series`` when setting a value on an empty ``Series`` whose index has a frequency. (:issue:`10193`)
- Bug in ``pd.Series.interpolate`` when setting no order value on ``Series.interpolate`` this needs to be at least 1. (:issue:`10633`) and (:issue:`10800`)
- Bug in ``DataFrame.plot`` raises ``ValueError`` when color name is specified by multiple characters (:issue:`10387`)
- Bug in ``Index`` construction with a mixed list of tuples (:issue:`10697`)
- Bug in ``DataFrame.reset_index`` when index contains `NaT`. (:issue:`10388`)
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,9 @@ 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:
raise ValueError("order needs to be specified and greater than 0")
terp = interpolate.UnivariateSpline(x, y, k=order, **kwargs)
new_y = terp(new_x)
else:
Expand Down
51 changes: 51 additions & 0 deletions pandas/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,40 @@ def test_nan_interpolate(self):
tm._skip_if_no_scipy()
result = s.interpolate(method='polynomial', order=1)
assert_series_equal(result, expected)
<<<<<<< HEAD
<<<<<<< HEAD

# GH #10633
=======
# GH #10633: first attempt
>>>>>>> d992cd0... Updated test
=======

# GH #10633
>>>>>>> 5a5407e... updating examples and the bug fix
def test_interpolate_spline(self):
np.random.seed(1)
s = pd.Series(np.arange(10)**2)
s[np.random.randint(0,9,3)] = np.nan
with tm.assertRaises(ValueError):
s.interpolate(method='spline')
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 027a5e7... Updating based on feedback

def test_interpolate_spline(self):
np.random.seed(1)
t = pd.Series(np.arange(10)**2)
t[np.random.randint(0,9,3)] = np.nan
with tm.assertRaises(ValueError):
t.interpolate(method='spline', order=0)
<<<<<<< HEAD
=======
>>>>>>> d992cd0... Updated test
=======
>>>>>>> 027a5e7... Updating based on feedback


def test_nan_irregular_index(self):
s = Series([1, 2, np.nan, 4], index=[1, 3, 5, 9])
Expand Down Expand Up @@ -1398,6 +1432,23 @@ def test_no_order(self):
s.interpolate(method='polynomial')
with tm.assertRaises(ValueError):
s.interpolate(method='spline')

<<<<<<< HEAD
<<<<<<< HEAD
=======
# GH #10633
def test_order_spline_interpolation(self):
tm._skip_if_no_scipy()
np.random.seed(1)
s = Series(np.arange(10)**2)
s[np.random.randint(0,9,3)] = np.nan
result1 = s.interpolate(method='spline', order=1)
expected1 = s.interpolate(method='spline', order=1)
assert_series_equal(result1, expected1)
>>>>>>> 5a5407e... updating examples and the bug fix
=======
>>>>>>> 027a5e7... Updating based on feedback


def test_spline(self):
tm._skip_if_no_scipy()
Expand Down