From b15ec40adf92926866fb6049d27440c60af5edb5 Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Fri, 5 Feb 2016 14:08:31 -0600 Subject: [PATCH] TST: fix some scipy 0.17.0 changes --- pandas/tests/test_generic.py | 9 ++++++++- pandas/tests/test_nanops.py | 5 +++-- pandas/tests/test_stats.py | 12 +++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/pandas/tests/test_generic.py b/pandas/tests/test_generic.py index 2a97fdad8dd44..7cb0dd249effd 100644 --- a/pandas/tests/test_generic.py +++ b/pandas/tests/test_generic.py @@ -6,6 +6,7 @@ from numpy import nan import pandas as pd +from distutils.version import LooseVersion from pandas import (Index, Series, DataFrame, Panel, isnull, date_range, period_range) from pandas.core.index import MultiIndex @@ -1195,9 +1196,15 @@ def test_interp_alt_scipy(self): assert_frame_equal(result, expectedk) _skip_if_no_pchip() + import scipy result = df.interpolate(method='pchip') expected.ix[2, 'A'] = 3 - expected.ix[5, 'A'] = 6.125 + + if LooseVersion(scipy.__version__) >= '0.17.0': + expected.ix[5, 'A'] = 6.0 + else: + expected.ix[5, 'A'] = 6.125 + assert_frame_equal(result, expected) def test_interp_rowwise(self): diff --git a/pandas/tests/test_nanops.py b/pandas/tests/test_nanops.py index ca5246ba98f89..3738f88c1800b 100644 --- a/pandas/tests/test_nanops.py +++ b/pandas/tests/test_nanops.py @@ -122,7 +122,7 @@ def check_results(self, targ, res, axis): # timedeltas are a beast here def _coerce_tds(targ, res): - if targ.dtype == 'm8[ns]': + if hasattr(targ, 'dtype') and targ.dtype == 'm8[ns]': if len(targ) == 1: targ = targ[0].item() res = res.item() @@ -141,7 +141,8 @@ def _coerce_tds(targ, res): tm.assert_almost_equal(targ, res) except: - if targ.dtype == 'm8[ns]': + # handle timedelta dtypes + if hasattr(targ, 'dtype') and targ.dtype == 'm8[ns]': targ, res = _coerce_tds(targ, res) tm.assert_almost_equal(targ, res) return diff --git a/pandas/tests/test_stats.py b/pandas/tests/test_stats.py index b4cc57cb8216c..56f6a80e58eea 100644 --- a/pandas/tests/test_stats.py +++ b/pandas/tests/test_stats.py @@ -2,6 +2,7 @@ from pandas import compat import nose +from distutils.version import LooseVersion from numpy import nan import numpy as np @@ -47,6 +48,7 @@ def _check(s, expected, method='average'): def test_rank_methods_series(self): tm.skip_if_no_package('scipy', '0.13', 'scipy.stats.rankdata') + import scipy from scipy.stats import rankdata xs = np.random.randn(9) @@ -61,10 +63,15 @@ def test_rank_methods_series(self): for m in ['average', 'min', 'max', 'first', 'dense']: result = ts.rank(method=m) sprank = rankdata(vals, m if m != 'first' else 'ordinal') - tm.assert_series_equal(result, Series(sprank, index=index)) + expected = Series(sprank, index=index) + + if LooseVersion(scipy.__version__) >= '0.17.0': + expected = expected.astype('float64') + tm.assert_series_equal(result, expected) def test_rank_methods_frame(self): tm.skip_if_no_package('scipy', '0.13', 'scipy.stats.rankdata') + import scipy from scipy.stats import rankdata xs = np.random.randint(0, 21, (100, 26)) @@ -81,6 +88,9 @@ def test_rank_methods_frame(self): rankdata, ax, vals, m if m != 'first' else 'ordinal') expected = DataFrame(sprank, columns=cols) + + if LooseVersion(scipy.__version__) >= '0.17.0': + expected = expected.astype('float64') tm.assert_frame_equal(result, expected) def test_rank_dense_method(self):