Assignment
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
Assignment of individual elements / subsets seems to be only partially supported, but I have not found clear documentation on it. After playing a bit around with xarray I believe the current support boils down to the following (I list some issues I see with the current documentation and how things seem to work).
DataSet
- Change a element in a associated DataArray
ds.loc[selector_dict].NAME_OF_VARIABLE = -1Doesn't work but at least throws an error (Use __setitem__ style assignment (e.g., ds['name'] = ...) instead to assign variables.)ds.loc[selector_dict]["NAME_OF_VARIABLE"] = -1Silently fails- Is it possible to throw an exception as well? I believe this usage variant is "more common", as
NAME_OF_VARIABLEmay only be known at runtime. #974 May fix this (?).
- Is it possible to throw an exception as well? I believe this usage variant is "more common", as
- Same goes for
ds.sel
DataArray
(Can be obtained via ds['name'])
- Using
.sel(which is documented to return a new DataArray, so arguably it's expected not to work)ds["NAME_OF_VARIABLE"].sel(**selector_dict) = -1Invalid python syntaxds["NAME_OF_VARIABLE"].sel(**selector_dict).values = -1Silently fails
- Using
.locds["NAME_OF_VARIABLE"].loc[selector_dict] = -1works
Is this the recommended behaviour? Then I believe the wrong pattern of ds.loc[selector_dict]["NAME_OF_VARIABLE"] = -1 should be documented and ds[NAME_OF_VARIABLE].loc[selector_dict] = -1 instead suggested.
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
Start by comparing the assignment behavior described for Dataset.loc, Dataset.sel, DataArray.sel, and DataArray.loc, then check the existing xarray documentation for these entry points. Done means the recommended assignment pattern and the behavior of silent failures are clearly documented, or the requested exception behavior is explicitly resolved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data, documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100