-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Allow to group by an empty list #35366
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
Comments
If you don't want to group by anything (why use
But this doesn't support named aggergation AFAIK. |
seems reasonable. PRs and contributions welcome. may want to redo the OP and use the feature request template (available when opening issue but repeated in details below)
#### Is your feature request related to a problem?
[this should provide a description of what the problem is, e.g. "I wish I could use pandas to do [...]"] Describe the solution you'd like[this should provide a description of the feature request, e.g. " API breaking implications[this should provide a description of how this feature will affect the API] Describe alternatives you've considered[this should provide a description of any alternative solutions or features you've considered] Additional context[add any other context, code examples, or references to existing implementations about the feature request here] # Your code here, if applicable |
1.1.0 gives
but 1.0.1 raises The output seems iffy. not looked in detail. This may be an issue with 1.1.0. |
I see. I didn't realise that was to be taken as the literal structure. I have edited my OP.
Interesting. That output looks like a bug to me. I am on 1.0.3. |
Great, good to know. I did not test in my development version. I tested it in |
Firstly because allowing an empty list would be more uniform (perhaps it's a parameter passed in my someone else) and secondly, that's what I tried first, but it doesn't support what I want (what I think you refer to as "named aggregation"):
|
Generic support for named aggregations was added very recently in #29116 so I think you can achieve the result you want without the groupby on master, though to @simonjayhawkins point maybe there are sum bugs to be worked out FWIW I am -1 on changes to groupby here as I agree with @gurukiran07 comment that agg should generically handle |
Here's a related question on SO How to do a groupby on an empty set of columns pandas where Wes Mckinney posted
This may be one of the reasons why As @WillAyd and @simonjayhawkins pointed out named aggregations now allowed with
A workaround can be:
|
#29116 didn't add documentation on the enhancement (one-line whatsnew add later in #35220). I'm not sure that it's a bug, the tests appear this was intentional. imo the output should maybe be a Series, the output above is confusing. |
Sure, but why work around it when it's a perfectly coherent thing for the pandas API to support? |
+1 for that feature, it currently makes using pandas as a backend of another library difficult. I'm currently writing functions that expose an optional |
I found myself in the same situation where I wanted |
I am -1 as well: #55068 (comment) From that PR, users can do this if they want without much effort:
|
Since there hasn't been much support for this, closing |
Is your feature request related to a problem?
Yes, I cannot group by an empty list.
Describe the solution you'd like
I would like to be able to group by an empty list of columns. At the moment I get an error.
I would prefer to see
which would generalise grouping by a non-empty list, which works fine.
It seems to me this would be reasonable behaviour. Is there a particular reason it is not supported?
API breaking implications
None that I know of.
Describe alternatives you've considered
A partial workaround is to cook up a grouping function for simulating the behaviour I want, but this lacks uniformity.
But I don't really want
"Only row"
to be there. I just wantThe text was updated successfully, but these errors were encountered: