Skip to content

Commit

Permalink
fix interpolation related issue with scipy 0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
zym1010 committed Mar 14, 2017
1 parent ca09705 commit 9ed7524
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
23 changes: 14 additions & 9 deletions pandas/tests/frame/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def test_interp_nan_idx(self):
df.interpolate(method='values')

def test_interp_various(self):
tm.skip_if_no_package('scipy', max_version='0.19.0')
tm._skip_if_no_scipy()

df = DataFrame({'A': [1, 2, np.nan, 4, 5, np.nan, 7],
'C': [1, 2, 3, 5, 8, 13, 21]})
Expand All @@ -561,8 +561,13 @@ def test_interp_various(self):
assert_frame_equal(result, expected)

result = df.interpolate(method='cubic')
expected.A.loc[3] = 2.81621174
expected.A.loc[13] = 5.64146581
import scipy
if scipy.__version__ >= LooseVersion('0.19.0'):
expected.A.loc[3] = 2.81547781
expected.A.loc[13] = 5.52964175
else:
expected.A.loc[3] = 2.81621174
expected.A.loc[13] = 5.64146581
assert_frame_equal(result, expected)

result = df.interpolate(method='nearest')
Expand All @@ -571,8 +576,12 @@ def test_interp_various(self):
assert_frame_equal(result, expected, check_dtype=False)

result = df.interpolate(method='quadratic')
expected.A.loc[3] = 2.82533638
expected.A.loc[13] = 6.02817974
if scipy.__version__ >= LooseVersion('0.19.0'):
expected.A.loc[3] = 2.82150771
expected.A.loc[13] = 6.12648668
else:
expected.A.loc[3] = 2.82533638
expected.A.loc[13] = 6.02817974
assert_frame_equal(result, expected)

result = df.interpolate(method='slinear')
Expand All @@ -585,10 +594,6 @@ def test_interp_various(self):
expected.A.loc[13] = 5
assert_frame_equal(result, expected, check_dtype=False)

result = df.interpolate(method='quadratic')
expected.A.loc[3] = 2.82533638
expected.A.loc[13] = 6.02817974
assert_frame_equal(result, expected)

def test_interp_alt_scipy(self):
tm._skip_if_no_scipy()
Expand Down
9 changes: 7 additions & 2 deletions pandas/tests/series/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytz
from datetime import timedelta, datetime

from distutils.version import LooseVersion
from numpy import nan
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -827,7 +828,7 @@ def test_interp_quad(self):
assert_series_equal(result, expected)

def test_interp_scipy_basic(self):
tm.skip_if_no_package('scipy', max_version='0.19.0')
tm._skip_if_no_scipy()

s = Series([1, 3, np.nan, 12, np.nan, 25])
# slinear
Expand All @@ -852,7 +853,11 @@ def test_interp_scipy_basic(self):
result = s.interpolate(method='zero', downcast='infer')
assert_series_equal(result, expected)
# quadratic
expected = Series([1, 3., 6.769231, 12., 18.230769, 25.])
import scipy
if scipy.__version__ >= LooseVersion('0.19.0'):
expected = Series([1, 3., 6.823529, 12., 18.058824, 25.])
else:
expected = Series([1, 3., 6.769231, 12., 18.230769, 25.])
result = s.interpolate(method='quadratic')
assert_series_equal(result, expected)

Expand Down

0 comments on commit 9ed7524

Please sign in to comment.