Skip to content

DOC: Remove inplace from user guide #51011

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 2, 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
10 changes: 0 additions & 10 deletions doc/source/getting_started/comparison/includes/copies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,3 @@ or overwrite the original one:
.. code-block:: python

df = df.sort_values("col1")

.. note::

You will see an ``inplace=True`` keyword argument available for some methods:
Copy link
Member

Choose a reason for hiding this comment

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

Should be fine to keep this one since we're discouraging inplace usage here?

Copy link
Member Author

Choose a reason for hiding this comment

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

But with the wrong arguments, I'd rather add it again after finishing the pdep


.. code-block:: python

df.sort_values("col1", inplace=True)

Its use is discouraged. :ref:`More information. <indexing.view_versus_copy>`
2 changes: 1 addition & 1 deletion doc/source/user_guide/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ are named.

.. ipython:: python

s.index.set_names(["L1", "L2"], inplace=True)
s.index = s.index.set_names(["L1", "L2"])
s.sort_index(level="L1")
s.sort_index(level="L2")

Expand Down
5 changes: 0 additions & 5 deletions doc/source/user_guide/basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1479,11 +1479,6 @@ you specify a single ``mapper`` and the ``axis`` to apply that mapping to.
df.rename({"one": "foo", "two": "bar"}, axis="columns")
df.rename({"a": "apple", "b": "banana", "d": "durian"}, axis="index")


The :meth:`~DataFrame.rename` method also provides an ``inplace`` named
parameter that is by default ``False`` and copies the underlying data. Pass
``inplace=True`` to rename the data in place.

Finally, :meth:`~Series.rename` also accepts a scalar or list-like
for altering the ``Series.name`` attribute.

Expand Down
8 changes: 4 additions & 4 deletions doc/source/user_guide/categorical.rst
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,9 @@ meaning and certain operations are possible. If the categorical is unordered, ``
.. ipython:: python

s = pd.Series(pd.Categorical(["a", "b", "c", "a"], ordered=False))
s.sort_values(inplace=True)
s = s.sort_values()
s = pd.Series(["a", "b", "c", "a"]).astype(CategoricalDtype(ordered=True))
s.sort_values(inplace=True)
s = s.sort_values()
s
s.min(), s.max()

Expand All @@ -459,7 +459,7 @@ This is even true for strings and numeric data:
s = pd.Series([1, 2, 3, 1], dtype="category")
s = s.cat.set_categories([2, 3, 1], ordered=True)
s
s.sort_values(inplace=True)
s = s.sort_values()
s
s.min(), s.max()

Expand All @@ -477,7 +477,7 @@ necessarily make the sort order the same as the categories order.
s = pd.Series([1, 2, 3, 1], dtype="category")
s = s.cat.reorder_categories([2, 3, 1], ordered=True)
s
s.sort_values(inplace=True)
s = s.sort_values()
s
s.min(), s.max()

Expand Down
14 changes: 5 additions & 9 deletions doc/source/user_guide/enhancingperf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -647,24 +647,21 @@ This allows for *formulaic evaluation*. The assignment target can be a
new column name or an existing column name, and it must be a valid Python
identifier.

The ``inplace`` keyword determines whether this assignment will performed
on the original :class:`DataFrame` or return a copy with the new column.

.. ipython:: python

df = pd.DataFrame(dict(a=range(5), b=range(5, 10)))
df.eval("c = a + b", inplace=True)
df.eval("d = a + b + c", inplace=True)
df.eval("a = 1", inplace=True)
df = df.eval("c = a + b")
df = df.eval("d = a + b + c")
df = df.eval("a = 1")
df

When ``inplace`` is set to ``False``, the default, a copy of the :class:`DataFrame` with the
A copy of the :class:`DataFrame` with the
new or modified columns is returned and the original frame is unchanged.

.. ipython:: python

df
df.eval("e = a - c", inplace=False)
df.eval("e = a - c")
df

As a convenience, multiple assignments can be performed by using a
Expand All @@ -677,7 +674,6 @@ multi-line string.
c = a + b
d = a + b + c
a = 1""",
inplace=False,
)

The equivalent in standard Python would be
Expand Down
3 changes: 1 addition & 2 deletions doc/source/user_guide/groupby.rst
Original file line number Diff line number Diff line change
Expand Up @@ -769,8 +769,7 @@ as the one being grouped. The transform function must:
the first group chunk using chunk.apply.
* Not perform in-place operations on the group chunk. Group chunks should
be treated as immutable, and changes to a group chunk may produce unexpected
results. For example, when using ``fillna``, ``inplace`` must be ``False``
(``grouped.transform(lambda x: x.fillna(inplace=False))``).
results.
* (Optionally) operates on the entire group chunk. If this is supported, a
fast path is used starting from the *second* chunk.

Expand Down
29 changes: 3 additions & 26 deletions doc/source/user_guide/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1074,15 +1074,7 @@ This can be done intuitively like so:
df2[df2 < 0] = 0
df2

By default, ``where`` returns a modified copy of the data. There is an
optional parameter ``inplace`` so that the original data can be modified
without creating a copy:

.. ipython:: python

df_orig = df.copy()
df_orig.where(df > 0, -df, inplace=True)
df_orig
``where`` returns a modified copy of the data.

.. note::

Expand Down Expand Up @@ -1239,18 +1231,6 @@ If instead you don't want to or cannot name your index, you can use the name
the index as ``ilevel_0`` as well, but at this point you should consider
renaming your columns to something less ambiguous.


The :class:`DataFrame.query` method has a ``inplace`` keyword which determines
whether the query modifies the original frame.

.. ipython:: python

df = pd.DataFrame(dict(a=range(5), b=range(5, 10)))
df.query("a > 2")
df.query("a > 2", inplace=True)
df


:class:`~pandas.MultiIndex` :meth:`~pandas.DataFrame.query` Syntax
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -1616,7 +1596,7 @@ See :ref:`Advanced Indexing <advanced>` for usage of MultiIndexes.
ind = pd.Index([1, 2, 3])
ind.rename("apple")
ind
ind.set_names(["apple"], inplace=True)
ind = ind.set_names(["apple"])
ind.name = "bob"
ind

Expand Down Expand Up @@ -1736,14 +1716,11 @@ the given columns to a MultiIndex:
frame = frame.set_index(['a', 'b'], append=True)
frame

Other options in ``set_index`` allow you not drop the index columns or to add
the index in-place (without creating a new object):
Other options in ``set_index`` allow you not drop the index columns.

.. ipython:: python

data.set_index('c', drop=False)
data.set_index(['a', 'b'], inplace=True)
data

Reset the index
~~~~~~~~~~~~~~~
Expand Down
6 changes: 0 additions & 6 deletions doc/source/user_guide/missing_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -685,12 +685,6 @@ Replacing more than one value is possible by passing a list.
df.replace([1.5, df00], [np.nan, "a"])
df[1].dtype

You can also operate on the DataFrame in place:

.. ipython:: python

df.replace(1.5, np.nan, inplace=True)

Missing data casting rules and indexing
---------------------------------------

Expand Down