Skip to content

isel() with xr.DataArray indexer along grid dimension fails to include indexer's coordinates in result #1712

Closed

Description

@Sevans711

Version

v2026.8.0

How did you install UXarray?

Source

What happened?

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.

What did you expect to happen?

I expected the xr.DataArray's coordinates to be included in the result where possible, consistently with xarray's behavior. See, e.g.: https://docs.xarray.dev/en/stable/user-guide/indexing.html#more-advanced-indexing

Can you provide a MCVE to repoduce the bug?

import uxarray as ux
obj = 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)

Activity

  1. added
    bug
    on Aug 26, 2026
  2. self-assigned this
    on Aug 26, 2026
  3. moved this from 📚 Backlog to 📝 To-Do in UXarray Developmenton Aug 31, 2026
  4. Sevans711 commented on Sep 14, 2026

    @Sevans711
    CollaboratorAuthor

    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.

  5. moved this from 📝 To-Do to 👀 In review in UXarray Developmenton Sep 14, 2026
  6. moved this from 👀 In review to ✅ Done in UXarray Developmenton Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Fields

Priority

None yet

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions