Skip to content

add_bounds creates broken dataset with xarray's new keep_attrs default #607

@aulemahal

Description

@aulemahal

Since "2025.11.0", xarray's default for keep_attrs is now True. When we call ds.cf.add_bounds(...) the attributes from the coordinate are copied over to the created bounds, which is incorrect and breaks cf-xarray as the new bounds are now also detected as a coordinate.

Example:

import cf_xarray as cfxr
import xarray as xr
ds = xr.tutorial.open_dataset('air_temperature')
dsb = ds.cf.add_bounds('longitude')

ds.cf:

Coordinates:
             CF Axes: * X: ['lon']
                      * Y: ['lat']
                      * T: ['time']
                        Z: n/a

      CF Coordinates: * longitude: ['lon']
                      * latitude: ['lat']
                      * time: ['time']
                        vertical: n/a
[...]

dsb.cf:

Coordinates:
             CF Axes:   X: ['lon', 'lon_bounds']
                      * Y: ['lat']
                      * T: ['time']
                        Z: n/a

      CF Coordinates:   longitude: ['lon', 'lon_bounds']
                      * latitude: ['lat']
                      * time: ['time']
                        vertical: n/a

lon_bounds should not be there.

I can suggest a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions