pydata / pydata/xarray

Whether a DataArray is copied when inserted into a Dataset depends on whether coordinates match exactly

Open
#630 18 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.