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

Method test_deepcopy

xarray/tests/test_datatree.py:464–489  ·  view source on GitHub ↗
(self, create_test_datatree)

Source from the content-addressed store, hash-verified

462 assert_identical(expected, actual)
463
464 def test_deepcopy(self, create_test_datatree) -> None:
465 dt = create_test_datatree()
466
467 for node in dt.root.subtree:
468 node.attrs["Test"] = [1, 2, 3]
469
470 for copied in [dt.copy(deep=True), deepcopy(dt)]:
471 assert_identical(dt, copied)
472
473 for node, copied_node in zip(
474 dt.root.subtree, copied.root.subtree, strict=True
475 ):
476 assert node.encoding == copied_node.encoding
477 # Note: IndexVariable objects with string dtype are always
478 # copied because of xarray.core.util.safe_cast_to_index.
479 # Limiting the test to data variables.
480 for k in node.data_vars:
481 v0 = node.variables[k]
482 v1 = copied_node.variables[k]
483 assert source_ndarray(v0.data) is not source_ndarray(v1.data)
484 copied_node["foo"] = xr.DataArray(data=np.arange(5), dims="z")
485 assert "foo" not in node
486
487 copied_node.attrs["foo"] = "bar"
488 assert "foo" not in node.attrs
489 assert node.attrs["Test"] is not copied_node.attrs["Test"]
490
491 @pytest.mark.xfail(reason="data argument not yet implemented")
492 def test_copy_with_data(self, create_test_datatree) -> None:

Callers

nothing calls this directly

Calls 5

assert_identicalFunction · 0.90
source_ndarrayFunction · 0.90
create_test_datatreeFunction · 0.85
arangeMethod · 0.80
copyMethod · 0.45

Tested by

no test coverage detected