Skip to content

BUG: Update FutureWarning message to be more clear #55066

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
3 tasks done
RyanBerger98 opened this issue Sep 8, 2023 · 5 comments · Fixed by #55082
Closed
3 tasks done

BUG: Update FutureWarning message to be more clear #55066

RyanBerger98 opened this issue Sep 8, 2023 · 5 comments · Fixed by #55082
Assignees
Labels
Docs Error Reporting Incorrect or improved errors from pandas Groupby
Milestone

Comments

@RyanBerger98
Copy link

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
df = pd.DataFrame({"ID": [1,1,2,2,3],"B": [1,10,5,5,3]})
df_new = df[df.groupby(["ID"])["B"].transform(max) == df["B"]]

Issue Description

This isn't necessarily a bug, but the other issue categories didn't fit it either.

In #53974, the use of built-in callable functions for SeriesGroupBy.transform()was deprecated. The current FutureWarning message that is displayed is:

E       FutureWarning: The provided callable <built-in function max> is currently using SeriesGroupBy.max. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass 'max' instead.
/pandas/core/apply.py:1828: FutureWarning

While the change is reasonable, I think the warning message could be updated to better convey the message. When I first saw the warning message, I didn't realize what was wrong. Obviously using the built-in functions was no longer supported, but the message said to keep current behavior pass 'max' instead, however this is exactly what I was doing, but I was passing the callable max instead.

After some time of reading the release notes and documentation, I realized the warning message was referring to the string "max".

Expected Behavior

My proposal is to just update the FutureWarning produced from this to explicitly state a string should be passed. Updating

FutureWarning: .... To keep current behavior pass 'max' instead.

to

FutureWarning: .... To keep current behavior pass the string 'max' instead.

Installed Versions

2.1.0

@RyanBerger98 RyanBerger98 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 8, 2023
@lithomas1 lithomas1 added Docs Error Reporting Incorrect or improved errors from pandas and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 8, 2023
@lithomas1
Copy link
Member

Thanks for opening this issue.

A PR would be welcome for this.

@phofl phofl added this to the 2.1.1 milestone Sep 8, 2023
@rsm-23
Copy link
Contributor

rsm-23 commented Sep 9, 2023

@RyanBerger98 do you wish to work on this? Otherwise I'll take it up.

@rhshadrach
Copy link
Member

Perhaps

pass the string `"max"` instead

would be even more clear.

@rhshadrach rhshadrach added Groupby Needs Triage Issue that has not been reviewed by a pandas team member and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 9, 2023
@rsm-23
Copy link
Contributor

rsm-23 commented Sep 10, 2023

take

@RyanBerger98
Copy link
Author

@rsm-23 thanks for picking this up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Error Reporting Incorrect or improved errors from pandas Groupby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants