From ca097050b3fa28bd910bea6fafdb235384f3ee0b Mon Sep 17 00:00:00 2001 From: Yimeng Zhang Date: Tue, 14 Mar 2017 14:51:02 -0400 Subject: [PATCH 1/3] get symmetric window --- pandas/core/window.py | 4 +++- pandas/tests/test_window.py | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pandas/core/window.py b/pandas/core/window.py index 6fda60c449f42..49dbf89dd91f9 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -544,7 +544,9 @@ 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. + # fftbins should be False; previously it was a mistake on pandas' side. + return sig.get_window(win_type, window, fftbins=False).astype(float) def _apply_window(self, mean=True, how=None, **kwargs): """ diff --git a/pandas/tests/test_window.py b/pandas/tests/test_window.py index b7164d31b2a5e..3f2973a9834ca 100644 --- a/pandas/tests/test_window.py +++ b/pandas/tests/test_window.py @@ -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'] @@ -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'] @@ -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'] @@ -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., @@ -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., From 9ed7524f7de463feb2008f2fa7d8d24a459d0de7 Mon Sep 17 00:00:00 2001 From: Yimeng Zhang Date: Tue, 14 Mar 2017 15:35:16 -0400 Subject: [PATCH 2/3] fix interpolation related issue with scipy 0.19 --- pandas/tests/frame/test_missing.py | 23 ++++++++++++++--------- pandas/tests/series/test_missing.py | 9 +++++++-- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/pandas/tests/frame/test_missing.py b/pandas/tests/frame/test_missing.py index 923ed2e7c3444..c99267b56a510 100644 --- a/pandas/tests/frame/test_missing.py +++ b/pandas/tests/frame/test_missing.py @@ -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]}) @@ -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') @@ -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') @@ -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() diff --git a/pandas/tests/series/test_missing.py b/pandas/tests/series/test_missing.py index 9e997da517bf6..6e19acc14a07b 100644 --- a/pandas/tests/series/test_missing.py +++ b/pandas/tests/series/test_missing.py @@ -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 @@ -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 @@ -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) From 3cc6528fe70a815d85849fd5a9f534e672c0d701 Mon Sep 17 00:00:00 2001 From: Yimeng Zhang Date: Tue, 14 Mar 2017 20:35:45 -0400 Subject: [PATCH 3/3] doc and PEP8 --- doc/source/whatsnew/v0.20.0.txt | 1 + pandas/core/window.py | 5 ++--- pandas/tests/frame/test_missing.py | 16 ++++++++++++---- pandas/tests/series/test_missing.py | 12 ++++++++++-- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index 9c6f5d3e0596d..c3fd484d2bc9c 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -308,6 +308,7 @@ Other enhancements - ``pd.types.concat.union_categoricals`` gained the ``ignore_ordered`` argument to allow ignoring the ordered attribute of unioned categoricals (:issue:`13410`). See the :ref:`categorical union docs ` for more information. - ``pandas.io.json.json_normalize()`` with an empty ``list`` will return an empty ``DataFrame`` (:issue:`15534`) - ``pd.DataFrame.to_latex`` and ``pd.DataFrame.to_string`` now allow optional header aliases. (:issue:`15536`) +- ``pd.test()`` will now pass with SciPy 0.19.0. (:issue:`15662`) .. _ISO 8601 duration: https://en.wikipedia.org/wiki/ISO_8601#Durations diff --git a/pandas/core/window.py b/pandas/core/window.py index 49dbf89dd91f9..9c9f861451309 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -544,9 +544,8 @@ def _pop_args(win_type, arg_names, kwargs): return all_args win_type = _validate_win_type(self.win_type, kwargs) - # GH #15662. - # fftbins should be False; previously it was a mistake on pandas' side. - return sig.get_window(win_type, window, fftbins=False).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): """ diff --git a/pandas/tests/frame/test_missing.py b/pandas/tests/frame/test_missing.py index c99267b56a510..93c3ba78a0abf 100644 --- a/pandas/tests/frame/test_missing.py +++ b/pandas/tests/frame/test_missing.py @@ -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 @@ -561,8 +568,10 @@ def test_interp_various(self): assert_frame_equal(result, expected) result = df.interpolate(method='cubic') - import scipy - if scipy.__version__ >= LooseVersion('0.19.0'): + # 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: @@ -576,7 +585,7 @@ def test_interp_various(self): assert_frame_equal(result, expected, check_dtype=False) result = df.interpolate(method='quadratic') - if scipy.__version__ >= LooseVersion('0.19.0'): + if _is_scipy_ge_0190: expected.A.loc[3] = 2.82150771 expected.A.loc[13] = 6.12648668 else: @@ -594,7 +603,6 @@ def test_interp_various(self): expected.A.loc[13] = 5 assert_frame_equal(result, expected, check_dtype=False) - def test_interp_alt_scipy(self): tm._skip_if_no_scipy() df = DataFrame({'A': [1, 2, np.nan, 4, 5, np.nan, 7], diff --git a/pandas/tests/series/test_missing.py b/pandas/tests/series/test_missing.py index 6e19acc14a07b..7174283494fe7 100644 --- a/pandas/tests/series/test_missing.py +++ b/pandas/tests/series/test_missing.py @@ -18,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: @@ -853,8 +859,10 @@ def test_interp_scipy_basic(self): result = s.interpolate(method='zero', downcast='infer') assert_series_equal(result, expected) # quadratic - import scipy - if scipy.__version__ >= LooseVersion('0.19.0'): + # 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.])