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: inplace in DataFrameGroupBy.fillna and SeriesGroupBy.fillna #48792

Closed
rhshadrach opened this issue Sep 26, 2022 · 3 comments · Fixed by #55719
Closed

DEPR: inplace in DataFrameGroupBy.fillna and SeriesGroupBy.fillna #48792

rhshadrach opened this issue Sep 26, 2022 · 3 comments · Fixed by #55719
Labels
Deprecate Functionality to remove in pandas Groupby Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

Comments

@rhshadrach
Copy link
Member

Specifying inplace returns an empty frame or a Series with all None values, and neither modifies the original input. Instead of fixing this, I think we should deprecate the inplace argument of these methods.

df = pd.DataFrame({'a': [1, 1, 2], 'b': [np.nan, 3, np.nan]})
gb = df.groupby('a')

print(gb.fillna(0, inplace=True))
# Empty DataFrame
# Columns: []
# Index: []

print(gb['b'].fillna(0, inplace=True))
# a
# 1    None
# 2    None
# Name: b, dtype: object

print(df)
#    a    b
# 0  1  NaN
# 1  1  3.0
# 2  2  NaN
@rhshadrach rhshadrach added Groupby Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Deprecate Functionality to remove in pandas labels Sep 26, 2022
@ambujpawar
Copy link
Contributor

I am interested in picking up the issue.
Just a question though, how should this deprecation take place? Are we gonna give users warning when they are using inplace? Or inplace as a parameter should be competely removed from the code?

And shouldn't this change be applied to Series.fillna() and DataFrame.fillna() as well?

@rhshadrach
Copy link
Member Author

rhshadrach commented Sep 30, 2022

Are we gonna give users warning when they are using inplace? Or inplace as a parameter should be competely removed from the code?

Any time the user specifies the inplace parameter, a FutureWarning should be raised explaining that this argument will be removed in a future version of pandas with the default, False, being the behavior. You can do this by changing the default argument to lib.no_default. Also, a good source is taking a look at other deprecation PRs: https://github.com/pandas-dev/pandas/pulls?q=is%3Apr+label%3ADeprecate+is%3Aclosed.

And shouldn't this change be applied to Series.fillna() and DataFrame.fillna() as well?

That's currently being discussed in #16529 and is not in the scope here. The key difference is that inplace=True is completely broken in groupby. I can't imagine anyone using it, but there may be users who specify inplace=False and their code would break if we just removed it without a deprecation.

@ambujpawar
Copy link
Contributor

Thanks! Thats more than enough to get me started.
Thanks a lot again!

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 Groupby Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants