Skip to content

fix assert_equal for DataTree #10440

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 3 commits into from
Jun 27, 2025
Merged

Conversation

mathause
Copy link
Collaborator

@mathause mathause commented Jun 23, 2025

xr.testing.assert_equal(dt1, dt2) fails when the DataTree objects differ. Because diff_dataset_repr was called with "equal" instead of "equals" which does not call all(), leading to the following error

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() 

To reproduce:

import xarray as xr

ds1 = xr.Dataset(data_vars={"data": ("y", [5, 2])})
ds2 = xr.Dataset(data_vars={"data": (("x", "y"), [[5, 2]])})
dt1 = xr.DataTree.from_dict({"node": ds1})
dt2 = xr.DataTree.from_dict({"node": ds2})

xr.testing.assert_equal(dt1, dt2)

@mathause mathause merged commit 5f47a03 into pydata:main Jun 27, 2025
33 checks passed
@mathause mathause deleted the fix_assert_equal_for_dt branch June 27, 2025 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant