Skip to content
forked from pydata/xarray

Commit

Permalink
Added test_deepcopy_nested_attrs() (pydata#2835). (pydata#7086)
Browse files Browse the repository at this point in the history
* Added test_deepcopy_nested_attrs() (pydata#2835).
* mark xfail
Co-authored-by: Michael Niklas <[email protected]>
  • Loading branch information
phockett authored Sep 28, 2022
1 parent 0b0b8f6 commit 6b2fdab
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ Documentation

Internal Changes
~~~~~~~~~~~~~~~~

- Added test for DataArray attrs deepcopy recursion/nested attrs (:issue:`2835`).
By `Paul hockett <https://github.com/phockett>`_.

.. _whats-new.2022.06.0:

Expand Down
25 changes: 25 additions & 0 deletions xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -6458,6 +6458,31 @@ def test_delete_coords() -> None:
assert set(a1.coords.keys()) == {"x"}


@pytest.mark.xfail
def test_deepcopy_nested_attrs() -> None:
"""Check attrs deep copy, see :issue:`2835`"""
da1 = xr.DataArray([[1, 2], [3, 4]], dims=("x", "y"), coords={"x": [10, 20]})
da1.attrs["flat"] = "0"
da1.attrs["nested"] = {"level1a": "1", "level1b": "1"}

da2 = da1.copy(deep=True)

da2.attrs["new"] = "2"
da2.attrs.update({"new2": "2"})
da2.attrs["flat"] = "2"
da2.attrs["nested"]["level1a"] = "2"
da2.attrs["nested"].update({"level1b": "2"})

# Coarse test
assert not da1.identical(da2)

# Check attrs levels
assert da1.attrs["flat"] != da2.attrs["flat"]
assert da1.attrs["nested"] != da2.attrs["nested"]
assert "new" not in da1.attrs
assert "new2" not in da1.attrs


def test_deepcopy_obj_array() -> None:
x0 = DataArray(np.array([object()]))
x1 = deepcopy(x0)
Expand Down

0 comments on commit 6b2fdab

Please sign in to comment.