Skip to content

DOC: Add comment about inplace/copy proposal #51487

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

Merged
merged 4 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions doc/source/getting_started/comparison/includes/copies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,18 @@ or overwrite the original one:
.. code-block:: python

df = df.sort_values("col1")

.. note::

You will see an ``inplace=True`` or ``copy=False`` keyword argument available for
some methods:

.. code-block:: python

df.replace(5, inplace=True)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think replace is a good example. We are keeping inplace there.

Copy link
Member Author

Choose a reason for hiding this comment

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

That’s why I am using it. I could add an explicit comment that replace is one of the few methods where we are keeping it

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a small note that replace might keep inplace

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, it might be good to also give an example of something that would lose inplace, for comparison's sake.

Copy link
Member Author

Choose a reason for hiding this comment

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

What would you want to show with it? I am struggling to come up with an explanation for such an example

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we would need to go to in detail, just say e.g.

"Some methods cannot operate inplace (e.g. reindex), or would already avoid copying the data with Copy on Write. (e.g. rename)

It is recommended that the inplace/copy parameters be avoided for those methods".

No big deal if we don't add this, though, since people can always read the PDEP.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah got you, I thought you wanted to add a code example.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll leave the suggestion to not use them out. When used in the appropriate context it can speed up your code. I think it's clear enough that users can figure the consequences out for themself.


There is an active discussion about deprecating and removing ``inplace`` and ``copy`` for
most methods (e.g. ``dropna``) except for a very small subset of methods
(including ``replace``). Both keywords won't be
necessary anymore in the context of Copy-on-Write. The proposal can be found
[here](https://github.com/pandas-dev/pandas/pull/51466).
9 changes: 9 additions & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,14 @@ Other API changes
- Added :func:`pandas.api.types.is_any_real_numeric_dtype` to check for real numeric dtypes (:issue:`51152`)
-

.. note::

A current PDEP proposes the deprecation and removal of the keywords ``inplace`` and ``copy``
for all but a small subset of methods from the pandas API. The current discussion takes place
at [here](https://github.com/pandas-dev/pandas/pull/51466). The keywords won't be necessary
anymore in the context of Copy-on-Write. If this proposal is accepted, both
keywords would be deprecated in the next release of pandas and removed in pandas 3.0.

.. ---------------------------------------------------------------------------
.. _whatsnew_200.deprecations:

Expand Down Expand Up @@ -1423,6 +1431,7 @@ Metadata

Other
^^^^^

- Bug in :meth:`Series.searchsorted` inconsistent behavior when accepting :class:`DataFrame` as parameter ``value`` (:issue:`49620`)
- Bug in :func:`array` failing to raise on :class:`DataFrame` inputs (:issue:`51167`)
-
Expand Down