MCPcopy
hub / github.com/pydata/xarray / assert_identical

Function assert_identical

xarray/tests/__init__.py:335–375  ·  view source on GitHub ↗

Assert that two xarray objects are identical. This is a test-internal wrapper around xarray.testing.assert_identical that also validates internal invariants. Parameters ---------- a, b : xarray objects Objects to compare. check_default_indexes : bool, default True

(a, b, check_default_indexes=True, check_indexes=None)

Source from the content-addressed store, hash-verified

333
334
335def assert_identical(a, b, check_default_indexes=True, check_indexes=None):
336 """Assert that two xarray objects are identical.
337
338 This is a test-internal wrapper around xarray.testing.assert_identical
339 that also validates internal invariants.
340
341 Parameters
342 ----------
343 a, b : xarray objects
344 Objects to compare.
345 check_default_indexes : bool, default True
346 If True, validates that 1D dimension coordinates have default indexes
347 (internal invariant check). Set to False for objects that intentionally
348 lack default indexes.
349 check_indexes : bool, optional
350 If not specified (default), defaults to the value of check_default_indexes
351 for backwards compatibility.
352 If True (default), compare indexes as part of identity check.
353 If False, skip index comparison (only check data, attrs, names).
354 """
355 __tracebackhide__ = True
356 # For backwards compatibility, check_default_indexes=False implies check_indexes=False
357 # unless check_indexes is explicitly specified
358 if check_indexes is None:
359 check_indexes = check_default_indexes
360 if check_indexes:
361 xarray.testing.assert_identical(a, b)
362 else:
363 # Drop all indexes before comparing to skip index comparison
364 from xarray import DataArray, Dataset
365
366 if isinstance(a, Dataset | DataArray):
367 a_no_idx = a.drop_indexes(list(a.xindexes))
368 b_no_idx = b.drop_indexes(list(b.xindexes))
369 else:
370 a_no_idx, b_no_idx = a, b
371
372 xarray.testing.assert_identical(a_no_idx, b_no_idx)
373
374 xarray.testing._assert_internal_invariants(a, check_default_indexes)
375 xarray.testing._assert_internal_invariants(b, check_default_indexes)
376
377
378def assert_allclose(a, b, check_default_indexes=True, **kwargs):

Callers 15

test_custom_engineFunction · 0.90
test_multiindexFunction · 0.90
check_datasetMethod · 0.90
test_pickleMethod · 0.90
test_dataarray_pickleMethod · 0.90
test_dataset_pickleMethod · 0.90
test_unify_chunksFunction · 0.90
test_map_blocksFunction · 0.90

Calls 1

drop_indexesMethod · 0.45

Tested by 15

test_custom_engineFunction · 0.72
test_multiindexFunction · 0.72
check_datasetMethod · 0.72
test_pickleMethod · 0.72
test_dataarray_pickleMethod · 0.72
test_dataset_pickleMethod · 0.72
test_unify_chunksFunction · 0.72
test_map_blocksFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…