-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: fixes pd.Grouper for non-datetimelike groupings #8866 #8964
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
Conversation
returns basegrouper class for non-datetime groupings while still returning a datetime index for datetime grouping
this needs a test. This should be a much simpler change. |
I thought it was going to be simpler, maybe I've missed something but I couldn't get around that I needed to pass a basegrouper to aggregate and a datetime index to resample. |
dbdc3f3
to
2162586
Compare
no, this just needs a small change in when |
Ah I see, I presumed TimeGrouper should only be used for datetimes, (was that originally the case?). So anything that gets passed into groupby as a grouper will be handled by the |
2162586
to
00eb085
Compare
I've had a look again and it's easy enough to return a |
00eb085
to
139342e
Compare
139342e
to
1aebb81
Compare
no this should be virtually identical to setting the index then resampling (in fact that can be w test) |
how can we resample on a non-datetime index? |
I mean groupby. |
turns out this was a trivial issue, see #9008 thanks for the effort |
closes #8866
The bug was caused by a couple of things, firstly when specifying only a level, the axis default was None. This meant it failed to create the internal grouper breaking on line 254 of groupby.py:
Secondly, the aggregate function is set up to take a basegrouper class whereas for datetime resampling we need to pass a datetime index. I split the
_set_grouper
method to return a datetime index when a resampling frequency is specified and aBaseGrouper
class otherwise. I opted to split that out into two functions to reduce complexity with much of the_set_basegrouper
function being borrowed from the_get_grouper
function. Let me know if there's a better way to fix this.