Skip to content

Commit a03bb08

Browse files
WillAydjreback
authored andcommitted
Dec cleanup (#18844)
1 parent 3539d80 commit a03bb08

File tree

5 files changed

+16
-102
lines changed

5 files changed

+16
-102
lines changed

pandas/conftest.py

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from distutils.version import LooseVersion
44
import numpy
55
import pandas
6-
import pandas.util.testing as tm
76
import dateutil
87

98

@@ -51,7 +50,6 @@ def add_imports(doctest_namespace):
5150

5251
@pytest.fixture(params=['bsr', 'coo', 'csc', 'csr', 'dia', 'dok', 'lil'])
5352
def spmatrix(request):
54-
tm._skip_if_no_scipy()
5553
from scipy import sparse
5654
return getattr(sparse, request.param + '_matrix')
5755

pandas/tests/io/test_pytables.py

-2
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,6 @@ def test_put_compression(self):
718718

719719
@td.skip_if_windows_python_3
720720
def test_put_compression_blosc(self):
721-
tm.skip_if_no_package('tables', min_version='2.2',
722-
app='blosc support')
723721
df = tm.makeTimeDataFrame()
724722

725723
with ensure_clean_store(self.path) as store:

pandas/tests/sparse/test_frame.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from numpy import nan
88
import numpy as np
99
import pandas as pd
10+
from distutils.version import LooseVersion
1011

1112
from pandas import Series, DataFrame, bdate_range, Panel
1213
from pandas.core.dtypes.common import (
@@ -20,6 +21,7 @@
2021
from pandas.compat import lrange
2122
from pandas import compat
2223
from pandas.core.sparse import frame as spf
24+
import pandas.util._test_decorators as td
2325

2426
from pandas._libs.sparse import BlockIndex, IntIndex
2527
from pandas.core.sparse.api import SparseSeries, SparseDataFrame, SparseArray
@@ -1169,14 +1171,13 @@ def test_notna(self):
11691171
tm.assert_frame_equal(res.to_dense(), exp)
11701172

11711173

1174+
@td.skip_if_no_scipy
11721175
@pytest.mark.parametrize('index', [None, list('abc')]) # noqa: F811
11731176
@pytest.mark.parametrize('columns', [None, list('def')])
11741177
@pytest.mark.parametrize('fill_value', [None, 0, np.nan])
11751178
@pytest.mark.parametrize('dtype', [bool, int, float, np.uint16])
11761179
def test_from_to_scipy(spmatrix, index, columns, fill_value, dtype):
11771180
# GH 4343
1178-
tm.skip_if_no_package('scipy')
1179-
11801181
# Make one ndarray and from it one sparse matrix, both to be used for
11811182
# constructing frames and comparing results
11821183
arr = np.eye(3, dtype=dtype)
@@ -1225,13 +1226,17 @@ def test_from_to_scipy(spmatrix, index, columns, fill_value, dtype):
12251226
assert sdf.to_coo().dtype == np.object_
12261227

12271228

1229+
@td.skip_if_no_scipy
12281230
@pytest.mark.parametrize('fill_value', [None, 0, np.nan]) # noqa: F811
12291231
def test_from_to_scipy_object(spmatrix, fill_value):
12301232
# GH 4343
12311233
dtype = object
12321234
columns = list('cd')
12331235
index = list('ab')
1234-
tm.skip_if_no_package('scipy', max_version='0.19.0')
1236+
import scipy
1237+
if (spmatrix is scipy.sparse.dok_matrix and LooseVersion(
1238+
scipy.__version__) >= LooseVersion('0.19.0')):
1239+
pytest.skip("dok_matrix from object does not work in SciPy >= 0.19")
12351240

12361241
# Make one ndarray and from it one sparse matrix, both to be used for
12371242
# constructing frames and comparing results
@@ -1270,10 +1275,9 @@ def test_from_to_scipy_object(spmatrix, fill_value):
12701275
assert sdf.to_coo().dtype == res_dtype
12711276

12721277

1278+
@td.skip_if_no_scipy
12731279
def test_from_scipy_correct_ordering(spmatrix):
12741280
# GH 16179
1275-
tm.skip_if_no_package('scipy')
1276-
12771281
arr = np.arange(1, 5).reshape(2, 2)
12781282
try:
12791283
spm = spmatrix(arr)
@@ -1290,10 +1294,9 @@ def test_from_scipy_correct_ordering(spmatrix):
12901294
tm.assert_frame_equal(sdf.to_dense(), expected.to_dense())
12911295

12921296

1297+
@td.skip_if_no_scipy
12931298
def test_from_scipy_fillna(spmatrix):
12941299
# GH 16112
1295-
tm.skip_if_no_package('scipy')
1296-
12971300
arr = np.eye(3)
12981301
arr[1:, 0] = np.nan
12991302

pandas/tests/test_nanops.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from pandas.core.dtypes.common import is_integer_dtype
1313
import pandas.core.nanops as nanops
1414
import pandas.util.testing as tm
15+
import pandas.util._test_decorators as td
1516

1617
use_bn = nanops._USE_BOTTLENECK
1718

@@ -381,8 +382,8 @@ def test_nanstd(self):
381382
allow_str=False, allow_date=False,
382383
allow_tdelta=True, allow_obj='convert')
383384

385+
@td.skip_if_no('scipy', min_version='0.17.0')
384386
def test_nansem(self):
385-
tm.skip_if_no_package('scipy', min_version='0.17.0')
386387
from scipy.stats import sem
387388
with np.errstate(invalid='ignore'):
388389
self.check_funs_ddof(nanops.nansem, sem, allow_complex=False,
@@ -441,17 +442,17 @@ def _skew_kurt_wrap(self, values, axis=None, func=None):
441442
return 0.
442443
return result
443444

445+
@td.skip_if_no('scipy', min_version='0.17.0')
444446
def test_nanskew(self):
445-
tm.skip_if_no_package('scipy', min_version='0.17.0')
446447
from scipy.stats import skew
447448
func = partial(self._skew_kurt_wrap, func=skew)
448449
with np.errstate(invalid='ignore'):
449450
self.check_funs(nanops.nanskew, func, allow_complex=False,
450451
allow_str=False, allow_date=False,
451452
allow_tdelta=False)
452453

454+
@td.skip_if_no('scipy', min_version='0.17.0')
453455
def test_nankurt(self):
454-
tm.skip_if_no_package('scipy', min_version='0.17.0')
455456
from scipy.stats import kurtosis
456457
func1 = partial(kurtosis, fisher=True)
457458
func = partial(self._skew_kurt_wrap, func=func1)
@@ -549,8 +550,8 @@ def test_nancorr_pearson(self):
549550
self.check_nancorr_nancov_1d(nanops.nancorr, targ0, targ1,
550551
method='pearson')
551552

553+
@td.skip_if_no_scipy
552554
def test_nancorr_kendall(self):
553-
tm.skip_if_no_package('scipy.stats')
554555
from scipy.stats import kendalltau
555556
targ0 = kendalltau(self.arr_float_2d, self.arr_float1_2d)[0]
556557
targ1 = kendalltau(self.arr_float_2d.flat, self.arr_float1_2d.flat)[0]
@@ -561,8 +562,8 @@ def test_nancorr_kendall(self):
561562
self.check_nancorr_nancov_1d(nanops.nancorr, targ0, targ1,
562563
method='kendall')
563564

565+
@td.skip_if_no_scipy
564566
def test_nancorr_spearman(self):
565-
tm.skip_if_no_package('scipy.stats')
566567
from scipy.stats import spearmanr
567568
targ0 = spearmanr(self.arr_float_2d, self.arr_float1_2d)[0]
568569
targ1 = spearmanr(self.arr_float_2d.flat, self.arr_float1_2d.flat)[0]

pandas/util/testing.py

-86
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from datetime import datetime
1616
from functools import wraps, partial
1717
from contextlib import contextmanager
18-
from distutils.version import LooseVersion
1918

2019
from numpy.random import randn, rand
2120
import numpy as np
@@ -317,35 +316,6 @@ def close(fignum=None):
317316
_close(fignum)
318317

319318

320-
def _skip_if_mpl_1_5():
321-
import matplotlib as mpl
322-
323-
v = mpl.__version__
324-
if LooseVersion(v) > LooseVersion('1.4.3') or str(v)[0] == '0':
325-
import pytest
326-
pytest.skip("matplotlib 1.5")
327-
else:
328-
mpl.use("Agg", warn=False)
329-
330-
331-
def _skip_if_no_scipy():
332-
import pytest
333-
334-
pytest.importorskip("scipy.stats")
335-
pytest.importorskip("scipy.sparse")
336-
pytest.importorskip("scipy.interpolate")
337-
338-
339-
def _skip_if_no_mock():
340-
try:
341-
import mock # noqa
342-
except ImportError:
343-
try:
344-
from unittest import mock # noqa
345-
except ImportError:
346-
import pytest
347-
raise pytest.skip("mock is not installed")
348-
349319
# -----------------------------------------------------------------------------
350320
# locale utilities
351321

@@ -1979,62 +1949,6 @@ def __init__(self, *args, **kwargs):
19791949
dict.__init__(self, *args, **kwargs)
19801950

19811951

1982-
# Dependency checker when running tests.
1983-
#
1984-
# Copied this from nipy/nipype
1985-
# Copyright of respective developers, License: BSD-3
1986-
def skip_if_no_package(pkg_name, min_version=None, max_version=None,
1987-
app='pandas', checker=LooseVersion):
1988-
"""Check that the min/max version of the required package is installed.
1989-
1990-
If the package check fails, the test is automatically skipped.
1991-
1992-
Parameters
1993-
----------
1994-
pkg_name : string
1995-
Name of the required package.
1996-
min_version : string, optional
1997-
Minimal version number for required package.
1998-
max_version : string, optional
1999-
Max version number for required package.
2000-
app : string, optional
2001-
Application that is performing the check. For instance, the
2002-
name of the tutorial being executed that depends on specific
2003-
packages.
2004-
checker : object, optional
2005-
The class that will perform the version checking. Default is
2006-
distutils.version.LooseVersion.
2007-
2008-
Examples
2009-
--------
2010-
package_check('numpy', '1.3')
2011-
2012-
"""
2013-
2014-
import pytest
2015-
if app:
2016-
msg = '{app} requires {pkg_name}'.format(app=app, pkg_name=pkg_name)
2017-
else:
2018-
msg = 'module requires {pkg_name}'.format(pkg_name=pkg_name)
2019-
if min_version:
2020-
msg += ' with version >= {min_version}'.format(min_version=min_version)
2021-
if max_version:
2022-
msg += ' with version < {max_version}'.format(max_version=max_version)
2023-
try:
2024-
mod = __import__(pkg_name)
2025-
except ImportError:
2026-
mod = None
2027-
try:
2028-
have_version = mod.__version__
2029-
except AttributeError:
2030-
pytest.skip('Cannot find version for {pkg_name}'
2031-
.format(pkg_name=pkg_name))
2032-
if min_version and checker(have_version) < checker(min_version):
2033-
pytest.skip(msg)
2034-
if max_version and checker(have_version) >= checker(max_version):
2035-
pytest.skip(msg)
2036-
2037-
20381952
def optional_args(decorator):
20391953
"""allows a decorator to take optional positional and keyword arguments.
20401954
Assumes that taking a single, callable, positional argument means that

0 commit comments

Comments
 (0)