Closed max-sixty closed 1 month ago
The error message mentions: Try passing .groupby(..., squeeze=False)
which ends up working. This will be fixed once we finally make that the default. It's been warning for 7 months now.
Or we can fix the bug here: https://github.com/pydata/xarray/blob/d0048ef8e5c07b5290e9d2c4c144d23a45ab91f7/xarray/core/groupby.py#L812-L818
We need to raise the error for virtual variables too.
OK great!
(so I understand — when we change the default, would da.groupby(dim).mean()
work — i.e. with no dim passed to mean
? Or we'll still mandate a dim passed to mean? Currently da.groupby('time').mean()
~fails~ passes but da.groupby('lat').mean()
fails, seemingly because lat
is a float index... )
Turns out it has to do with sortedness of lat
. We only check.is_monotonic_increasing
but yes if I pass squeeze=False
it all works.
Could switch it to add is_monotonic_decreasing
too.
https://github.com/pydata/xarray/issues/6220 https://github.com/pydata/xarray/pull/7427
OK great!
So it sounds like after we make that change, it won't be required to pass any dimensions to the aggregation func — da.groupby('lat').mean()
, (with nothing passed to mean()
), will aggregate over groups along lat
without reducing any other dims. (lmk if I'm mistaken)
That'll be much better than the current state, where not passing anything to mean()
works depending on the dimension's sortedness + whether flox is installed. Notably, if we only add is_monotonically_decreasing
without making squeeze=False
the default, it'll still depend on the array sortedness.
TY!
Setting squeeze=False
makes it always work.
main
. Perhaps we should just delete the squeeze
kwarg, it's been a pain for quite long.OK v nice — on #7427 this dependably works on both flox & no flox, both ordered & unordered.
with xr.set_options(use_flox=True):
print(da.assign_coords(lat=lambda x: x.lat % 2).groupby('lat', squeeze=False).sum())
Closed by #9280, thanks !
What happened?
(Following up from https://github.com/pydata/xarray/issues/8263)
Without flox:
But with flox:
What did you expect to happen?
Identical behavior
Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
No response
Anything else we need to know?
No response
Environment