5
5
import numpy as np # noqa
6
6
from pandas import DataFrame
7
7
from 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
8
21
9
22
10
23
@pytest .fixture
@@ -14,8 +27,8 @@ def df():
14
27
15
28
def test_dask (df ):
16
29
17
- toolz = pytest . importorskip ('toolz' ) # noqa
18
- dask = pytest . importorskip ('dask' ) # noqa
30
+ toolz = import_module ('toolz' ) # noqa
31
+ dask = import_module ('dask' ) # noqa
19
32
20
33
import dask .dataframe as dd
21
34
@@ -26,14 +39,14 @@ def test_dask(df):
26
39
27
40
def test_xarray (df ):
28
41
29
- xarray = pytest . importorskip ('xarray' ) # noqa
42
+ xarray = import_module ('xarray' ) # noqa
30
43
31
44
assert df .to_xarray () is not None
32
45
33
46
34
47
def test_statsmodels ():
35
48
36
- statsmodels = pytest . importorskip ('statsmodels' ) # noqa
49
+ statsmodels = import_module ('statsmodels' ) # noqa
37
50
import statsmodels .api as sm
38
51
import statsmodels .formula .api as smf
39
52
df = sm .datasets .get_rdataset ("Guerry" , "HistData" ).data
@@ -42,7 +55,7 @@ def test_statsmodels():
42
55
43
56
def test_scikit_learn (df ):
44
57
45
- sklearn = pytest . importorskip ('sklearn' ) # noqa
58
+ sklearn = import_module ('sklearn' ) # noqa
46
59
from sklearn import svm , datasets
47
60
48
61
digits = datasets .load_digits ()
@@ -53,33 +66,34 @@ def test_scikit_learn(df):
53
66
54
67
def test_seaborn ():
55
68
56
- seaborn = pytest . importorskip ('seaborn' )
69
+ seaborn = import_module ('seaborn' )
57
70
tips = seaborn .load_dataset ("tips" )
58
71
seaborn .stripplot (x = "day" , y = "total_bill" , data = tips )
59
72
60
73
61
74
def test_pandas_gbq (df ):
62
75
63
- pandas_gbq = pytest . importorskip ( 'pandas-gbq ' ) # noqa
76
+ pandas_gbq = import_module ( 'pandas_gbq ' ) # noqa
64
77
65
78
66
- @tm .network
79
+ @pytest .mark .xfail (reason = ("pandas_datareader<=0.3.0 "
80
+ "broken w.r.t. pandas >= 0.20.0" ))
67
81
def test_pandas_datareader ():
68
82
69
- pandas_datareader = pytest . importorskip ( 'pandas-datareader ' ) # noqa
83
+ pandas_datareader = import_module ( 'pandas_datareader ' ) # noqa
70
84
pandas_datareader .get_data_yahoo ('AAPL' )
71
85
72
86
73
87
def test_geopandas ():
74
88
75
- geopandas = pytest . importorskip ('geopandas' ) # noqa
89
+ geopandas = import_module ('geopandas' ) # noqa
76
90
fp = geopandas .datasets .get_path ('naturalearth_lowres' )
77
91
assert geopandas .read_file (fp ) is not None
78
92
79
93
80
94
def test_pyarrow (df ):
81
95
82
- pyarrow = pytest . importorskip ('pyarrow' ) # noqa
96
+ pyarrow = import_module ('pyarrow' ) # noqa
83
97
table = pyarrow .Table .from_pandas (df )
84
98
result = table .to_pandas ()
85
99
tm .assert_frame_equal (result , df )
0 commit comments