-
-
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
groupby_bins groups not correctly applied with built-in methods #7601
Labels
Comments
michaelaye
added
bug
needs triage
Issue that has not been reviewed by xarray team member
labels
Mar 9, 2023
I think this is a bug with not passing Use |
dcherian
added
topic-groupby
and removed
needs triage
Issue that has not been reviewed by xarray team member
labels
Mar 9, 2023
What do you mean? |
dcherian
added a commit
that referenced
this issue
Mar 29, 2023
* Save groupby codes after factorizing * Fix tests * Fix cftime resampling * Fix resampling codes. * codes is always a DataArray. * cleanup * WIP * Revert "WIP" This reverts commit c9e2a62. * Fix doctests * Fix cftime resampling Fix cftime resampling * Better resampling example code. * Fix test. * Fix bad merge * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Try fixing some typing * Avoid warning * Fix typing * Add regression test for #7601 Closes #7601 * Cleanup + fix typnig * Typing run * Fix --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Illviljan <14371165+Illviljan@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What happened?
Setup
I want to calculate image statistics per chunk in one dimension. Let's assume a very small image for demonstration purposes:
Trying to chunk this into three subimages, I use these bins into the x dimension:
I look at the groups this creates by default:
I don't understand the use-case for this grouping, as it's missing the beginning and is having uneven sized last group (Obviously a follow-error from not including the first row).
To force the even chunking of the image I need to call it with these parameters:
Issue
But now, calculating the mean value of each group, I get different results when doing it by hand using the groups or doing it using the groups inherent method
mean()
:Indeed, I verified, that these results are what one gets, using the first version of applying the bins:
The same is true when I use the elliptical operator to receive the mean over the remaining dimensions (note, the 2nd cell here is using the
groups
variable as defined in the cell before, so should really return the same values, but it doesn't:Application
I believe that
groupby_bins
is the most appropriate tool to do this in xarray. I wished that one could enforce the dask-chunks in dask arrays to survive and return stats from them, but haven't found a way to do that.What did you expect to happen?
That the inherent stats methods of the
groups
method respect the interval use constraints from thegroupby_bins
call.I also have verified that the same problem exists with
groups.std()
.Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
No response
Anything else we need to know?
No response
Environment
INSTALLED VERSIONS
commit: None
python: 3.10.9 | packaged by conda-forge | (main, Feb 2 2023, 20:20:04) [GCC 11.3.0]
python-bits: 64
OS: Linux
OS-release: 6.0.12-76060006-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.12.2
libnetcdf: 4.9.1
xarray: 2023.2.0
pandas: 1.5.3
numpy: 1.23.5
scipy: 1.10.1
netCDF4: 1.6.3
pydap: None
h5netcdf: None
h5py: 3.8.0
Nio: None
zarr: None
cftime: 1.6.2
nc_time_axis: None
PseudoNetCDF: None
rasterio: 1.3.6
cfgrib: None
iris: None
bottleneck: 1.3.7
dask: 2023.3.0
distributed: 2023.3.0
matplotlib: 3.7.1
cartopy: 0.21.1
seaborn: 0.12.2
numbagg: None
fsspec: 2023.3.0
cupy: None
pint: None
sparse: None
flox: 0.6.8
numpy_groupies: 0.9.20
setuptools: 67.5.1
pip: 23.0.1
conda: installed
pytest: 7.1.3
mypy: None
IPython: 8.7.0
sphinx: None
The text was updated successfully, but these errors were encountered: