Skip to content

Math with multiple uxarray objects with different grids silently succeeds, when data dims are otherwise compatible #1718

Description

@Sevans711

Version

v2026.8.0

How did you install UXarray?

Source

What happened?

Mathematical operations with multiple uxarray objects having data with compatible dimensions (i.e., compatible via broadcasting, such that xarray wouldn't complain if performing the same operation on [obj.to_xarray() for obj in objs]) succeeds regardless of whether the underlying grids are the same, and keeps only one of the objects' uxgrids.

This might not have been noticed before because xarray crashes if the data dimensions aren't compatible; this only occurs when the dimensions are compatible.

What did you expect to happen?

I expected any operations combining multiple uxarray objects to require all of those objects to have equivalent uxgrids (compared as objA.uxgrid == objB.uxgrid). When having compatible dimensions but incompatible uxgrids, I expected a GridsMismatchError would be raised.

Can you provide a MCVE to repoduce the bug?

objA = ux.tutorial.open_dataset('quad-hexagon')['t2m']
_tmp = ux.tutorial.open_dataset('outCSne30-timeseries')['psi']
objB = _tmp.isel(n_face=[10,20,30,40])
print((objA.sizes, objB.sizes))
# prints (Frozen({'n_face': 4}), Frozen({'time': 6, 'n_face': 4}))
print(arrA.uxgrid == arrB.uxgrid)
# prints False

# this should fail but it succeeds:
result = objA + objB

# result's uxgrid == objA.uxgrid; the objB.uxgrid was silently ignored:
print((result.uxgrid == objA.uxgrid, result.uxgrid == objB.uxgrid))
# prints (True, False)

# similar issue if objB is a UxDataset instead (i.e. remove ['psi'] above)
# although that actually leads to result.uxgrid == objB.uxgrid instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status
    📚 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions