Skip to content

Commit 3980696

Browse files
authored
DOC: Add clearer info when copy is False but memory shared only for certain objects (#41514)
1 parent 3fec908 commit 3980696

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

pandas/core/series.py

+33-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class Series(base.IndexOpsMixin, generic.NDFrame):
224224
name : str, optional
225225
The name to give to the Series.
226226
copy : bool, default False
227-
Copy input data.
227+
Copy input data. Only affects Series or 1d ndarray input. See examples.
228228
229229
Examples
230230
--------
@@ -252,6 +252,38 @@ class Series(base.IndexOpsMixin, generic.NDFrame):
252252
Note that the Index is first build with the keys from the dictionary.
253253
After this the Series is reindexed with the given Index values, hence we
254254
get all NaN as a result.
255+
256+
Constructing Series from a list with `copy=False`.
257+
258+
>>> r = [1, 2]
259+
>>> ser = pd.Series(r, copy=False)
260+
>>> ser.iloc[0] = 999
261+
>>> r
262+
[1, 2]
263+
>>> ser
264+
0 999
265+
1 2
266+
dtype: int64
267+
268+
Due to input data type the Series has a `copy` of
269+
the original data even though `copy=False`, so
270+
the data is unchanged.
271+
272+
Constructing Series from a 1d ndarray with `copy=False`.
273+
274+
>>> r = np.array([1, 2])
275+
>>> ser = pd.Series(r, copy=False)
276+
>>> ser.iloc[0] = 999
277+
>>> r
278+
array([999, 2])
279+
>>> ser
280+
0 999
281+
1 2
282+
dtype: int64
283+
284+
Due to input data type the Series has a `view` on
285+
the original data, so
286+
the data is changed as well.
255287
"""
256288

257289
_typ = "series"

0 commit comments

Comments
 (0)