Skip to content
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

DEPR: groupby nuisance warnings #46010

Closed

Conversation

rhshadrach
Copy link
Member

@rhshadrach rhshadrach commented Feb 15, 2022

Follow up to #41475

The warning currently generated for pivot_table says groupby - but it points to the correct line of user code, and I think it's easy to understand what's going on from a user perspective. E.g.

df = pd.DataFrame(
    {
        "A": ["foo", "bar"],
        "B": ["small", "large"],
        "C": [1, 2],
        "D": ["3", "4"],
    }
)
result = pd.pivot_table(df, values=["C", "D"], index=["A"], columns=["B"], aggfunc="sum")

gives

scratch.py:61: FutureWarning: Dropping invalid columns in DataFrameGroupBy.sum is deprecated. In a future version, a TypeError will be raised. Before calling .sum, select only columns which should be valid for the function.
result = pd.pivot_table(df, values=["C", "D"], index=["A"], columns=["B"], aggfunc="sum")

cc @jbrockmendel

@rhshadrach rhshadrach added Deprecate Functionality to remove in pandas Warnings Warnings that appear or should be added to pandas labels Feb 15, 2022
@rhshadrach rhshadrach changed the title Groupby nuisance warnings DEPR: groupby nuisance warnings Feb 15, 2022
@@ -27,6 +27,7 @@
import numpy as np

from pandas._libs import reduction as libreduction
import pandas._libs.lib as lib
Copy link
Member

Choose a reason for hiding this comment

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

can include in previous line

@@ -258,6 +258,8 @@ def _check(self, df, method, expected_columns, expected_columns_numeric):
elif method in ["min", "max"]:
# these have numeric_only kwarg, but default to False
warn = FutureWarning
elif method in ["mean", "median", "prod", "cumprod", "sum", "cumsum"]:
Copy link
Member

Choose a reason for hiding this comment

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

comment here similar to L256, L259?

@rhshadrach
Copy link
Member Author

The deprecations are essentially correct, but for the wrong reason. They should be deprecated due to #46072 and not #41475. Will be reworking this.

@rhshadrach rhshadrach closed this Feb 19, 2022
@rhshadrach rhshadrach deleted the groupby_nuisance_warnings branch September 10, 2022 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas Warnings Warnings that appear or should be added to pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants