Skip to content

Commit 5645847

Browse files
authored
DOC: remove inplace usage from docstring examples (#51124)
* DOC: remove inplace usage from docstring examples * Remove copy examples * Fix some warnings * Fix docstring * Revert "Fix some warnings" This reverts commit 201f877.
1 parent 9bf0670 commit 5645847

File tree

5 files changed

+3
-95
lines changed

5 files changed

+3
-95
lines changed

pandas/core/arrays/categorical.py

-7
Original file line numberDiff line numberDiff line change
@@ -1674,13 +1674,6 @@ def sort_values(
16741674
[5, 2, 2, 1, 1]
16751675
Categories (3, int64): [1, 2, 5]
16761676
1677-
Inplace sorting can be done as well:
1678-
1679-
>>> c.sort_values(inplace=True)
1680-
>>> c
1681-
[1, 1, 2, 2, 5]
1682-
Categories (3, int64): [1, 2, 5]
1683-
>>>
16841677
>>> c = pd.Categorical([1, 2, 2, 1, 5])
16851678
16861679
'sort_values' behaviour with NaNs. Note that 'na_position'

pandas/core/frame.py

-26
Original file line numberDiff line numberDiff line change
@@ -4512,17 +4512,6 @@ def eval(self, expr: str, *, inplace: bool = False, **kwargs) -> Any | None:
45124512
3 4 4
45134513
4 5 2
45144514
4515-
Use ``inplace=True`` to modify the original DataFrame.
4516-
4517-
>>> df.eval('C = A + B', inplace=True)
4518-
>>> df
4519-
A B C
4520-
0 1 10 11
4521-
1 2 8 10
4522-
2 3 6 9
4523-
3 4 4 8
4524-
4 5 2 7
4525-
45264515
Multiple columns can be assigned to using multi-line expressions:
45274516
45284517
>>> df.eval(
@@ -4998,14 +4987,6 @@ def align(
49984987
0 1 4
49994988
1 2 5
50004989
2 3 6
5001-
5002-
Now, update the labels without copying the underlying data.
5003-
5004-
>>> df.set_axis(['i', 'ii'], axis='columns', copy=False)
5005-
i ii
5006-
0 1 4
5007-
1 2 5
5008-
2 3 6
50094990
"""
50104991
)
50114992
@Substitution(
@@ -6372,13 +6353,6 @@ def dropna(
63726353
name toy born
63736354
1 Batman Batmobile 1940-04-25
63746355
2 Catwoman Bullwhip NaT
6375-
6376-
Keep the DataFrame with valid entries in the same variable.
6377-
6378-
>>> df.dropna(inplace=True)
6379-
>>> df
6380-
name toy born
6381-
1 Batman Batmobile 1940-04-25
63826356
"""
63836357
if (how is not no_default) and (thresh is not no_default):
63846358
raise TypeError(

pandas/core/generic.py

-11
Original file line numberDiff line numberDiff line change
@@ -6216,17 +6216,6 @@ def astype(
62166216
dtype: category
62176217
Categories (2, int64): [2 < 1]
62186218
6219-
Note that using ``copy=False`` and changing data on a new
6220-
pandas object may propagate changes:
6221-
6222-
>>> s1 = pd.Series([1, 2])
6223-
>>> s2 = s1.astype('int64', copy=False)
6224-
>>> s2[0] = 10
6225-
>>> s1 # note that s1[0] has changed too
6226-
0 10
6227-
1 2
6228-
dtype: int64
6229-
62306219
Create a series of dates:
62316220
62326221
>>> ser_date = pd.Series(pd.date_range('20200101', periods=3))

pandas/core/indexes/base.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -1733,13 +1733,7 @@ def set_names(
17331733
( 'cobra', 2018),
17341734
( 'cobra', 2019)],
17351735
)
1736-
>>> idx.set_names(['kind', 'year'], inplace=True)
1737-
>>> idx
1738-
MultiIndex([('python', 2018),
1739-
('python', 2019),
1740-
( 'cobra', 2018),
1741-
( 'cobra', 2019)],
1742-
names=['kind', 'year'])
1736+
>>> idx = idx.set_names(['kind', 'year'])
17431737
>>> idx.set_names('species', level=0)
17441738
MultiIndex([('python', 2018),
17451739
('python', 2019),

pandas/core/series.py

+2-44
Original file line numberDiff line numberDiff line change
@@ -1494,17 +1494,6 @@ def reset_index(
14941494
3 4
14951495
Name: foo, dtype: int64
14961496
1497-
To update the Series in place, without generating a new one
1498-
set `inplace` to True. Note that it also requires ``drop=True``.
1499-
1500-
>>> s.reset_index(inplace=True, drop=True)
1501-
>>> s
1502-
0 1
1503-
1 2
1504-
2 3
1505-
3 4
1506-
Name: foo, dtype: int64
1507-
15081497
The `level` parameter is interesting for Series with a multi-level
15091498
index.
15101499
@@ -2242,11 +2231,9 @@ def drop_duplicates(
22422231
Name: animal, dtype: object
22432232
22442233
The value ``False`` for parameter 'keep' discards all sets of
2245-
duplicated entries. Setting the value of 'inplace' to ``True`` performs
2246-
the operation inplace and returns ``None``.
2234+
duplicated entries.
22472235
2248-
>>> s.drop_duplicates(keep=False, inplace=True)
2249-
>>> s
2236+
>>> s.drop_duplicates(keep=False)
22502237
1 cow
22512238
3 beetle
22522239
5 hippo
@@ -3490,17 +3477,6 @@ def sort_values(
34903477
0 NaN
34913478
dtype: float64
34923479
3493-
Sort values inplace
3494-
3495-
>>> s.sort_values(ascending=False, inplace=True)
3496-
>>> s
3497-
3 10.0
3498-
4 5.0
3499-
2 3.0
3500-
1 1.0
3501-
0 NaN
3502-
dtype: float64
3503-
35043480
Sort values putting NAs first
35053481
35063482
>>> s.sort_values(na_position='first')
@@ -3750,16 +3726,6 @@ def sort_index(
37503726
1 c
37513727
dtype: object
37523728
3753-
Sort Inplace
3754-
3755-
>>> s.sort_index(inplace=True)
3756-
>>> s
3757-
1 c
3758-
2 b
3759-
3 a
3760-
4 d
3761-
dtype: object
3762-
37633729
By default NaNs are put at the end, but use `na_position` to place
37643730
them at the beginning
37653731
@@ -5619,14 +5585,6 @@ def dropna(
56195585
1 2.0
56205586
dtype: float64
56215587
5622-
Keep the Series with valid entries in the same variable.
5623-
5624-
>>> ser.dropna(inplace=True)
5625-
>>> ser
5626-
0 1.0
5627-
1 2.0
5628-
dtype: float64
5629-
56305588
Empty strings are not considered NA values. ``None`` is considered an
56315589
NA value.
56325590

0 commit comments

Comments
 (0)