Skip to content

BUG: Don't apply function to grouper #5908

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

Closed
TomAugspurger opened this issue Jan 11, 2014 · 2 comments
Closed

BUG: Don't apply function to grouper #5908

TomAugspurger opened this issue Jan 11, 2014 · 2 comments
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Groupby

Comments

@TomAugspurger
Copy link
Contributor

This came up in #5264, especially here, here, and this SO post.

Essentially, there are cases now where the agg or transform or apply function is applied to the grouper. This can cause failures in some very odd ways. As a simple example:

In [25]: df = pd.DataFrame({"A": ['a', 'b', 'a', 'b'], 'B': [1, 2, 3, 4]})

In [26]: df
Out[26]: 
   A  B
0  a  1
1  b  2
2  a  3
3  b  4

[4 rows x 2 columns]

In [28]: df.groupby('A').apply(lambda x: x+1)

TypeError: Could not operate 1 with block values cannot concatenate 'str' and 'int' objects

The example in the SO post linked above is especially subtle because the path the code follows depends on whether or not the aggfunc is successfully applied to the grouping column.

I'm going to poke around the code and see what breaks. I'd propose that we apply the function to the grouper in fewer (possibly zero) cases.

@jreback
Copy link
Contributor

jreback commented Apr 28, 2014

pushing to 0.15

@jreback jreback modified the milestones: 0.15.0, 0.14.0 Apr 28, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 3, 2015
@mroeschke
Copy link
Member

This looks tested and fixed. Closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Groupby
Projects
None yet
Development

No branches or pull requests

3 participants