Skip to content

Commit 785691e

Browse files
authored
DOC: Remove inplace from user guide (#51011)
* DOC: Remove inplace from user guide * Fix * Remove from getting started as well * Remove note
1 parent dbed131 commit 785691e

File tree

8 files changed

+14
-63
lines changed

8 files changed

+14
-63
lines changed

doc/source/getting_started/comparison/includes/copies.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,3 @@ or overwrite the original one:
1111
.. code-block:: python
1212
1313
df = df.sort_values("col1")
14-
15-
.. note::
16-
17-
You will see an ``inplace=True`` keyword argument available for some methods:
18-
19-
.. code-block:: python
20-
21-
df.sort_values("col1", inplace=True)
22-
23-
Its use is discouraged. :ref:`More information. <indexing.view_versus_copy>`

doc/source/user_guide/advanced.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ are named.
609609

610610
.. ipython:: python
611611
612-
s.index.set_names(["L1", "L2"], inplace=True)
612+
s.index = s.index.set_names(["L1", "L2"])
613613
s.sort_index(level="L1")
614614
s.sort_index(level="L2")
615615

doc/source/user_guide/basics.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,11 +1479,6 @@ you specify a single ``mapper`` and the ``axis`` to apply that mapping to.
14791479
df.rename({"one": "foo", "two": "bar"}, axis="columns")
14801480
df.rename({"a": "apple", "b": "banana", "d": "durian"}, axis="index")
14811481
1482-
1483-
The :meth:`~DataFrame.rename` method also provides an ``inplace`` named
1484-
parameter that is by default ``False`` and copies the underlying data. Pass
1485-
``inplace=True`` to rename the data in place.
1486-
14871482
Finally, :meth:`~Series.rename` also accepts a scalar or list-like
14881483
for altering the ``Series.name`` attribute.
14891484

doc/source/user_guide/categorical.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,9 @@ meaning and certain operations are possible. If the categorical is unordered, ``
437437
.. ipython:: python
438438
439439
s = pd.Series(pd.Categorical(["a", "b", "c", "a"], ordered=False))
440-
s.sort_values(inplace=True)
440+
s = s.sort_values()
441441
s = pd.Series(["a", "b", "c", "a"]).astype(CategoricalDtype(ordered=True))
442-
s.sort_values(inplace=True)
442+
s = s.sort_values()
443443
s
444444
s.min(), s.max()
445445
@@ -459,7 +459,7 @@ This is even true for strings and numeric data:
459459
s = pd.Series([1, 2, 3, 1], dtype="category")
460460
s = s.cat.set_categories([2, 3, 1], ordered=True)
461461
s
462-
s.sort_values(inplace=True)
462+
s = s.sort_values()
463463
s
464464
s.min(), s.max()
465465
@@ -477,7 +477,7 @@ necessarily make the sort order the same as the categories order.
477477
s = pd.Series([1, 2, 3, 1], dtype="category")
478478
s = s.cat.reorder_categories([2, 3, 1], ordered=True)
479479
s
480-
s.sort_values(inplace=True)
480+
s = s.sort_values()
481481
s
482482
s.min(), s.max()
483483

doc/source/user_guide/enhancingperf.rst

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -647,24 +647,21 @@ This allows for *formulaic evaluation*. The assignment target can be a
647647
new column name or an existing column name, and it must be a valid Python
648648
identifier.
649649

650-
The ``inplace`` keyword determines whether this assignment will performed
651-
on the original :class:`DataFrame` or return a copy with the new column.
652-
653650
.. ipython:: python
654651
655652
df = pd.DataFrame(dict(a=range(5), b=range(5, 10)))
656-
df.eval("c = a + b", inplace=True)
657-
df.eval("d = a + b + c", inplace=True)
658-
df.eval("a = 1", inplace=True)
653+
df = df.eval("c = a + b")
654+
df = df.eval("d = a + b + c")
655+
df = df.eval("a = 1")
659656
df
660657
661-
When ``inplace`` is set to ``False``, the default, a copy of the :class:`DataFrame` with the
658+
A copy of the :class:`DataFrame` with the
662659
new or modified columns is returned and the original frame is unchanged.
663660

664661
.. ipython:: python
665662
666663
df
667-
df.eval("e = a - c", inplace=False)
664+
df.eval("e = a - c")
668665
df
669666
670667
As a convenience, multiple assignments can be performed by using a
@@ -677,7 +674,6 @@ multi-line string.
677674
c = a + b
678675
d = a + b + c
679676
a = 1""",
680-
inplace=False,
681677
)
682678
683679
The equivalent in standard Python would be

doc/source/user_guide/groupby.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,7 @@ as the one being grouped. The transform function must:
769769
the first group chunk using chunk.apply.
770770
* Not perform in-place operations on the group chunk. Group chunks should
771771
be treated as immutable, and changes to a group chunk may produce unexpected
772-
results. For example, when using ``fillna``, ``inplace`` must be ``False``
773-
(``grouped.transform(lambda x: x.fillna(inplace=False))``).
772+
results.
774773
* (Optionally) operates on the entire group chunk. If this is supported, a
775774
fast path is used starting from the *second* chunk.
776775

doc/source/user_guide/indexing.rst

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,15 +1074,7 @@ This can be done intuitively like so:
10741074
df2[df2 < 0] = 0
10751075
df2
10761076
1077-
By default, ``where`` returns a modified copy of the data. There is an
1078-
optional parameter ``inplace`` so that the original data can be modified
1079-
without creating a copy:
1080-
1081-
.. ipython:: python
1082-
1083-
df_orig = df.copy()
1084-
df_orig.where(df > 0, -df, inplace=True)
1085-
df_orig
1077+
``where`` returns a modified copy of the data.
10861078

10871079
.. note::
10881080

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

1242-
1243-
The :class:`DataFrame.query` method has a ``inplace`` keyword which determines
1244-
whether the query modifies the original frame.
1245-
1246-
.. ipython:: python
1247-
1248-
df = pd.DataFrame(dict(a=range(5), b=range(5, 10)))
1249-
df.query("a > 2")
1250-
df.query("a > 2", inplace=True)
1251-
df
1252-
1253-
12541234
:class:`~pandas.MultiIndex` :meth:`~pandas.DataFrame.query` Syntax
12551235
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12561236

@@ -1635,7 +1615,7 @@ See :ref:`Advanced Indexing <advanced>` for usage of MultiIndexes.
16351615
ind = pd.Index([1, 2, 3])
16361616
ind.rename("apple")
16371617
ind
1638-
ind.set_names(["apple"], inplace=True)
1618+
ind = ind.set_names(["apple"])
16391619
ind.name = "bob"
16401620
ind
16411621
@@ -1755,14 +1735,11 @@ the given columns to a MultiIndex:
17551735
frame = frame.set_index(['a', 'b'], append=True)
17561736
frame
17571737
1758-
Other options in ``set_index`` allow you not drop the index columns or to add
1759-
the index in-place (without creating a new object):
1738+
Other options in ``set_index`` allow you not drop the index columns.
17601739

17611740
.. ipython:: python
17621741
17631742
data.set_index('c', drop=False)
1764-
data.set_index(['a', 'b'], inplace=True)
1765-
data
17661743
17671744
Reset the index
17681745
~~~~~~~~~~~~~~~

doc/source/user_guide/missing_data.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -685,12 +685,6 @@ Replacing more than one value is possible by passing a list.
685685
df.replace([1.5, df00], [np.nan, "a"])
686686
df[1].dtype
687687
688-
You can also operate on the DataFrame in place:
689-
690-
.. ipython:: python
691-
692-
df.replace(1.5, np.nan, inplace=True)
693-
694688
Missing data casting rules and indexing
695689
---------------------------------------
696690

0 commit comments

Comments
 (0)