MCPcopy Index your code
hub / github.com/pydata/xarray / assert_allclose

Function assert_allclose

xarray/testing/assertions.py:200–270  ·  view source on GitHub ↗

Like :py:func:`numpy.testing.assert_allclose`, but for xarray objects. Raises an AssertionError if two objects are not equal up to desired tolerance. Parameters ---------- a : xarray.Dataset, xarray.DataArray or xarray.Variable The first object to compare. b : xarra

(
    a, b, rtol=1e-05, atol=1e-08, decode_bytes=True, check_dim_order: bool = True
)

Source from the content-addressed store, hash-verified

198
199@ensure_warnings
200def assert_allclose(
201 a, b, rtol=1e-05, atol=1e-08, decode_bytes=True, check_dim_order: bool = True
202):
203 """Like :py:func:`numpy.testing.assert_allclose`, but for xarray objects.
204
205 Raises an AssertionError if two objects are not equal up to desired
206 tolerance.
207
208 Parameters
209 ----------
210 a : xarray.Dataset, xarray.DataArray or xarray.Variable
211 The first object to compare.
212 b : xarray.Dataset, xarray.DataArray or xarray.Variable
213 The second object to compare.
214 rtol : float, optional
215 Relative tolerance.
216 atol : float, optional
217 Absolute tolerance.
218 decode_bytes : bool, optional
219 Whether byte dtypes should be decoded to strings as UTF-8 or not.
220 This is useful for testing serialization methods on Python 3 that
221 return saved strings as bytes.
222 check_dim_order : bool, optional, default is True
223 Whether dimensions must be in the same order.
224
225 See Also
226 --------
227 assert_identical, assert_equal, numpy.testing.assert_allclose
228 """
229 __tracebackhide__ = True
230 assert type(a) is type(b)
231 b = maybe_transpose_dims(a, b, check_dim_order)
232
233 equiv = functools.partial(
234 _data_allclose_or_equiv, rtol=rtol, atol=atol, decode_bytes=decode_bytes
235 )
236 equiv.__name__ = "allclose" # type: ignore[attr-defined]
237
238 def compat_variable(a, b):
239 a = getattr(a, "variable", a)
240 b = getattr(b, "variable", b)
241 return a.dims == b.dims and (a._data is b._data or equiv(a.data, b.data))
242
243 def compat_node(a, b):
244 return a.ds._coord_names == b.ds._coord_names and utils.dict_equiv(
245 a.variables, b.variables, compat=compat_variable
246 )
247
248 if isinstance(a, Variable):
249 allclose = compat_variable(a, b)
250 assert allclose, formatting.diff_array_repr(a, b, compat=equiv)
251 elif isinstance(a, DataArray):
252 allclose = utils.dict_equiv(
253 a.coords, b.coords, compat=compat_variable
254 ) and compat_variable(a.variable, b.variable)
255 assert allclose, formatting.diff_array_repr(a, b, compat=equiv)
256 elif isinstance(a, Dataset):
257 allclose = a._coord_names == b._coord_names and utils.dict_equiv(

Callers 14

test_covFunction · 0.90
test_corrFunction · 0.90
test_covcorr_consistencyFunction · 0.90
test_autocovFunction · 0.90
test_bilinear_cov_corrFunction · 0.90
test_reduceFunction · 0.90
test_argmin_maxFunction · 0.90
test_min_countFunction · 0.90
test_min_count_ndFunction · 0.90
test_min_count_specificFunction · 0.90

Calls 3

typeFunction · 0.85
maybe_transpose_dimsFunction · 0.85
compat_variableFunction · 0.85

Tested by 14

test_covFunction · 0.72
test_corrFunction · 0.72
test_covcorr_consistencyFunction · 0.72
test_autocovFunction · 0.72
test_bilinear_cov_corrFunction · 0.72
test_reduceFunction · 0.72
test_argmin_maxFunction · 0.72
test_min_countFunction · 0.72
test_min_count_ndFunction · 0.72
test_min_count_specificFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…