-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Coordinates not deep copy #7463
Comments
It seems that in copy IndexVariables are treated special and are explicitly excluded from copying. |
I think that the reverting change in IndexVariable came after refactoring copy in Xarray introduced some performance regression (#7209 (comment)). I didn't see #1463 (#1463 (comment)), though. It feels weird to me that we can mutate an IndexVariable via its |
should we then raise an error if someone tries to replace values in an index? |
Yes I think we should, but I might have missed the rationale behind allowing it if this is intentional. EDIT: perhaps better to issue a warning first to avoid some breaking change. We could also try to fix it (make a deep copy) at the same time as deprecating it, but that might be tricky without again introducing performance regressions. |
I would assume that deepcopy are completely going to copy the object, so if I change internal parts (like coordinates here), 1st object shall not change. It definitely affects the performance, but otherwise |
There are two issues:
|
I agree. We don't allow it on Now I see we already did this in https://github.com/pydata/xarray/pull/3862/files So I guess that got lost in the indexes refactor.
I would expect On that pandas thread I see:
Seems like we should all be setting the numpy data to be read-only with |
Hi, I am hitting the similar issue, and curious if there any plan for this issue. I think when |
If there are difficulties or ambiguities here, would it be reasonable to switch to deep-copying everything for the moment? If we can figure out optimizations on things that are definitely immutable, then great, but in the meantime any objections to defaulting to the slower-but-always-correct thing? |
I also just stumbled across this bug. A rogue plotting script is changing the longitude of a map internally, and even when passing the script a da.copy(), the da's own longitude is modified after plotting. Deep copies should be truly deep. If the performance loss is too large to pass on to everyone, the copy function should get a new optional parameter to force the really-deep copy mode. |
I don't hear anyone clamoring to retain skipping indexes from deep copy. Would anyone like to do a PR to include them in deep copy, and we'll plan to merge that unless anyone comes up with a thought-through objection? |
What happened?
The coordinates are not copied if you perform deepcopy for xarray.
This issue was fixed before. I don't see it, for example, in
xarray 2022.12.0
, but in the latest version the issue is there again.Interesting, that if your coordinates are
int
, then the issue is goneWhat did you expect to happen?
Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
No response
Anything else we need to know?
No response
Environment
python 3.8.10
The text was updated successfully, but these errors were encountered: