4
4
import pytest
5
5
import numpy as np # noqa
6
6
from pandas import DataFrame
7
+ from pandas .compat import PY36
7
8
from pandas .util import testing as tm
9
+ import importlib
10
+
11
+
12
+ def import_module (name ):
13
+ # we *only* want to skip if the module is truly not available
14
+ # and NOT just an actual import error because of pandas changes
15
+
16
+ if PY36 :
17
+ try :
18
+ return importlib .import_module (name )
19
+ except ModuleNotFoundError : # noqa
20
+ pytest .skip ("skipping as {} not available" .format (name ))
21
+
22
+ else :
23
+ try :
24
+ return importlib .import_module (name )
25
+ except ImportError as e :
26
+ if "No module named" in str (e ) and name in str (e ):
27
+ pytest .skip ("skipping as {} not available" .format (name ))
28
+ raise
8
29
9
30
10
31
@pytest .fixture
@@ -14,8 +35,8 @@ def df():
14
35
15
36
def test_dask (df ):
16
37
17
- toolz = pytest . importorskip ('toolz' ) # noqa
18
- dask = pytest . importorskip ('dask' ) # noqa
38
+ toolz = import_module ('toolz' ) # noqa
39
+ dask = import_module ('dask' ) # noqa
19
40
20
41
import dask .dataframe as dd
21
42
@@ -26,14 +47,14 @@ def test_dask(df):
26
47
27
48
def test_xarray (df ):
28
49
29
- xarray = pytest . importorskip ('xarray' ) # noqa
50
+ xarray = import_module ('xarray' ) # noqa
30
51
31
52
assert df .to_xarray () is not None
32
53
33
54
34
55
def test_statsmodels ():
35
56
36
- statsmodels = pytest . importorskip ('statsmodels' ) # noqa
57
+ statsmodels = import_module ('statsmodels' ) # noqa
37
58
import statsmodels .api as sm
38
59
import statsmodels .formula .api as smf
39
60
df = sm .datasets .get_rdataset ("Guerry" , "HistData" ).data
@@ -42,7 +63,7 @@ def test_statsmodels():
42
63
43
64
def test_scikit_learn (df ):
44
65
45
- sklearn = pytest . importorskip ('sklearn' ) # noqa
66
+ sklearn = import_module ('sklearn' ) # noqa
46
67
from sklearn import svm , datasets
47
68
48
69
digits = datasets .load_digits ()
@@ -53,33 +74,34 @@ def test_scikit_learn(df):
53
74
54
75
def test_seaborn ():
55
76
56
- seaborn = pytest . importorskip ('seaborn' )
77
+ seaborn = import_module ('seaborn' )
57
78
tips = seaborn .load_dataset ("tips" )
58
79
seaborn .stripplot (x = "day" , y = "total_bill" , data = tips )
59
80
60
81
61
82
def test_pandas_gbq (df ):
62
83
63
- pandas_gbq = pytest . importorskip ( 'pandas-gbq ' ) # noqa
84
+ pandas_gbq = import_module ( 'pandas_gbq ' ) # noqa
64
85
65
86
66
- @tm .network
87
+ @pytest .mark .xfail (reason = ("pandas_datareader<=0.3.0 "
88
+ "broken w.r.t. pandas >= 0.20.0" ))
67
89
def test_pandas_datareader ():
68
90
69
- pandas_datareader = pytest . importorskip ( 'pandas-datareader ' ) # noqa
91
+ pandas_datareader = import_module ( 'pandas_datareader ' ) # noqa
70
92
pandas_datareader .get_data_yahoo ('AAPL' )
71
93
72
94
73
95
def test_geopandas ():
74
96
75
- geopandas = pytest . importorskip ('geopandas' ) # noqa
97
+ geopandas = import_module ('geopandas' ) # noqa
76
98
fp = geopandas .datasets .get_path ('naturalearth_lowres' )
77
99
assert geopandas .read_file (fp ) is not None
78
100
79
101
80
102
def test_pyarrow (df ):
81
103
82
- pyarrow = pytest . importorskip ('pyarrow' ) # noqa
104
+ pyarrow = import_module ('pyarrow' ) # noqa
83
105
table = pyarrow .Table .from_pandas (df )
84
106
result = table .to_pandas ()
85
107
tm .assert_frame_equal (result , df )
0 commit comments