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: groupby doesn't identify null values when sort=False #48506

Closed
rhshadrach opened this issue Sep 11, 2022 · 2 comments · Fixed by #48539
Closed

BUG: groupby doesn't identify null values when sort=False #48506

rhshadrach opened this issue Sep 11, 2022 · 2 comments · Fixed by #48539
Assignees
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Bug Groupby Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@rhshadrach
Copy link
Member

rhshadrach commented Sep 11, 2022

Closely related to #48476

As far as I can tell this only occurs when the input dtype to groupby is object.

df = pd.DataFrame({'a': [np.nan, pd.NA, None], 'b': [1, 2, 3]})
gb = df.groupby('a', sort=True, dropna=False)
print(gb.sum())

#      b
# a     
# NaN  6

but with sort=False:

df = pd.DataFrame({'a': [np.nan, pd.NA, None], 'b': [1, 2, 3]})
gb = df.groupby('a', sort=False, dropna=False)
print(gb.sum())

#       b
# a      
# NaN   1
# <NA>  2
# None  3

I think we should prefer the sort=True behavior as that is the default value for now, but prefer sort=False in the long run.

@rhshadrach rhshadrach added Bug Groupby Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Needs Discussion Requires discussion from core team before further action Regression Functionality that used to work in a prior pandas version and removed Needs Discussion Requires discussion from core team before further action labels Sep 11, 2022
@rhshadrach
Copy link
Member Author

rhshadrach commented Sep 11, 2022

This is a regression that occurred in #46601, cc @rhshadrach. Prior to this, the sort=False behavior agreed with sort=True in collapsing different types of null values.

@phofl phofl added this to the 1.5 milestone Sep 11, 2022
@phofl
Copy link
Member

phofl commented Sep 11, 2022

Added 1.5 milestone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Bug Groupby Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants