-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: #57775 Fix groupby apply in case func returns None for all groups #57800
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: #57775 Fix groupby apply in case func returns None for all groups #57800
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems reasonable to me. @rhshadrach
pandas/core/groupby/groupby.py
Outdated
Groups for which ``func`` returns ``None`` will be filtered from the result. | ||
|
||
.. versionchanged:: 2.2.2 | ||
|
||
In case all groups are filtered from the result, an empty DataFrame | ||
with the columns and dtypes of the original dataframe will be returned. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Groups for which ``func`` returns ``None`` will be filtered from the result. | |
.. versionchanged:: 2.2.2 | |
In case all groups are filtered from the result, an empty DataFrame | |
with the columns and dtypes of the original dataframe will be returned. |
(the example below is sufficient)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the description, only left the example
doc/source/whatsnew/v2.2.2.rst
Outdated
@@ -21,7 +21,7 @@ Fixed regressions | |||
|
|||
Bug fixes | |||
~~~~~~~~~ | |||
- | |||
- :meth:`DataFrameGroupBy.apply` was returning a completely empty DataFrame when all return values of ``func`` were ``None`` instead of returning an empty DataFrame with the original columns and dtypes. (:issue:`57775`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this to v3.0.0.rst
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
doc/source/whatsnew/v2.2.2.rst
Outdated
@@ -22,7 +22,6 @@ Fixed regressions | |||
Bug fixes | |||
~~~~~~~~~ | |||
- | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you undo this white space change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks, I missed that one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Thanks @dontgoto |
… all groups (pandas-dev#57800) * Ensure that the empty frame has the information of the original frame * Adjust test to expect DataFrame with columns * Construct leaner dataframe * Update doc * Add example to doc * Update whatsnew * Add issue #; phrasing * Fix doc * Fix doc * Fix docstring formatting * move from 2.2.2 to 3.0.0 * remove description * fix whitespace
doc/source/whatsnew/v2.2.2.rst
file if fixing a bug or adding a new feature.In case the func passed to DataFrameGroupBy.apply returns None for all groups (filtering out all groups), the original dataframe's columns and dtypes are now part of the empty result dataframe.