-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Reduction operations fail with Weighted DataArrayWeighted #9841
Comments
Thanks for opening your first issue here at xarray! Be sure to follow the issue template! |
Very much agree with your suggestion. It's likely worth spiking a quick example of what the code changes would look like. If it does delegate the Does that make sense? |
I don't think this is a good idea. Consider the case when the weights Dataset is mistakenly missing a couple of data vars. Then you'll unintentionally get unweighted means and not know about it! You might consider simply adding a scalar |
I'm interpreting this differently — the dataset has some data variables that are weighted and some that are unweighted. There's no Instead it's (when I'm confused during a discussion of ours, it's 3 times out of 4 me who's missing something, so asking from the perspective of likely being wrong but hopefully nonetheless helpful) |
What happened?
I have a
DataSet
with some weightedDataArrays
. This set-up is extremely useful to me as I can filter and perform operations over the whole dataset and all shared dimensions. One of theDataArrays
is weighted, and I was hoping this would be automatically handled in groupbys and general reduction operations, but the error thrown is below. If I callmean
on the dataset.I'm happy to raise a PR to fix if I can work out how to do it, but I just want to make sure that it's agreed that this isn't correct behaviour.
What did you expect to happen?
I would like
DataArray
s that are unweighted to return the usual mean, and forDataArrayWeighted
to return a mean reflecting their weights, as if I'd just calledda_weighted.mean()
. This would allow me to calculate means in groupbys on theDataSet
.Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
Anything else we need to know?
There are several functions that might fall into this category like
std
, but I think they could all be handled similarly.Environment
INSTALLED VERSIONS
commit: None
python: 3.12.3 (main, Jul 31 2024, 17:43:48) [GCC 13.2.0]
python-bits: 64
OS: Linux
OS-release: 5.15.153.1-microsoft-standard-WSL2
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C.UTF-8
LOCALE: ('C', 'UTF-8')
libhdf5: 1.14.4
libnetcdf: None
xarray: 2024.10.0
pandas: 2.2.3
numpy: 2.0.2
scipy: 1.14.1
netCDF4: None
pydap: None
h5netcdf: 1.4.0
h5py: 3.12.1
zarr: None
cftime: None
nc_time_axis: None
iris: None
bottleneck: 1.4.2
dask: None
distributed: None
matplotlib: 3.9.2
cartopy: None
seaborn: 0.13.2
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: 0.15.4
flox: None
numpy_groupies: None
setuptools: 75.3.0
pip: 24.0
conda: None
pytest: 8.3.3
mypy: 1.13.0
IPython: 8.29.0
sphinx: None
The text was updated successfully, but these errors were encountered: