don't apply `weighted`, `groupby`, etc. to `DataArray` without `dims`?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
What is your issue?
Applying e.g. ds.weighted(weights).mean() applies the operation over all DataArray objects - even if they don't have the dimensions over which it is applied (or is a scalar variable). I don't think this is wanted.
import xarray as xr
air = xr.tutorial.open_dataset("air_temperature")
air.attrs = {}
# add variable without dims
air["foo"] = 5
print("resample")
print(air.resample(time="MS").mean(dim="time").foo.dims)
print("groupby")
print(air.groupby("time.year").mean(dim="time").foo.dims)
print("weighted")
print(air.weighted(weights=air.time.dt.year).mean("lat").foo.dims)
print("where")
print(air.where(air.air > 5).foo.dims)
Results
resample
('time',)
groupby
('year',)
weighted
('time',)
Related #6952 - I am sure there are other issues, but couldn't find them quickly...
rolling and coarsen don't seem to do this.
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 running the provided reproduction against the Dataset operations resample, groupby, weighted, and where, checking the dimensions of the scalar foo variable. Compare these results with rolling and coarsen, then determine the consistent expected behavior for variables without the requested dimensions. Done means the affected operations no longer add those dimensions to scalar or otherwise unrelated DataArrays, with regression coverage for the demonstrated cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100