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

Function test_deepcopy_nested_attrs

xarray/tests/test_dataarray.py:7381–7402  ·  view source on GitHub ↗

Check attrs deep copy, see :issue:`2835`

()

Source from the content-addressed store, hash-verified

7379
7380
7381def test_deepcopy_nested_attrs() -> None:
7382 """Check attrs deep copy, see :issue:`2835`"""
7383 da1 = xr.DataArray([[1, 2], [3, 4]], dims=("x", "y"), coords={"x": [10, 20]})
7384 da1.attrs["flat"] = "0"
7385 da1.attrs["nested"] = {"level1a": "1", "level1b": "1"}
7386
7387 da2 = da1.copy(deep=True)
7388
7389 da2.attrs["new"] = "2"
7390 da2.attrs.update({"new2": "2"})
7391 da2.attrs["flat"] = "2"
7392 da2.attrs["nested"]["level1a"] = "2"
7393 da2.attrs["nested"].update({"level1b": "2"})
7394
7395 # Coarse test
7396 assert not da1.identical(da2)
7397
7398 # Check attrs levels
7399 assert da1.attrs["flat"] != da2.attrs["flat"]
7400 assert da1.attrs["nested"] != da2.attrs["nested"]
7401 assert "new" not in da1.attrs
7402 assert "new2" not in da1.attrs
7403
7404
7405def test_deepcopy_obj_array() -> None:

Callers

nothing calls this directly

Calls 3

copyMethod · 0.95
identicalMethod · 0.95
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…