Skip to content

DOC: remove inplace usage from docstring examples #51124

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 6 commits into from
Feb 3, 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
7 changes: 0 additions & 7 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1673,13 +1673,6 @@ def sort_values(
[5, 2, 2, 1, 1]
Categories (3, int64): [1, 2, 5]

Inplace sorting can be done as well:

>>> c.sort_values(inplace=True)
>>> c
[1, 1, 2, 2, 5]
Categories (3, int64): [1, 2, 5]
>>>
>>> c = pd.Categorical([1, 2, 2, 1, 5])

'sort_values' behaviour with NaNs. Note that 'na_position'
Expand Down
26 changes: 0 additions & 26 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4512,17 +4512,6 @@ def eval(self, expr: str, *, inplace: bool = False, **kwargs) -> Any | None:
3 4 4
4 5 2

Use ``inplace=True`` to modify the original DataFrame.

>>> df.eval('C = A + B', inplace=True)
>>> df
A B C
0 1 10 11
1 2 8 10
2 3 6 9
3 4 4 8
4 5 2 7

Multiple columns can be assigned to using multi-line expressions:

>>> df.eval(
Expand Down Expand Up @@ -4998,14 +4987,6 @@ def align(
0 1 4
1 2 5
2 3 6

Now, update the labels without copying the underlying data.

>>> df.set_axis(['i', 'ii'], axis='columns', copy=False)
i ii
0 1 4
1 2 5
2 3 6
"""
)
@Substitution(
Expand Down Expand Up @@ -6372,13 +6353,6 @@ def dropna(
name toy born
1 Batman Batmobile 1940-04-25
2 Catwoman Bullwhip NaT

Keep the DataFrame with valid entries in the same variable.

>>> df.dropna(inplace=True)
>>> df
name toy born
1 Batman Batmobile 1940-04-25
"""
if (how is not no_default) and (thresh is not no_default):
raise TypeError(
Expand Down
11 changes: 0 additions & 11 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6216,17 +6216,6 @@ def astype(
dtype: category
Categories (2, int64): [2 < 1]

Note that using ``copy=False`` and changing data on a new
pandas object may propagate changes:

>>> s1 = pd.Series([1, 2])
>>> s2 = s1.astype('int64', copy=False)
>>> s2[0] = 10
>>> s1 # note that s1[0] has changed too
0 10
1 2
dtype: int64

Create a series of dates:

>>> ser_date = pd.Series(pd.date_range('20200101', periods=3))
Expand Down
8 changes: 1 addition & 7 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1745,13 +1745,7 @@ def set_names(
( 'cobra', 2018),
( 'cobra', 2019)],
)
>>> idx.set_names(['kind', 'year'], inplace=True)
>>> idx
MultiIndex([('python', 2018),
('python', 2019),
( 'cobra', 2018),
( 'cobra', 2019)],
names=['kind', 'year'])
>>> idx = idx.set_names(['kind', 'year'])
>>> idx.set_names('species', level=0)
MultiIndex([('python', 2018),
('python', 2019),
Expand Down
46 changes: 2 additions & 44 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1494,17 +1494,6 @@ def reset_index(
3 4
Name: foo, dtype: int64

To update the Series in place, without generating a new one
set `inplace` to True. Note that it also requires ``drop=True``.

>>> s.reset_index(inplace=True, drop=True)
>>> s
0 1
1 2
2 3
3 4
Name: foo, dtype: int64

The `level` parameter is interesting for Series with a multi-level
index.

Expand Down Expand Up @@ -2242,11 +2231,9 @@ def drop_duplicates(
Name: animal, dtype: object

The value ``False`` for parameter 'keep' discards all sets of
duplicated entries. Setting the value of 'inplace' to ``True`` performs
the operation inplace and returns ``None``.
duplicated entries.

>>> s.drop_duplicates(keep=False, inplace=True)
>>> s
>>> s.drop_duplicates(keep=False)
1 cow
3 beetle
5 hippo
Expand Down Expand Up @@ -3490,17 +3477,6 @@ def sort_values(
0 NaN
dtype: float64

Sort values inplace

>>> s.sort_values(ascending=False, inplace=True)
>>> s
3 10.0
4 5.0
2 3.0
1 1.0
0 NaN
dtype: float64

Sort values putting NAs first

>>> s.sort_values(na_position='first')
Expand Down Expand Up @@ -3750,16 +3726,6 @@ def sort_index(
1 c
dtype: object

Sort Inplace

>>> s.sort_index(inplace=True)
>>> s
1 c
2 b
3 a
4 d
dtype: object

By default NaNs are put at the end, but use `na_position` to place
them at the beginning

Expand Down Expand Up @@ -5619,14 +5585,6 @@ def dropna(
1 2.0
dtype: float64

Keep the Series with valid entries in the same variable.

>>> ser.dropna(inplace=True)
>>> ser
0 1.0
1 2.0
dtype: float64

Empty strings are not considered NA values. ``None`` is considered an
NA value.

Expand Down