Skip to content

Commit 76e5185

Browse files
zym1010jreback
authored andcommitted
compatibility with scipy 0.19
fix #15662 Author: Yimeng Zhang <[email protected]> Closes #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
1 parent 2cad4dd commit 76e5185

File tree

5 files changed

+46
-18
lines changed

5 files changed

+46
-18
lines changed

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,7 @@ Bug Fixes
816816
- Bug in ``Rolling.quantile`` function that caused a segmentation fault when called with a quantile value outside of the range [0, 1] (:issue:`15463`)
817817
- Bug in ``pd.cut()`` with a single bin on an all 0s array (:issue:`15428`)
818818
- Bug in ``pd.qcut()`` with a single quantile and an array with identical values (:issue:`15431`)
819+
- Compat with SciPy 0.19.0 for testing on ``.interpolate()`` (:issue:`15662`)
819820

820821

821822
- Bug in the display of ``.info()`` where a qualifier (+) would always be displayed with a ``MultiIndex`` that contains only non-strings (:issue:`15245`)

pandas/core/window.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,8 @@ def _pop_args(win_type, arg_names, kwargs):
544544
return all_args
545545

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

549550
def _apply_window(self, mean=True, how=None, **kwargs):
550551
"""

pandas/tests/frame/test_missing.py

+23-10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
from pandas.tests.frame.common import TestData, _check_mixed_float
2020

2121

22+
try:
23+
import scipy
24+
_is_scipy_ge_0190 = scipy.__version__ >= LooseVersion('0.19.0')
25+
except:
26+
_is_scipy_ge_0190 = False
27+
28+
2229
def _skip_if_no_pchip():
2330
try:
2431
from scipy.interpolate import pchip_interpolate # noqa
@@ -548,7 +555,7 @@ def test_interp_nan_idx(self):
548555
df.interpolate(method='values')
549556

550557
def test_interp_various(self):
551-
tm.skip_if_no_package('scipy', max_version='0.19.0')
558+
tm._skip_if_no_scipy()
552559

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

563570
result = df.interpolate(method='cubic')
564-
expected.A.loc[3] = 2.81621174
565-
expected.A.loc[13] = 5.64146581
571+
# GH #15662.
572+
# new cubic and quadratic interpolation algorithms from scipy 0.19.0.
573+
# previously `splmake` was used. See scipy/scipy#6710
574+
if _is_scipy_ge_0190:
575+
expected.A.loc[3] = 2.81547781
576+
expected.A.loc[13] = 5.52964175
577+
else:
578+
expected.A.loc[3] = 2.81621174
579+
expected.A.loc[13] = 5.64146581
566580
assert_frame_equal(result, expected)
567581

568582
result = df.interpolate(method='nearest')
@@ -571,8 +585,12 @@ def test_interp_various(self):
571585
assert_frame_equal(result, expected, check_dtype=False)
572586

573587
result = df.interpolate(method='quadratic')
574-
expected.A.loc[3] = 2.82533638
575-
expected.A.loc[13] = 6.02817974
588+
if _is_scipy_ge_0190:
589+
expected.A.loc[3] = 2.82150771
590+
expected.A.loc[13] = 6.12648668
591+
else:
592+
expected.A.loc[3] = 2.82533638
593+
expected.A.loc[13] = 6.02817974
576594
assert_frame_equal(result, expected)
577595

578596
result = df.interpolate(method='slinear')
@@ -585,11 +603,6 @@ def test_interp_various(self):
585603
expected.A.loc[13] = 5
586604
assert_frame_equal(result, expected, check_dtype=False)
587605

588-
result = df.interpolate(method='quadratic')
589-
expected.A.loc[3] = 2.82533638
590-
expected.A.loc[13] = 6.02817974
591-
assert_frame_equal(result, expected)
592-
593606
def test_interp_alt_scipy(self):
594607
tm._skip_if_no_scipy()
595608
df = DataFrame({'A': [1, 2, np.nan, 4, 5, np.nan, 7],

pandas/tests/series/test_missing.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytz
55
from datetime import timedelta, datetime
66

7+
from distutils.version import LooseVersion
78
from numpy import nan
89
import numpy as np
910
import pandas as pd
@@ -17,6 +18,12 @@
1718

1819
from .common import TestData
1920

21+
try:
22+
import scipy
23+
_is_scipy_ge_0190 = scipy.__version__ >= LooseVersion('0.19.0')
24+
except:
25+
_is_scipy_ge_0190 = False
26+
2027

2128
def _skip_if_no_pchip():
2229
try:
@@ -827,7 +834,7 @@ def test_interp_quad(self):
827834
assert_series_equal(result, expected)
828835

829836
def test_interp_scipy_basic(self):
830-
tm.skip_if_no_package('scipy', max_version='0.19.0')
837+
tm._skip_if_no_scipy()
831838

832839
s = Series([1, 3, np.nan, 12, np.nan, 25])
833840
# slinear
@@ -852,7 +859,13 @@ def test_interp_scipy_basic(self):
852859
result = s.interpolate(method='zero', downcast='infer')
853860
assert_series_equal(result, expected)
854861
# quadratic
855-
expected = Series([1, 3., 6.769231, 12., 18.230769, 25.])
862+
# GH #15662.
863+
# new cubic and quadratic interpolation algorithms from scipy 0.19.0.
864+
# previously `splmake` was used. See scipy/scipy#6710
865+
if _is_scipy_ge_0190:
866+
expected = Series([1, 3., 6.823529, 12., 18.058824, 25.])
867+
else:
868+
expected = Series([1, 3., 6.769231, 12., 18.230769, 25.])
856869
result = s.interpolate(method='quadratic')
857870
assert_series_equal(result, expected)
858871

pandas/tests/test_window.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ def test_cmov_window_na_min_periods(self):
905905

906906
def test_cmov_window_regular(self):
907907
# GH 8238
908-
tm.skip_if_no_package('scipy', max_version='0.19.0')
908+
tm._skip_if_no_scipy()
909909

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

939939
def test_cmov_window_regular_linear_range(self):
940940
# GH 8238
941-
tm.skip_if_no_package('scipy', max_version='0.19.0')
941+
tm._skip_if_no_scipy()
942942

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

956956
def test_cmov_window_regular_missing_data(self):
957957
# GH 8238
958-
tm.skip_if_no_package('scipy', max_version='0.19.0')
958+
tm._skip_if_no_scipy()
959959

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

989989
def test_cmov_window_special(self):
990990
# GH 8238
991-
tm.skip_if_no_package('scipy', max_version='0.19.0')
991+
tm._skip_if_no_scipy()
992992

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

10161016
def test_cmov_window_special_linear_range(self):
10171017
# GH 8238
1018-
tm.skip_if_no_package('scipy', max_version='0.19.0')
1018+
tm._skip_if_no_scipy()
10191019

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

0 commit comments

Comments
 (0)