Skip to content

Needs Triage: In aggregation, pd.Series.nunique outputs float instead of int. #42383

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
qniksefat opened this issue Jul 5, 2021 · 2 comments
Closed
Labels
Dtype Conversions Unexpected or buggy dtype conversions Groupby

Comments

@qniksefat
Copy link

qniksefat commented Jul 5, 2021

Sorry, I'm very new to issuing. I'm not sure if it's a bug or improvement. Here it is.

When you count the number of unique values in a groupby aggregation, you'll get a float output when the values are float themselves.

df = pd.DataFrame({
    'a': 4 * list(range(1, 3)),
    'b': map(float, list(range(1, 9)))
})

df
   a    b
0  1  1.0
1  2  2.0
2  1  3.0
3  2  4.0
4  1  5.0
5  2  6.0
6  1  7.0
7  2  8.0
df.groupby('a').agg({'b': pd.Series.nunique}).b
a
1    4.0
2    4.0
Name: b, dtype: float64

Problem description

If the type of b is int, it outputs int, but not for the float type. Nevertheless, the unique number is int no matter what.

Expected Output

a
1    4
2    4
Name: b, dtype: int64
@qniksefat qniksefat added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 5, 2021
@mzeitlin11
Copy link
Member

Thanks for reporting this @qniksefat! This works on master (and the latest version 1.3). I'd guess this was fixed by #40790, where it looks sufficiently tested.

@mzeitlin11 mzeitlin11 added Closing Candidate May be closeable, needs more eyeballs Dtype Conversions Unexpected or buggy dtype conversions Groupby and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 5, 2021
@rhshadrach rhshadrach removed the Closing Candidate May be closeable, needs more eyeballs label Jul 7, 2021
@rhshadrach
Copy link
Member

Agreed @mzeitlin11. @qniksefat if you are still setting this (or related) behavior on 1.3, please comment here and can reopen.

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

No branches or pull requests

3 participants