55import numpy as np # noqa
66from pandas import DataFrame
77from pandas .util import testing as tm
8+ import importlib
9+
10+
11+ def import_module (name ):
12+ # we *only* want to skip if the module is truly not available
13+ # and NOT just an actual import error because of pandas changes
14+
15+ try :
16+ return importlib .import_module (name )
17+ except ImportError as e :
18+ if "No module named {}" .format (name ) in str (e ):
19+ pytest .skip ("skipping as {} not available" .format (name ))
20+ raise
821
922
1023@pytest .fixture
@@ -14,8 +27,8 @@ def df():
1427
1528def test_dask (df ):
1629
17- toolz = pytest . importorskip ('toolz' ) # noqa
18- dask = pytest . importorskip ('dask' ) # noqa
30+ toolz = import_module ('toolz' ) # noqa
31+ dask = import_module ('dask' ) # noqa
1932
2033 import dask .dataframe as dd
2134
@@ -26,14 +39,14 @@ def test_dask(df):
2639
2740def test_xarray (df ):
2841
29- xarray = pytest . importorskip ('xarray' ) # noqa
42+ xarray = import_module ('xarray' ) # noqa
3043
3144 assert df .to_xarray () is not None
3245
3346
3447def test_statsmodels ():
3548
36- statsmodels = pytest . importorskip ('statsmodels' ) # noqa
49+ statsmodels = import_module ('statsmodels' ) # noqa
3750 import statsmodels .api as sm
3851 import statsmodels .formula .api as smf
3952 df = sm .datasets .get_rdataset ("Guerry" , "HistData" ).data
@@ -42,7 +55,7 @@ def test_statsmodels():
4255
4356def test_scikit_learn (df ):
4457
45- sklearn = pytest . importorskip ('sklearn' ) # noqa
58+ sklearn = import_module ('sklearn' ) # noqa
4659 from sklearn import svm , datasets
4760
4861 digits = datasets .load_digits ()
@@ -53,33 +66,34 @@ def test_scikit_learn(df):
5366
5467def test_seaborn ():
5568
56- seaborn = pytest . importorskip ('seaborn' )
69+ seaborn = import_module ('seaborn' )
5770 tips = seaborn .load_dataset ("tips" )
5871 seaborn .stripplot (x = "day" , y = "total_bill" , data = tips )
5972
6073
6174def test_pandas_gbq (df ):
6275
63- pandas_gbq = pytest . importorskip ( 'pandas-gbq ' ) # noqa
76+ pandas_gbq = import_module ( 'pandas_gbq ' ) # noqa
6477
6578
66- @tm .network
79+ @pytest .mark .xfail (reason = ("pandas_datareader<=0.3.0 "
80+ "broken w.r.t. pandas >= 0.20.0" ))
6781def test_pandas_datareader ():
6882
69- pandas_datareader = pytest . importorskip ( 'pandas-datareader ' ) # noqa
83+ pandas_datareader = import_module ( 'pandas_datareader ' ) # noqa
7084 pandas_datareader .get_data_yahoo ('AAPL' )
7185
7286
7387def test_geopandas ():
7488
75- geopandas = pytest . importorskip ('geopandas' ) # noqa
89+ geopandas = import_module ('geopandas' ) # noqa
7690 fp = geopandas .datasets .get_path ('naturalearth_lowres' )
7791 assert geopandas .read_file (fp ) is not None
7892
7993
8094def test_pyarrow (df ):
8195
82- pyarrow = pytest . importorskip ('pyarrow' ) # noqa
96+ pyarrow = import_module ('pyarrow' ) # noqa
8397 table = pyarrow .Table .from_pandas (df )
8498 result = table .to_pandas ()
8599 tm .assert_frame_equal (result , df )
0 commit comments