-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
BUG: Fix numeric_only ignored with list of functions in DataFrame.agg and GroupBy.agg (#49352) #62803
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
base: main
Are you sure you want to change the base?
Conversation
…er type checking with isinstance and type ignore
|
Thanks for the PR. The text in the OP here is very long and appears to be AI generated. It also contains a lot of information that is entirely redundant. Please do not do this - it is mostly noise and very little signal. A short summary of the PR and any additional details or context that are not found elsewhere would be appropriate. |
|
Thanks for the feedback |
rhshadrach
left a comment
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.
Thanks for the PR!
| # GH#49352 - Handle numeric_only with list of functions | ||
| # When numeric_only=True is passed with a list of functions, filter | ||
| # to numeric columns before processing to avoid TypeError on non-numeric Series | ||
| if op_name == "agg" and kwargs.get("numeric_only", False): |
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.
Only two of the five paths in DataFrameGroupBy.aggregate hits here, thus introducing inconsistencies. To accept a PR, we would need to do this consistently through the op. Take a look at the code in pandas.core.groupby.generic.
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.
You're right I need to ensure the filtering is applied consistently across all code paths in DataFrameGroupBy.aggregate.
I'll update the PR.
Closes #49352
When
numeric_only=Trueis used with a list of aggregation functions inDataFrame.agg()orGroupBy.agg(), non-numeric columns cause aTypeErrorbecause filtering isn't applied before the functions run.This PR filter to numeric columns before applying the list of functions when
numeric_only=Trueis specified.Changes-
NDFrameApplyandGroupByApplyinpandas/core/apply.pyto filter numeric columns before aggregationtest_frame_apply_numeric_only.pyandtest_aggregate_numeric_only.pyExample