Skip to content

BUG: Update FutureWarning message to be more clear #55066

Closed
@RyanBerger98

Description

@RyanBerger98

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions