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)
| 333 | |
| 334 | |
| 335 | def 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 | |
| 378 | def assert_allclose(a, b, check_default_indexes=True, **kwargs): |
searching dependent graphs…