Skip to content

UxDataArray.isel() on edge-centered data crashes with confusing KeyError: No variable named '_subgrid_edge_indices'... if connectivity isn't populated #1758

Open

Description

@Sevans711

Version

v2026.09.1

How did you install UXarray?

Source

What happened?

Calling UxDataArray.isel(n_face=...) or .isel(n_node=...) on edge-centered data crashes with a very confusing error (see title). I suspect this is related to the lines in uxarray.grid.slice._slice_face_indices commented as "Only slice edge dimension if we have the face edge connectivity", which hide the ds["_subgrid_edge_indices"] = xr.DataArray(edge_indices, dims=["n_edge"]) inside a check of if "face_edge_connectivity" in ds, and when that check gives False it silently does something else instead of crashing or raising a warning.

This problem currently only affects UxDataArray, not also UxDataset, because UxDataset simply ignores the command to slice by anything (see #1713) in these cases.

What did you expect to happen?

I expected a clearer error message telling me why I can't do this, or suggesting that I should call arr.uxgrid.face_edge_connectivity to populate the connectivity and then try again, or for the connectivity to just be automatically populated at this stage because it was required for an operation I was attempting (most/all other uxarray grid vars get populated automatically as soon as they are needed…).

Can you provide a MCVE to repoduce the bug?

import uxarray as ux
arr = ux.tutorial.open_dataset('quad-hexagon-random-edge')['random_data_edge']
arr.isel(n_face=0)  # crashes
arr.isel(n_node=0)  # crashes

# but, if running the following before calling isel():
arr.uxgrid.face_edge_connectivity

# then the isel() commands do not crash:
arr.isel(n_face=0)
arr.isel(n_node=0)

Activity

  1. moved this from 📚 Backlog to On Pause in UXarray Developmenton Sep 21, 2026
  2. moved this from On Pause to 📝 To-Do in UXarray Developmenton Oct 28, 2026
  3. self-assigned this
    on Nov 3, 2026
  4. Sevans711 commented on Nov 3, 2026

    @Sevans711
    CollaboratorAuthor

    It is probably reasonable to just populate face_edge_connectivity in this case, now that the connectivity is much faster to compute (see, e.g., #1560 (comment)) compared to when this isel() routine was initially introduced. If connectivity was slow to compute it might be a different story, but since it is relatively fast (e.g. just a few seconds even for 3.75km MPAS grid) I suspect the user experience would be better if this just gets handled automatically.

  5. moved this from 📝 To-Do to 🏗 In progress in UXarray Developmenton Nov 4, 2026
  6. moved this from 🏗 In progress to 👀 In review in UXarray Developmenton Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Fields

Priority

Medium

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions