Skip to content

attrs are now views, not copies #6996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fmaussion opened this issue Sep 6, 2022 · 5 comments
Closed

attrs are now views, not copies #6996

fmaussion opened this issue Sep 6, 2022 · 5 comments

Comments

@fmaussion
Copy link
Member

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!

@fmaussion fmaussion added the needs triage Issue that has not been reviewed by xarray team member label Sep 6, 2022
@benbovy
Copy link
Member

benbovy commented Sep 6, 2022

I thought #6857 would have fixed it but apparently not.

@fmaussion
Copy link
Member Author

Yes sorry I also tested on main and this still occurs. Tagging this as bug.

@benbovy
Copy link
Member

benbovy commented Sep 6, 2022

This happens with previous versions too (e.g., 0.21.0). Is there an older version where it returned copies?

@fmaussion
Copy link
Member Author

Is there an older version where it returned copies?

Yes, tests started to fail on salem which I haven't maintained in quite a long time.

@fmaussion fmaussion added bug and removed needs triage Issue that has not been reviewed by xarray team member labels Sep 6, 2022
@fmaussion
Copy link
Member Author

Sorry false alarm the bug that caused salem tests to fail is indeed solved by #6857

Sorry for the noise.

@fmaussion fmaussion removed the bug label Sep 6, 2022
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

No branches or pull requests

2 participants