Skip to content
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

BUG: coercing of bools in groupby transform #16875

Closed
jongmmm opened this issue Jul 10, 2017 · 1 comment · Fixed by #16895
Closed

BUG: coercing of bools in groupby transform #16875

jongmmm opened this issue Jul 10, 2017 · 1 comment · Fixed by #16895
Milestone

Comments

@jongmmm
Copy link

jongmmm commented Jul 10, 2017

Code Sample

df = pd.DataFrame({'A': [1.1,2.2], 'B':[1,2]})
df.groupby('B').A.transform(lambda x: True)

This returns

Out[3]:
0    1.0
1    1.0
Name: A, dtype: float64

Problem

groupby.transform returns numeric values, not bool . This is inconsistent
because DataFrame.transform behaves differently:

In [5]: df.A.transform(lambda x:True)
Out[5]:
0    True
1    True
Name: A, dtype: bool

Additional

But please note that if the original data type is int, it works properly:

In [9]: df = pd.DataFrame({'A': [1,2], 'B':[1,2]})
   ...: df.groupby('B').A.transform(lambda x: True)
   ...:
Out[9]:
0    True
1    True
Name: A, dtype: bool
@chris-b1
Copy link
Contributor

Looks essentially the same as #10972, which was closed by #15430, but apparently didn't capture this case. apply does do the right inference here:

In [2]: df.groupby('B').A.apply(lambda x: True)
Out[2]:
B
1    True
2    True
Name: A, dtype: bool

@chris-b1 chris-b1 added this to the Next Major Release milestone Jul 10, 2017
@jreback jreback changed the title Inconsistency in groupby transformation BUG: coercing of bools in groupby transform Jul 12, 2017
@jreback jreback modified the milestones: 0.21.0, Next Major Release Jul 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants