-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
API: inconsistent return format of groupby apply #13056
Comments
You are trying to do too much inside an apply which is completely non-performant.
I'll mark it as an issue if you'd like to investigate whether this could be made consistent w/o breaking anything else (might not be possible). |
this was changed by this: #3239 sort of a special case was added I think. |
yep, I think the way you(@jreback) use do solve problem of inconsistent return format, However, sometimes it's important to keep the groupby variables as a label, which your method failed to. what's more, the function in |
@edfall and so how would you reconcile this issue? I don't think you can infer what format the user wants and meet all users expectations. |
of cause, it's really difficult to meet all users' satisfaction, but return format of any specific application should always keep the same. and I think the result should at least be something like: df.groupby('y').apply(lambda x: x.x)
#y
#1 0 2.481148
# 1 -1.324170
# 2 0.783518
# 3 0.869827
# 4 -0.080157
# 5 0.071685
# 6 0.987246
# 7 0.099149
# 8 -0.159449
# 9 -0.383200 Maybe I have use R package |
Also related to this: #14927 (about detecting mutating functions) |
Here is a short notebook with an overview of the behaviours: http://nbviewer.jupyter.org/gist/jorisvandenbossche/16f511fe111a8b9fa0eac74e920c5251 Some things to note:
I think in gerenal the second bullet point above makes sense. Only the Series differentiation is a bit strange. Do we want to keep this? Additional note:
cc @WillAyd (the above is only for functions |
I ran into the same issue. Need a consistent behavior for this. |
Also hitting a problem because of the inconsistent shape of what apply returns. +1 for fix please! |
get the same problem. It is very annoying that every time I call group(...).apply(), I need to check how many groups are there in order to further process the result. Please fix. |
@liushapku are you interested in working on it? |
I'm still encountering this issue of inconsistent return formats as mentioned in #5839 with pandas 1.4.4 and 1.5 |
Same here |
related issues:
Thank you very much for provide us pandas which is really a good packages I have used!
There were several times when I use pandas but get inconsistent return format which finally leads to a break!
even though, I knew the way to avoid this issue, I still believe it is better to return the same format. It's really annoying when some inconsistent return format happened which force me to look backwards to use some awkward methods to avoid it.
So, if possible, I do suggest the above function will only return one kind of format.
The text was updated successfully, but these errors were encountered: