xarray icon indicating copy to clipboard operation
xarray copied to clipboard

fix assert_equal for DataTree

Open mathause opened this issue 5 months ago • 0 comments

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 avatar Jun 23 '25 16:06 mathause