Skip to content

Fix dataarray drop attrs #10030

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

Merged
merged 12 commits into from
Feb 9, 2025
Prev Previous commit
Add DataArray()._replace() tests
  • Loading branch information
j-haacker committed Feb 9, 2025
commit 6482a5bcaadd4aa05be442d996f5282fb9f12237
15 changes: 15 additions & 0 deletions xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,21 @@ def test_rename_dimension_coord_warnings(self) -> None:
warnings.simplefilter("error")
da.rename(x="x")

def test_replace(self) -> None:
# Tests the `attrs` replacement and whether it interferes with a
# `variable` replacement
da = self.mda
attrs1 = {"a1": "val1", "a2": 161}
x = np.ones((10, 20))
v = Variable(["x", "y"], x)
assert da._replace(variable=v, attrs=attrs1).attrs == attrs1
attrs2 = {"b1": "val2", "b2": 1312}
va = Variable(["x", "y"], x, attrs2)
# assuming passed `attrs` should prevail
assert da._replace(variable=va, attrs=attrs1).attrs == attrs1
# assuming `va.attrs` should be adopted
assert da._replace(variable=va).attrs == attrs2

def test_init_value(self) -> None:
expected = DataArray(
np.full((3, 4), 3), dims=["x", "y"], coords=[range(3), range(4)]
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy