Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test_deepcopy_nested_attrs() (#2835). #7086

Merged
merged 3 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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