Skip to content

Fix subset crashes for edge-centered data if face_edge_connectivity isn't populated - #1899

Open
lucas-santos-f wants to merge 1 commit into
UXARRAY:mainfrom
lucas-santos-f:subset-edge-centered-data
Open

lucas-santos-f wants to merge 1 commit into
UXARRAY:mainfrom
lucas-santos-f:subset-edge-centered-data

Conversation

@lucas-santos-f

Copy link
Copy Markdown

Closes #1888

Overview

UxDataArray.subset.bounding_box(), bounding_circle() and nearest_neighbor() slice the grid first and then slice the data with the indices the grid subset stores. For edge-centered data those are _subgrid_edge_indices, and _slice_face_indices only stores them when the grid already has face_edge_connectivity, so on a grid where it hadn't been built yet they raised KeyError: No variable named '_subgrid_edge_indices'.

The accessor now builds face_edge_connectivity before subsetting when the data has an n_edge dimension, the same fix #1875 makes in isel(). Face- and node-centered data are not affected. The other subset methods don't need it: constant_latitude() and constant_longitude() only accept face-centered data, and constant_latitude_interval() / constant_longitude_interval() go through isel(), so #1875 covers them (checked with #1875 applied on top of this branch). With both in, every subset method either works on edge-centered data or raises the existing face-centered-only error.

The new test runs the three methods on the quad-hexagon edge data, each selecting one face, and checks that the result holds the data on that face's six edges. It fails on main with the KeyError above and passes with this change. pytest test passes (1287 passed, 1 skipped, Python 3.13 on Windows) and pre-commit is clean.

Happy to adjust anything if needed.

PR Checklist

General

  • An issue is created and linked
  • [N/A] Added appropriate labels (if your uxarray repo permissions allow it)
  • Filled out Overview and Expected Usage (if applicable) sections

Testing & Benchmarking

  • There is adequate test coverage of changes from this PR (add new tests if needed)
  • [N/A] If this PR could affect performance, ran ASV benchmarks and confirmed they show expected behavior (add a new benchmark if necessary)

Documentation and Examples

  • Docstrings updated with any function changes, and included in all new functions
  • [N/A] User (public) functions added to docs/api.rst; internal (private) function names start with an underscore (_)
  • [N/A] If touched any notebook files, cleared the output of all cells before committing
  • [N/A] If added new notebook files, put into appropriate directories and referenced in appropriate files

AI Disclosure

AI Usage: Claude Code (Claude Opus 5.5) traced the cause, wrote the fix and the test, and ran the checks.

  • I have tested and take responsibility for all AI-generated content in my PR.

AI disclosure: this change was written with the help of Claude Code (Claude Opus 5.5).

…sn't populated

bounding_box(), bounding_circle() and nearest_neighbor() on edge-centered
data raised a KeyError for _subgrid_edge_indices when the grid had no
face_edge_connectivity yet, because the grid subset only slices edges
when that connectivity exists. Build it before subsetting, the same way
UXARRAY#1875 does for isel().

Closes UXARRAY#1888
@Sevans711
Sevans711 self-requested a review November 16, 2026 16:06
@Sevans711 Sevans711 added the bug Something isn't working label Nov 16, 2026
@Sevans711

Copy link
Copy Markdown
Collaborator

Hi @lucas-santos-f, thank you for opening this PR! I wanted to send a quick followup to let you know that this is on the uxarray team's to-do list, but reviews might not happen for a while (possibly a few weeks or more) since the underlying issue isn't necessarily a high priority right now. Although, if you or any uxarray users have encountered this issue directly while using uxarray, please feel free to mention that here, as that could certainly influence the priority level.

No pressure to answer this part, it is unrelated to this PR's contents, but if you are willing to share, what motivated you to contribute to uxarray? We are always trying to learn more about what leads people to find / use / contribute to uxarray!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

2 participants