I'm writing a bunch of tests for one of my code bases that checks that the output of some operation done on a dataset has the expected results. As such, I'm using xarray.testing. assert_identical in these tests. I discovered that the assertion would fail occasionally with a ValueError rather than the expected AssertionError. Poking at different combinations of inputs, it appears to only fail when comparing a Dataset with non identical DataArrays that both contain an attribute that isn't comparable with ==
What did you expect to happen?
An AssertionError to be raised with the appropriate diff.
What happened?
I'm writing a bunch of tests for one of my code bases that checks that the output of some operation done on a dataset has the expected results. As such, I'm using xarray.testing. assert_identical in these tests. I discovered that the assertion would fail occasionally with a ValueError rather than the expected AssertionError. Poking at different combinations of inputs, it appears to only fail when comparing a Dataset with non identical DataArrays that both contain an attribute that isn't comparable with
==
What did you expect to happen?
An AssertionError to be raised with the appropriate diff.
Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
Anything else we need to know?
Comparing the underlying DataArray objects works as expected:
Traceback
```python --------------------------------------------------------------------------- AssertionError Traceback (most recent call last) Cell In[3], line 6 4 ds1 = xr.Dataset({"t1": xr.DataArray([1], attrs={"test": np.array([0,1,2,3], dtype="byte")})}) 5 ds2 = xr.Dataset({"t1": xr.DataArray([2], attrs={"test": np.array([0,1,2,3], dtype="byte")})}) ----> 6 xr.testing.assert_identical(ds1.t1, ds2.t1) [... skipping hidden 1 frame] File [~/.dotfiles/pyenv/versions/3.12.3/envs/jupyter/lib/python3.12/site-packages/xarray/testing/assertions.py:215](http://localhost:8888/~/.dotfiles/pyenv/versions/3.12.3/envs/jupyter/lib/python3.12/site-packages/xarray/testing/assertions.py#line=214), in assert_identical(a, b, from_root) 213 elif isinstance(a, DataArray): 214 assert a.name == b.name --> 215 assert a.identical(b), formatting.diff_array_repr(a, b, "identical") 216 elif isinstance(a, (Dataset, Variable)): 217 assert a.identical(b), formatting.diff_dataset_repr(a, b, "identical") AssertionError: Left and right DataArray objects are not identical Differing values: L array([1]) R array([2]) ```This potentially looks related to #3711
Environment