Open max-sixty opened 1 day ago
Hmmm... we've lost an error message somewhere in all the groupby PRs I've been pushing. Note it doesn't work at all without flox
ValueError: cannot reduce over dimensions ['a']. expected either '...' to reduce over all dimensions or one or more of ('stacked_a_b',).
we've lost an error message somewhere in all the groupby PRs I've been pushing
As in, we should fail but we don't?
Note it doesn't work at all without flox
Good point...
For completeness, stacking is a reasonable workaround (with or without flox)
with xr.set_options(use_flox=False):
print(d.groupby('g').sum('stacked_a_b'))
<xarray.DataArray (g: 2)> Size: 16B
array([2., 2.])
Coordinates:
* g (g) int64 16B 42 52
Yes we should be erroring with same message in both cases.
For completeness, stacking is a reasonable workaround (with or without flox)
This isn't the same! You can't apply a subset of dims without .map(lambda g: g.unstack().mean(dim))
This isn't the same! You can't apply a subset of dims without
.map(lambda g: g.unstack().mean(dim))
Ah yes, ofc
Yes we should be erroring with same message in both cases.
Am I right in thinking we're pretty close to the correct result though? We're just missing putting the labels on?
(obviously it would still be work, reasonable to error in the meantime — but is my assessment correct that the difficult piece is working correctly?)
Am I right in thinking we're pretty close to the correct result though? We're just missing putting the labels on?
Yes correct, flox supports this. Though I think .mean('a')
fails ...
I wanted consistent behaviour in both code paths that's all...
Note this is a dupe of #1013 though this one is clearer about the end-goal.
Yes correct, flox supports this. Though I think
.mean('a')
fails ...
You're correct!
Note this is a dupe of #1013 though this one is clearer about the end-goal.
Ah OK, now I understand #1013 more clearly :) Shall we close this and link from that?
What happened?
When grouping by a coord which has multiple dimensions and reducing by a subset of dimensions, the returned dimensions are given as the int values
(0,1)
, rather than the actual labels.Check out MCVE below
What did you expect to happen?
No response
Minimal Complete Verifiable Example
This is as expected:
But then we get
g (g) int64 16B 0 1
if we do.sum('a')
:Notably, removing some of the conditions make it work fine:
MVCE confirmation
Relevant log output
No response
Anything else we need to know?
Happens both on current and earlier versions of xarray — doesn't seem like a new thing with the recent groupby changes
Environment