question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

API/DEPR: Deprecate inplace parameter

See original GitHub issue

The parameter inplace=False should be deprecated across the board in preparation for pandas 2, which will not support that input (we will always return a copy). That would give people time to stop using it.

Thoughts?

Methods using inplace:

Deprecation non controvertial (a copy will be made anyway, and inplace=True does not add value):

  • (Series/DataFrame).drop
  • (Series/DataFrame).drop_duplicates
  • (Series/DataFrame).dropna
  • DataFrame.set_index (with drop=False wouldn’t change the data, but that doesn’t seem the main use case)
  • DataFrame.query
  • DataFrame.eval

Not sure:

  • (Series/DataFrame).sort_values
  • (Series/DataFrame).sort_index

Should be able to not copy memory (under discussion on what to do):

  • (Series/DataFrame).clip
  • (Series/DataFrame).where
  • (Series/DataFrame).fillna
  • (Series/DataFrame).rename_axis
  • (Series/DataFrame).reset_index
  • (Series/DataFrame).replace
  • (Series/DataFrame).set_axis
  • (Series/DataFrame).mask
  • (Series/DataFrame).interpolate
  • DataFrame.rename
  • Index.rename
  • Index.set_names
  • MultiIndex.set_levels
  • MultiIndex.set_labels
  • pandas.core.resample.Resampler.interpolate

Special cases:

  • pandas.eval (with inplace=False the value is not returned but set to an argument target)

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:41
  • Comments:52 (42 by maintainers)

github_iconTop GitHub Comments

9reactions
jrebackcommented, Dec 3, 2018

So, df = df.fillna(0) wouldn’t copy memory (assuming no type change), and if the user does want to modify a copy, they should do df2 = df.copy().fillna(0).

this is too complex. You either do it inplace or you don’t. The keyword controls it. If we remove the keyword then it should never modify the original.

7reactions
SamRWestcommented, Aug 24, 2020

@jreback I understand that there needs to be specific conditions for inplace to actually work. I’ve profiled my update() call, and it’s definitely halving memory compared to a standard join(), presumably because my dataframe’s dytpes are all floats. My point was that this (dataframe of a single dtype) is an extremely common case in data science work, which I believe is one of Pandas main use-cases. By removing explicit and/or inherent inplace calls, you’re removing my ability to do memory optimisation which halve my peak RAM use. When you’re working with 50Gb+ dataframes, this is a big deal.

@toobaz yep - there was some discussion above of whether the existing few inherently inplace operations should remain. I was giving an example where they are very useful to have, but also trying to make a case that other inplace operations are still extremely useful. For example, it seems crazy to me to remove an optimisation for, say fillna(), which halves the overall peak memory usage.

Now I don’t understand the complexity of keeping the inplace param and functions, but if you could keep them, and instead educate users about when they don’t work (using a warning message for mixed dtype dataframes, for example), I would find this far more useful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

In pandas, is inplace = True considered harmful, or not?
Yes, it is. Not just harmful. Quite harmful. This GitHub issue is proposing the inplace argument be deprecated api-wide sometime in the near...
Read more >
Deprecated API Migration Guide - Kubernetes
This page contains information you need to know when migrating from deprecated API versions to newer and more stable API versions. Removed APIs...
Read more >
Why You Should Probably Never Use pandas inplace=True
The parameter will likely eventually be deprecated (so you may as well get used to not using it already). In conclusion, inplace=True is...
Read more >
Deprecations by version - GitLab Docs
The support for registration tokens and certain runner configuration arguments in the POST method operation on the /api/v4/runners endpoint is deprecated.
Read more >
What's the future of the pandas library? - Data School
The pandas core team discourages the use of the inplace parameter, and eventually it will be deprecated (which means "scheduled for removal from ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found