Deltares / xugrid

Xarray and unstructured grids
https://deltares.github.io/xugrid/
MIT License
64 stars 8 forks source link

Fix arrangement of test_infer_bounds_errors after xarray v2023.08.0 #151

Closed JoerivanEngelen closed 1 year ago

JoerivanEngelen commented 1 year ago

A test is failing due to the most recent xarray v2023.08.0 update. Apparently the indexes attribute is not updated anymore when setting values on coordinates as follows:

up = xr.DataArray(
        data=np.arange(4),
        coords={"x": [2.0, 4.0, 6.0, 8.0]},
        dims=["x"],
        name="grid",
    )

up["x"].values[2] = 3.0

print(up["x"].indexes)
# up["x"].indexes not updated

But this works:

up = up.assign_coords(x = [2.0, 4.0, 3.0, 8.0])

print(up["x"].indexes)
# up["x"].indexes are updated

It turns out the first example is not what the xarray devs have in mind on how coords should be set, so this explains why this test is failing without this fix.