Skip to content

.isel() modifies indexers dict, causing inconsistent behavior across repeated calls #1711

Description

@Sevans711

Version

v2026.8.0

How did you install UXarray?

Source

What happened?

When using UxDataArray.isel(indexers) or UxDataset.isel(indexers) with a pre-defined indexers dict, the dict itself is edited, so repeating the same .isel() code multiple times leads to different results.

What did you expect to happen?

I expected the indexers dict to not be modified directly.

The fix should be simple; inside .isel() methods, use a copy of indexers instead of popping grid_dim from the original.

Can you provide a MCVE to repoduce the bug?

obj = ux.tutorial.open_dataset('quad-hexagon')  # obj is a UxDataset
chosen_faces = {'n_face': 0}
resultA = obj.isel(chosen_faces)
resultB = obj.isel(chosen_faces)
print((resultA.sizes['n_face'], resultB.sizes['n_face']))
# expected (1, 1), got (1, 4)
print(chosen_faces)
# expected {'n_face': 0}, got {}

# same issue occurs with UxDataArray, e.g. try above with obj=obj['t2m']

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status
📝 To-Do

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions