Skip to content

Add warning to .groupby when null keys would be dropped due to default dropna #61351

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

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

tehunter
Copy link
Contributor

@tehunter tehunter commented Apr 24, 2025

TODO:

  • Check performance for codes check approaches (codes.min() was about 3x faster)
  • Run full test suite to ensure nothing broke
  • Add tests/implementation for .pivot_table/.stack/etc. (possibly in a follow-up PR?)

Comment on lines +64 to +68
_NULL_KEY_MESSAGE = (
"`dropna` is not specified but grouper encountered null group keys. These keys "
"will be dropped from the result by default. To keep null keys, set `dropna=True`, "
"or to hide this warning and drop null keys, set `dropna=False`."
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a standard approach for a warning message that could be hit from two lines of code?

Comment on lines +489 to +493
@property
def dropna(self) -> bool:
if self._dropna is lib.no_default:
return True
return self._dropna
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know the implementation is trivial, but this is redundant with Grouper. I'm not sure we can get around it while still being a class property, but should the default value be referenced as a constant defined just once?

this will help with PDEP-11 (pandas-dev#53094) as an intermediate step to identify tests that will fail under the default value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Add warning when DataFrame.groupby drops NA keys
1 participant