Skip to content

attrs are now views, not copies #6996

@fmaussion

Description

@fmaussion

What is your issue?

I'm not sure yet if this is a feature or a bug - I would tend to the latter. Apologies if this has been discussed before.

Objects originating from operations such as y = x > 2 are now sharing the same attrs, which leads to things like:

import numpy as np
import xarray as xr
xr.__version__
'2022.6.0'

x = xr.DataArray(
    0.1 * np.arange(10),
    dims=["lat"],
    coords={"lat": np.arange(10)},
    name="sst",
)
x.lat.attrs['long_name'] = 'latitude'
x.lat.attrs
{'long_name': 'latitude'}

y = x > 2
y.lat.attrs
{'long_name': 'latitude'}

y.lat.attrs = {}
x.lat.attrs  # x is changed as well!
{}

I think this is rather a non-intuitive behavior but I'm happy to discuss!

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