Skip to content

.sel() unexpectedly forgets to slice the uxgrid too, for UxDataArray and UxDataset #1641

Description

@Sevans711

Version

2026.7.0

How did you install UXarray?

Source

What happened?

When calling .sel() on a UxDataArray or UxDataset, the underlying uxgrid does not get sliced at all.

An example workflow that might want to utilize .sel() instead of .isel() is if you are slicing multiple times in a row, or doing subsetting, and want to utilize faces' original labels. In that case, it would be reasonable to do something like:

arr = ux.tutorial.open_dataset("outCSne30-vortex")['psi']
arr1 = arr.assign_coords(n_face=np.arange(arr.n_face.size))   # make sure to track the faces' original labels
arr2 = arr1.isel(n_face=range(0, 100, 5))
arr3 = arr2 + 7   # or some other math or analysis operations
# then realize "oh I want to check what the results look like on what were originally faces 20, 30, and 40"
arr4 = arr3.sel(n_face=[20,30,40])
# and "I want to remind myself where the data is located so I want to plot this"
arr4.plot()

This currently works up until the last line, when there is a crash because the grid wasn't also sliced to just faces 20, 30, and 40.

What did you expect to happen?

I expected .sel() to work similarly to .isel(); the underlying grid should be sliced appropriately. Or, at the very least, I expected to receive a warning message or a crash to suggest that .sel() is not yet fully supported by uxarray, rather than a confusing error later on when the data no longer aligns with the grid (for example, the code above makes ValueError: Length of values (3) does not match length of index (20)).

Can you provide a MCVE to repoduce the bug?

arrA = ux.tutorial.open_dataset("outCSne30-vortex")['psi']
arrB = arrA.sel(n_face=[20,30,40])
arrB.uxgrid.n_face   # Got 5400; expected 3.

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