You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
isel() with xr.DataArray indexer along grid dimension fails to include indexer's coordinates in result #1712
When using .isel() from a UxDataArray or UxDataset, and supplying an xr.DataArray as the indexer for a grid dimension, the xr.DataArray's coordinates are not included in the result.
importuxarrayasuxobj=ux.tutorial.open_dataset('quad-hexagon')
result=obj.isel(n_face=xr.DataArray(0, coords={'newcoord': 7}))
print(result.coords)
# expected 'newcoord' to be in result.coords, but it was not.# to see the corresponding xarray behavior, can try:result=obj.to_xarray().isel(n_face=xr.DataArray(0, coords={'newcoord': 7}))
print(result.coords)
# (in this case, 'newcoord' is indeed in result.coords)
Copy-pasting desired behavior as mentioned in comment in #1729:
The dims/coords of the Grid object should never incorporate indexer's dims/coords.
The dims/coords of the data object (UxDataArray or UxDataset) should not incorporate the indexer's dims when indexing along a grid dim (e.g. 'n_face') (this is already true), but should probably incorporate its coords (this isn't true yet; see issue 1712).
Here "incorporating the indexer's dims" would mean renaming the grid dim accordingly. For example, in pure xarray,
original = xr.DataArray(['a','b','c','d'], dims='letter')
indexer = xr.DataArray([0,2], dims='newdim')
result = original.isel(letter=indexer)
result.equals(xr.DataArray(['a','c'], dims='newdim')) # this is True
That makes sense in xarray. However, if "letter" was a grid dim like "n_face", and original was a UxDataArray, then result should still continue to use dim "n_face", not swap to "newdim".
Meanwhile, "incorporating the indexer's coords" would mean that all coords found in the indexer should be included in the result.
If indexer has a scalar coord like {"newscalar": 7} then the result should have result.coords['newscalar']==7. If indexer had any 1D coords along newdim, like from calling indexer.assign_coords({'new1dcoord': ('newdim', [-100, 200])}), then the result should have those coord(s) along the grid dim, e.g. result.coords["new1dcoord"] == [-100, 200], along "n_face" dim. EDIT: note: this cannot always apply for "n_node" and "n_edge" indexing, because the result's size might not equal the indexer's size in those cases.
2D+ indexers do not need to be handled because they are not supported along grid dims.
Activity
Sevans711 commentedon Sep 14, 2026
Copy-pasting desired behavior as mentioned in comment in #1729:
Here "incorporating the indexer's dims" would mean renaming the grid dim accordingly. For example, in pure xarray,
That makes sense in xarray. However, if "letter" was a grid dim like "n_face", and
originalwas a UxDataArray, then result should still continue to use dim "n_face", not swap to "newdim".Meanwhile, "incorporating the indexer's coords" would mean that all coords found in the indexer should be included in the result.
If indexer has a scalar coord like {"newscalar": 7} then the result should have result.coords['newscalar']==7. If indexer had any 1D coords along newdim, like from calling
indexer.assign_coords({'new1dcoord': ('newdim', [-100, 200])}), then the result should have those coord(s) along the grid dim, e.g. result.coords["new1dcoord"] == [-100, 200], along "n_face" dim. EDIT: note: this cannot always apply for "n_node" and "n_edge" indexing, because the result's size might not equal the indexer's size in those cases.2D+ indexers do not need to be handled because they are not supported along grid dims.
update sel/isel docstrings to clarify #1712 fix
Fix isel() bugs: missing indexers' coords; UxDataset.isel() silently …