Skip to content

Bugfix/coords not deep copy #2930

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
wants to merge 2 commits into from

Conversation

pletchm
Copy link
Contributor

@pletchm pletchm commented Apr 29, 2019

This pull request fixes a bug that prevented making a complete deep copy of a DataArray or Dataset, because the coords weren't being deep copied. It took a small fix in the IndexVariable.copy method. This method now allows both deep and shallow copies of coords to be made.

This pull request corresponds to this issue #1463.

  • Tests added
  • Fully documented, including whats-new.rst for all changes and api.rst for new API

Sync with upstream master
@pep8speaks
Copy link

pep8speaks commented Apr 29, 2019

Hello @pletchm! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-04-30 01:17:27 UTC

@pletchm pletchm force-pushed the bugfix/coords-not-deep-copy branch from 05fd8f5 to b14497f Compare April 29, 2019 22:52
…le.copy method

Update whats-new.rst to include this change in the bugfix section
@pletchm pletchm force-pushed the bugfix/coords-not-deep-copy branch from b14497f to 3d96498 Compare April 30, 2019 01:17
@pletchm
Copy link
Contributor Author

pletchm commented May 2, 2019

I'm perplexed by why the build and tests are failing on this. I'm going to try 3 things:

  1. Make a new branch from master and PR (making sure my fork master is synced up with the upstream master) to see if the tests/build pass without any additional commits
  2. Commit my non-test changes and see if the build/tests pass
  3. Commit my tests and see if the build/tests pass
    Then I'll rebase my 2 commits into 1 commit.

@pletchm pletchm closed this May 2, 2019
@mgaspary
Copy link

mgaspary commented Jan 20, 2023

seems like the same issue again:

import xarray as xr

xarr1 = xr.DataArray(
    np.zeros([2]), 
    coords=dict(x=[0.0, 1.0]), # important to use 'float' here! with 'int' it is working fine
    dims=("x")
)
print(xarr1.x.data[0]) # 0.0

xarr2 = xarr1.copy(deep=True)
xarr2.x.data[0] = 45
print(xarr1.x.data[0]) # gives 45

@mgaspary mgaspary mentioned this pull request Jan 20, 2023
4 tasks
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.

3 participants