Skip to content

DOC: Add clearer info when copy is False but memory shared only for certain objects #41514

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 10 commits into from
May 21, 2021
34 changes: 33 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class Series(base.IndexOpsMixin, generic.NDFrame):
name : str, optional
The name to give to the Series.
copy : bool, default False
Copy input data.
Copy input data. Only affects Series or 1d ndarray input. See examples.

Examples
--------
Expand Down Expand Up @@ -251,6 +251,38 @@ class Series(base.IndexOpsMixin, generic.NDFrame):
Note that the Index is first build with the keys from the dictionary.
After this the Series is reindexed with the given Index values, hence we
get all NaN as a result.

Constructing Series from a list with `copy=False`.

>>> r = [1, 2]
>>> ser = pd.Series(r, copy=False)
>>> ser.iloc[0] = 999
>>> r
[1, 2]
>>> ser
0 999
1 2
dtype: int64

Due to input data type the Series has a `copy` of
the original data even though `copy=False`, so
the data is unchanged.

Constructing Series from a 1d ndarray with `copy=False`.

>>> r = np.array([1, 2])
>>> ser = pd.Series(r, copy=False)
>>> ser.iloc[0] = 999
>>> r
array([999, 2])
>>> ser
0 999
1 2
dtype: int64

Due to input data type the Series has a `view` on
the original data, so
the data is changed as well.
"""

_typ = "series"
Expand Down