Whether a DataArray is copied when inserted into a Dataset depends on whether coordinates match exactly
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
Consider
import numpy as np
from xray import *
ds = Dataset({"a": DataArray(np.zeros((3, 4)))})
ds["b"] = b = DataArray(np.zeros((3, 4)))
b[0, 0] = 1
print(ds["b"][0, 0]) # ==> prints 1
ds = Dataset({"a": DataArray(np.zeros((3, 4)))})
ds["b"] = b = DataArray(np.zeros((3, 3))) # !!! we implicitly fill the last column with nans.
b[0, 0] = 1
print(ds["b"][0, 0]) # ==> prints 0
In the first case, the dataset was modified when the dataarray was modified, but not in the second case.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce both examples from the issue and inspect the Dataset insertion and coordinate-alignment paths involved in assigning a DataArray. No file or test is named; done should mean the copy behavior for matching and nonmatching coordinates is consistent and covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100