Skip to content

Commit d393c07

Browse files
committed
TST: skip scipy tests for >= 0.19.0 as needed in interpolation / window / sparse
1 parent 3510956 commit d393c07

File tree

8 files changed

+34
-36
lines changed

8 files changed

+34
-36
lines changed

pandas/tests/frame/test_missing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,8 @@ def test_interp_nan_idx(self):
548548
df.interpolate(method='values')
549549

550550
def test_interp_various(self):
551-
tm._skip_if_no_scipy()
551+
tm.skip_if_no_package('scipy', max_version='0.19.0')
552+
552553
df = DataFrame({'A': [1, 2, np.nan, 4, 5, np.nan, 7],
553554
'C': [1, 2, 3, 5, 8, 13, 21]})
554555
df = df.set_index('C')

pandas/tests/frame/test_rank.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ def test_rank_axis(self):
193193
tm.assert_frame_equal(df.rank(axis=1), df.rank(axis='columns'))
194194

195195
def test_rank_methods_frame(self):
196-
tm.skip_if_no_package('scipy', '0.13', 'scipy.stats.rankdata')
196+
tm.skip_if_no_package('scipy', min_version='0.13',
197+
app='scipy.stats.rankdata')
197198
import scipy
198199
from scipy.stats import rankdata
199200

pandas/tests/series/test_missing.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,8 @@ def test_interp_quad(self):
827827
assert_series_equal(result, expected)
828828

829829
def test_interp_scipy_basic(self):
830-
tm._skip_if_no_scipy()
830+
tm.skip_if_no_package('scipy', max_version='0.19.0')
831+
831832
s = Series([1, 3, np.nan, 12, np.nan, 25])
832833
# slinear
833834
expected = Series([1., 3., 7.5, 12., 18.5, 25.])
@@ -1027,8 +1028,8 @@ def test_spline(self):
10271028

10281029
def test_spline_extrapolate(self):
10291030
tm.skip_if_no_package(
1030-
'scipy', '0.15',
1031-
'setting ext on scipy.interpolate.UnivariateSpline')
1031+
'scipy', min_version='0.15',
1032+
app='setting ext on scipy.interpolate.UnivariateSpline')
10321033
s = Series([1, 2, 3, 4, np.nan, 6, np.nan])
10331034
result3 = s.interpolate(method='spline', order=1, ext=3)
10341035
expected3 = Series([1., 2., 3., 4., 5., 6., 6.])

pandas/tests/series/test_rank.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ def _check(s, expected, method='average'):
246246
_check(series, results[method], method=method)
247247

248248
def test_rank_methods_series(self):
249-
tm.skip_if_no_package('scipy', '0.13', 'scipy.stats.rankdata')
249+
tm.skip_if_no_package('scipy', min_version='0.13',
250+
app='scipy.stats.rankdata')
250251
import scipy
251252
from scipy.stats import rankdata
252253

pandas/tests/sparse/test_frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ def test_isnotnull(self):
11321132
@pytest.mark.parametrize('dtype', [object, bool, int, float, np.uint16])
11331133
def test_from_to_scipy(spmatrix, index, columns, fill_value, dtype):
11341134
# GH 4343
1135-
tm._skip_if_no_scipy()
1135+
tm.skip_if_no_package('scipy', max_version='0.19.0')
11361136

11371137
# Make one ndarray and from it one sparse matrix, both to be used for
11381138
# constructing frames and comparing results

pandas/tests/test_nanops.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import warnings
77
import numpy as np
8-
from pandas import Series, isnull
8+
from pandas import Series, isnull, _np_version_under1p9
99
from pandas.types.common import is_integer_dtype
1010
import pandas.core.nanops as nanops
1111
import pandas.util.testing as tm
@@ -338,8 +338,7 @@ def test_nanmean_overflow(self):
338338
# is now consistent with numpy
339339

340340
# numpy < 1.9.0 is not computing this correctly
341-
from distutils.version import LooseVersion
342-
if LooseVersion(np.__version__) >= '1.9.0':
341+
if not _np_version_under1p9:
343342
for a in [2 ** 55, -2 ** 55, 20150515061816532]:
344343
s = Series(a, index=range(500), dtype=np.int64)
345344
result = s.mean()
@@ -388,8 +387,7 @@ def test_nanstd(self):
388387
allow_tdelta=True, allow_obj='convert')
389388

390389
def test_nansem(self):
391-
tm.skip_if_no_package('scipy.stats')
392-
tm._skip_if_scipy_0_17()
390+
tm.skip_if_no_package('scipy', min_version='0.17.0')
393391
from scipy.stats import sem
394392
self.check_funs_ddof(nanops.nansem, sem, allow_complex=False,
395393
allow_str=False, allow_date=False,
@@ -448,16 +446,14 @@ def _skew_kurt_wrap(self, values, axis=None, func=None):
448446
return result
449447

450448
def test_nanskew(self):
451-
tm.skip_if_no_package('scipy.stats')
452-
tm._skip_if_scipy_0_17()
449+
tm.skip_if_no_package('scipy', min_version='0.17.0')
453450
from scipy.stats import skew
454451
func = partial(self._skew_kurt_wrap, func=skew)
455452
self.check_funs(nanops.nanskew, func, allow_complex=False,
456453
allow_str=False, allow_date=False, allow_tdelta=False)
457454

458455
def test_nankurt(self):
459-
tm.skip_if_no_package('scipy.stats')
460-
tm._skip_if_scipy_0_17()
456+
tm.skip_if_no_package('scipy', min_version='0.17.0')
461457
from scipy.stats import kurtosis
462458
func1 = partial(kurtosis, fisher=True)
463459
func = partial(self._skew_kurt_wrap, func=func1)

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_scipy()
908+
tm.skip_if_no_package('scipy', max_version='0.19.0')
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_scipy()
941+
tm.skip_if_no_package('scipy', max_version='0.19.0')
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_scipy()
958+
tm.skip_if_no_package('scipy', max_version='0.19.0')
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_scipy()
991+
tm.skip_if_no_package('scipy', max_version='0.19.0')
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_scipy()
1018+
tm.skip_if_no_package('scipy', max_version='0.19.0')
10191019

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

pandas/util/testing.py

+13-15
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,6 @@ def _skip_if_no_scipy():
304304
pytest.skip('scipy.sparse missing')
305305

306306

307-
def _skip_if_scipy_0_17():
308-
import scipy
309-
v = scipy.__version__
310-
if v >= LooseVersion("0.17.0"):
311-
import pytest
312-
pytest.skip("scipy 0.17")
313-
314-
315307
def _check_if_lzma():
316308
try:
317309
return compat.import_lzma()
@@ -2020,15 +2012,18 @@ def __init__(self, *args, **kwargs):
20202012

20212013
# Dependency checks. Copied this from Nipy/Nipype (Copyright of
20222014
# respective developers, license: BSD-3)
2023-
def package_check(pkg_name, version=None, app='pandas', checker=LooseVersion):
2024-
"""Check that the minimal version of the required package is installed.
2015+
def package_check(pkg_name, min_version=None, max_version=None, app='pandas',
2016+
checker=LooseVersion):
2017+
"""Check that the min/max version of the required package is installed.
20252018
20262019
Parameters
20272020
----------
20282021
pkg_name : string
20292022
Name of the required package.
2030-
version : string, optional
2023+
min_version : string, optional
20312024
Minimal version number for required package.
2025+
max_version : string, optional
2026+
Max version number for required package.
20322027
app : string, optional
20332028
Application that is performing the check. For instance, the
20342029
name of the tutorial being executed that depends on specific
@@ -2040,7 +2035,6 @@ def package_check(pkg_name, version=None, app='pandas', checker=LooseVersion):
20402035
Examples
20412036
--------
20422037
package_check('numpy', '1.3')
2043-
package_check('networkx', '1.0', 'tutorial1')
20442038
20452039
"""
20462040

@@ -2049,8 +2043,10 @@ def package_check(pkg_name, version=None, app='pandas', checker=LooseVersion):
20492043
msg = '%s requires %s' % (app, pkg_name)
20502044
else:
20512045
msg = 'module requires %s' % pkg_name
2052-
if version:
2053-
msg += ' with version >= %s' % (version,)
2046+
if min_version:
2047+
msg += ' with version >= %s' % (min_version,)
2048+
if max_version:
2049+
msg += ' with version < %s' % (max_version,)
20542050
try:
20552051
mod = __import__(pkg_name)
20562052
except ImportError:
@@ -2059,7 +2055,9 @@ def package_check(pkg_name, version=None, app='pandas', checker=LooseVersion):
20592055
have_version = mod.__version__
20602056
except AttributeError:
20612057
pytest.skip('Cannot find version for %s' % pkg_name)
2062-
if version and checker(have_version) < checker(version):
2058+
if min_version and checker(have_version) < checker(min_version):
2059+
pytest.skip(msg)
2060+
if max_version and checker(have_version) >= checker(max_version):
20632061
pytest.skip(msg)
20642062

20652063

0 commit comments

Comments
 (0)