Skip to content

Commit

Permalink
compatibility with scipy 0.19
Browse files Browse the repository at this point in the history
fix pandas-dev#15662

Author: Yimeng Zhang <[email protected]>

Closes pandas-dev#15689 from zym1010/fix_scipy019 and squashes the following commits:

3cc6528 [Yimeng Zhang] doc and PEP8
9ed7524 [Yimeng Zhang] fix interpolation related issue with scipy 0.19
ca09705 [Yimeng Zhang] get symmetric window
  • Loading branch information
zym1010 authored and AnkurDedania committed Mar 21, 2017
1 parent 883536a commit c556177
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 18 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ Bug Fixes
- Bug in ``Rolling.quantile`` function that caused a segmentation fault when called with a quantile value outside of the range [0, 1] (:issue:`15463`)
- Bug in ``pd.cut()`` with a single bin on an all 0s array (:issue:`15428`)
- Bug in ``pd.qcut()`` with a single quantile and an array with identical values (:issue:`15431`)
- Compat with SciPy 0.19.0 for testing on ``.interpolate()`` (:issue:`15662`)


- Bug in the display of ``.info()`` where a qualifier (+) would always be displayed with a ``MultiIndex`` that contains only non-strings (:issue:`15245`)
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,8 @@ def _pop_args(win_type, arg_names, kwargs):
return all_args

win_type = _validate_win_type(self.win_type, kwargs)
return sig.get_window(win_type, window).astype(float)
# GH #15662. `False` makes symmetric window, rather than periodic.
return sig.get_window(win_type, window, False).astype(float)

def _apply_window(self, mean=True, how=None, **kwargs):
"""
Expand Down
33 changes: 23 additions & 10 deletions pandas/tests/frame/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
from pandas.tests.frame.common import TestData, _check_mixed_float


try:
import scipy
_is_scipy_ge_0190 = scipy.__version__ >= LooseVersion('0.19.0')
except:
_is_scipy_ge_0190 = False


def _skip_if_no_pchip():
try:
from scipy.interpolate import pchip_interpolate # noqa
Expand Down Expand Up @@ -548,7 +555,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 +568,15 @@ 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
# GH #15662.
# new cubic and quadratic interpolation algorithms from scipy 0.19.0.
# previously `splmake` was used. See scipy/scipy#6710
if _is_scipy_ge_0190:
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 +585,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 _is_scipy_ge_0190:
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,11 +603,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()
df = DataFrame({'A': [1, 2, np.nan, 4, 5, np.nan, 7],
Expand Down
17 changes: 15 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 All @@ -17,6 +18,12 @@

from .common import TestData

try:
import scipy
_is_scipy_ge_0190 = scipy.__version__ >= LooseVersion('0.19.0')
except:
_is_scipy_ge_0190 = False


def _skip_if_no_pchip():
try:
Expand Down Expand Up @@ -827,7 +834,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 +859,13 @@ 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.])
# GH #15662.
# new cubic and quadratic interpolation algorithms from scipy 0.19.0.
# previously `splmake` was used. See scipy/scipy#6710
if _is_scipy_ge_0190:
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
10 changes: 5 additions & 5 deletions pandas/tests/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ def test_cmov_window_na_min_periods(self):

def test_cmov_window_regular(self):
# GH 8238
tm.skip_if_no_package('scipy', max_version='0.19.0')
tm._skip_if_no_scipy()

win_types = ['triang', 'blackman', 'hamming', 'bartlett', 'bohman',
'blackmanharris', 'nuttall', 'barthann']
Expand Down Expand Up @@ -938,7 +938,7 @@ def test_cmov_window_regular(self):

def test_cmov_window_regular_linear_range(self):
# GH 8238
tm.skip_if_no_package('scipy', max_version='0.19.0')
tm._skip_if_no_scipy()

win_types = ['triang', 'blackman', 'hamming', 'bartlett', 'bohman',
'blackmanharris', 'nuttall', 'barthann']
Expand All @@ -955,7 +955,7 @@ def test_cmov_window_regular_linear_range(self):

def test_cmov_window_regular_missing_data(self):
# GH 8238
tm.skip_if_no_package('scipy', max_version='0.19.0')
tm._skip_if_no_scipy()

win_types = ['triang', 'blackman', 'hamming', 'bartlett', 'bohman',
'blackmanharris', 'nuttall', 'barthann']
Expand Down Expand Up @@ -988,7 +988,7 @@ def test_cmov_window_regular_missing_data(self):

def test_cmov_window_special(self):
# GH 8238
tm.skip_if_no_package('scipy', max_version='0.19.0')
tm._skip_if_no_scipy()

win_types = ['kaiser', 'gaussian', 'general_gaussian', 'slepian']
kwds = [{'beta': 1.}, {'std': 1.}, {'power': 2.,
Expand All @@ -1015,7 +1015,7 @@ def test_cmov_window_special(self):

def test_cmov_window_special_linear_range(self):
# GH 8238
tm.skip_if_no_package('scipy', max_version='0.19.0')
tm._skip_if_no_scipy()

win_types = ['kaiser', 'gaussian', 'general_gaussian', 'slepian']
kwds = [{'beta': 1.}, {'std': 1.}, {'power': 2.,
Expand Down

0 comments on commit c556177

Please sign in to comment.