33from __future__ import print_function
44import warnings
55from contextlib import contextmanager
6+ from distutils .version import StrictVersion
67
78import numpy as np
89from numpy .testing import assert_array_equal
6869
6970try :
7071 import bottleneck
72+ if StrictVersion (bottleneck .__version__ ) < StrictVersion ('1.0' ):
73+ raise ImportError ('Fall back to numpy' )
7174 has_bottleneck = True
7275except ImportError :
7376 has_bottleneck = False
7679# Generally `pytest.importorskip('package')` inline is even easier
7780requires_matplotlib = pytest .mark .skipif (not has_matplotlib , reason = 'requires matplotlib' )
7881
82+
7983def requires_scipy (test ):
8084 return test if has_scipy else pytest .mark .skip ('requires scipy' )(test )
8185
@@ -192,16 +196,18 @@ def assertDataArrayIdentical(self, ar1, ar2):
192196 def assertDataArrayAllClose (self , ar1 , ar2 , rtol = 1e-05 , atol = 1e-08 ):
193197 assert_xarray_allclose (ar1 , ar2 , rtol = rtol , atol = atol )
194198
199+
195200def assert_xarray_equal (a , b ):
196201 import xarray as xr
197202 ___tracebackhide__ = True # noqa: F841
198203 assert type (a ) == type (b )
199204 if isinstance (a , (xr .Variable , xr .DataArray , xr .Dataset )):
200205 assert a .equals (b ), '{}\n {}' .format (a , b )
201- else :
206+ else :
202207 raise TypeError ('{} not supported by assertion comparison'
203208 .format (type (a )))
204209
210+
205211def assert_xarray_identical (a , b ):
206212 import xarray as xr
207213 ___tracebackhide__ = True # noqa: F841
@@ -215,6 +221,7 @@ def assert_xarray_identical(a, b):
215221 raise TypeError ('{} not supported by assertion comparison'
216222 .format (type (a )))
217223
224+
218225def assert_xarray_allclose (a , b , rtol = 1e-05 , atol = 1e-08 ):
219226 import xarray as xr
220227 ___tracebackhide__ = True # noqa: F841
@@ -241,6 +248,7 @@ def assert_xarray_allclose(a, b, rtol=1e-05, atol=1e-08):
241248 raise TypeError ('{} not supported by assertion comparison'
242249 .format (type (a )))
243250
251+
244252class UnexpectedDataAccess (Exception ):
245253 pass
246254
0 commit comments