Skip to content

Preserve coords and attrs in topological aggregations - #1666

Open
rajeeja wants to merge 1 commit into
mainfrom
rajeeja/fix_agg_coords_attrs
Open

Preserve coords and attrs in topological aggregations#1666
rajeeja wants to merge 1 commit into
mainfrom
rajeeja/fix_agg_coords_attrs

Conversation

@rajeeja

@rajeeja rajeeja commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Overview

Fixes #1665.

Came across this while reviewing #1588. Node-to-face and node-to-edge aggregations dropped every coordinate and all variable metadata, so .sel(time=...), groupby('time.season') and .resample(time=...) raised KeyError on the result, and units/long_name were lost for plotting and CF output.

The fix carries over any coordinate that does not span the reduced n_node dimension, plus the attrs. Coordinates along n_node (node_lon and friends) are still dropped, since after the reduction they would be the wrong length.

@cmdupuis3 — this should make #1588 simpler. The dask paths you added already preserve coords/attrs via apply_ufunc, so once this lands and you merge main, your numpy and dask paths will agree and .chunk() goes back to being purely a performance knob.

Testing

Three parametrized tests over face and edge: metadata preservation across all aggregations, the label-based indexing that was failing, and confirmation that node-spanning coords are still dropped. All 6 fail on main without the fix. Full suite 827 passed, 1 skipped; pre-commit clean.

Node-to-face and node-to-edge aggregations rebuilt the output UxDataArray
from data/dims/name only, so every coordinate and all variable metadata were
dropped. A result keeps its 'time' dimension but loses the 'time' coordinate,
which breaks label-based indexing downstream: .sel(time=...),
groupby('time.season') and .resample(time=...) all raise KeyError, and
units/long_name are lost for plotting and CF output.

Carry over any coordinate that does not span the reduced node dimension,
along with the variable attrs. Coordinates along n_node are still dropped,
since they no longer match the length of the output dimension.
@rajeeja
rajeeja requested a review from cmdupuis3 August 10, 2026 21:11
@rajeeja rajeeja added the bug Something isn't working label Aug 10, 2026
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

Development

Successfully merging this pull request may close these issues.

Topological aggregations drop coordinates and attributes

1 participant