@@ -82,7 +82,20 @@ def mpl_test_settings(request):
82
82
83
83
@pytest .fixture
84
84
def pd ():
85
- """Fixture to import and configure pandas."""
85
+ """
86
+ Fixture to import and configure pandas. Using this fixture, the test is skipped when
87
+ pandas is not installed. Use this fixture instead of importing pandas in test files.
88
+
89
+ Examples
90
+ --------
91
+ Request the pandas fixture by passing in `pd` as an argument to the test ::
92
+
93
+ def test_matshow_pandas(pd):
94
+
95
+ df = pd.DataFrame({'x':[1,2,3], 'y':[4,5,6]})
96
+ im = plt.figure().subplots().matshow(df)
97
+ np.testing.assert_array_equal(im.get_array(), df)
98
+ """
86
99
pd = pytest .importorskip ('pandas' )
87
100
try :
88
101
from pandas .plotting import (
@@ -95,6 +108,20 @@ def pd():
95
108
96
109
@pytest .fixture
97
110
def xr ():
98
- """Fixture to import xarray."""
111
+ """
112
+ Fixture to import xarray so that the test is skipped when xarray is not installed.
113
+ Use this fixture instead of importing xrray in test files.
114
+
115
+ Examples
116
+ --------
117
+ Request the xarray fixture by passing in `xr` as an argument to the test ::
118
+
119
+ def test_imshow_xarray(xr):
120
+
121
+ ds = xr.DataArray(np.random.randn(2, 3))
122
+ im = plt.figure().subplots().imshow(ds)
123
+ np.testing.assert_array_equal(im.get_array(), ds)
124
+ """
125
+
99
126
xr = pytest .importorskip ('xarray' )
100
127
return xr
0 commit comments