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

Method test_copy

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

Source from the content-addressed store, hash-verified

411
412class TestCopy:
413 def test_copy(self, create_test_datatree) -> None:
414 dt = create_test_datatree()
415
416 for node in dt.root.subtree:
417 node.attrs["Test"] = [1, 2, 3]
418
419 for copied in [dt.copy(deep=False), copy(dt)]:
420 assert_identical(dt, copied)
421
422 for node, copied_node in zip(
423 dt.root.subtree, copied.root.subtree, strict=True
424 ):
425 assert node.encoding == copied_node.encoding
426 # Note: IndexVariable objects with string dtype are always
427 # copied because of xarray.core.util.safe_cast_to_index.
428 # Limiting the test to data variables.
429 for k in node.data_vars:
430 v0 = node.variables[k]
431 v1 = copied_node.variables[k]
432 assert source_ndarray(v0.data) is source_ndarray(v1.data)
433 copied_node["foo"] = xr.DataArray(data=np.arange(5), dims="z")
434 assert "foo" not in node
435
436 copied_node.attrs["foo"] = "bar"
437 assert "foo" not in node.attrs
438 assert node.attrs["Test"] is copied_node.attrs["Test"]
439
440 def test_copy_subtree(self) -> None:
441 dt = DataTree.from_dict({"/level1/level2/level3": xr.Dataset()})

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