Skip to content

Fix grid mappings after CF decoding - #673

Open
vera-rubin wants to merge 1 commit into
xarray-contrib:mainfrom
vera-rubin:fix/decoded-grid-mappings
Open

vera-rubin wants to merge 1 commit into
xarray-contrib:mainfrom
vera-rubin:fix/decoded-grid-mappings

Conversation

@vera-rubin

Copy link
Copy Markdown

Opening a dataset with decode_coords="all" moves grid_mapping from attrs to encoding. After that, .cf.grid_mappings raises AttributeError on DataArrays and returns empty coordinate associations on Datasets, although the API promises coordinate variable names.

import cf_xarray
import xarray as xr
from cf_xarray.datasets import rotds

decoded = xr.decode_cf(rotds, decode_coords="all")
decoded.cf.grid_mappings[0].coordinates  # Was (), should be ("rlon", "rlat")
decoded.temp.cf.grid_mappings  # Raised AttributeError

We now read associations from both metadata mappings, keeping attrs precedence and the declared order for multiple mappings.

The regression test covers both accessors with single and multiple mappings, and the accessor suite passes.

Tested: cf-xarray main at b0ecc0d and xarray 2026.9.0.

— ChipLab

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant