Skip to content

Topological aggregations drop coordinates and attributes #1665

Description

@rajeeja

While reviewing #1588 I went digging through aggregation.py and came across this, which turns out to be broken on main already, independent of that PR.

_node_to_face_aggregation and _node_to_edge_aggregation rebuild the output from data/dims/name only, so all coordinates and variable attributes are dropped. The result keeps its time dimension but loses the time coordinate:

uxda = ux.UxDataArray(data, dims=("time", "n_node"),
                      coords={"time": pd.date_range("2000-01-01", periods=6, freq="MS")},
                      uxgrid=grid, attrs={"units": "m"})

r = uxda.topological_mean(destination="face")
r.coords   # []   <- time gone
r.attrs    # {}   <- units gone

r.sel(time="2000-03-01")       # KeyError: 'time'
r.groupby("time.season")       # KeyError: 'time'
r.resample(time="QS")          # TypeError: Only valid with DatetimeIndex...

CI misses it because the existing tests use areaTriangle, which is 1-D with no leading coordinate, so there is nothing to lose.

This is also relevant to #1588: the dask paths added there go through apply_ufunc, which propagates coords and attrs for free, so on that branch the numpy and dask paths disagree and .chunk() starts deciding whether .sel(time=...) works. Fixing the numpy path on main makes them agree.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingextra dimsHandling of non-grid dimensions, such as time or altitude

    Type

    No type

    Projects

    Status
    🏗 In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions