From f9efd2aad409c471195f27bc2e8e9213687afef9 Mon Sep 17 00:00:00 2001 From: Michael Hsieh Date: Fri, 14 May 2021 15:46:49 -0700 Subject: [PATCH 1/9] DOC: Add info on memory location sharing when copy=False (#41423). Update is on main Series documentation. --- pandas/core/series.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index c8e9898f9462a..bfaabc51f0eef 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -223,7 +223,9 @@ 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. If False and the Series returns a `view` of the data, + the memory location for the values is shared. If False and the Series returns a `copy` + of the data, the memory location for the values is not shared. Examples -------- From 0c70b9f843489432a7f84b4410b3a85d17c3b953 Mon Sep 17 00:00:00 2001 From: Michael Hsieh Date: Sun, 16 May 2021 15:29:52 -0700 Subject: [PATCH 2/9] DOC: Add 2 examples when creating Series and copy is False (#41423). Original data unchanged when Series is a Copy, but original data is changed when Series is a View. --- pandas/core/series.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index bfaabc51f0eef..d2d4fdcc41023 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -223,9 +223,10 @@ class Series(base.IndexOpsMixin, generic.NDFrame): name : str, optional The name to give to the Series. copy : bool, default False - Copy input data. If False and the Series returns a `view` of the data, - the memory location for the values is shared. If False and the Series returns a `copy` + Copy input data. If False and the Series returns a `copy` of the data, the memory location for the values is not shared. + If False and the Series returns a `view` on the data, + the memory location for the values is shared. Examples -------- @@ -253,6 +254,34 @@ 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 an array 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 + + The Series returns a `copy` of the original data, so + `r` is unchanged. + + Constructing Series from a `numpy.array` 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: int32 + + The Series returns a `view` on the original data, so + `r` is changed as well. """ _typ = "series" From 2ed2b8dbdec90cb0f8060a9423e49f7078db3ed9 Mon Sep 17 00:00:00 2001 From: Michael Hsieh Date: Sun, 16 May 2021 15:56:37 -0700 Subject: [PATCH 3/9] DOC: Fix code format of 2 examples added to Series section (#41423). After building documentation, found the code examples were not displayed correctly. Added newlines and rebuilt to fix. --- pandas/core/series.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index d2d4fdcc41023..ea36383deb1c8 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -256,6 +256,7 @@ class Series(base.IndexOpsMixin, generic.NDFrame): get all NaN as a result. Constructing Series from an array with `copy=False`. + >>> r = [1,2] >>> ser = pd.Series(r, copy=False) >>> ser.iloc[0] = 999 @@ -267,9 +268,10 @@ class Series(base.IndexOpsMixin, generic.NDFrame): dtype: int64 The Series returns a `copy` of the original data, so - `r` is unchanged. + the original data is unchanged. Constructing Series from a `numpy.array` with `copy=False`. + >>> r = np.array([1,2]) >>> ser = pd.Series(r, copy=False) >>> ser.iloc[0] = 999 @@ -281,7 +283,7 @@ class Series(base.IndexOpsMixin, generic.NDFrame): dtype: int32 The Series returns a `view` on the original data, so - `r` is changed as well. + the original data is changed as well. """ _typ = "series" From 1a564494371c9e2b7e5138c6efa1ffd52cc44eae Mon Sep 17 00:00:00 2001 From: Michael Hsieh Date: Mon, 17 May 2021 23:19:48 -0700 Subject: [PATCH 4/9] DOC: Fix spacing and reword parameter info and examples (#41423). Remove return, replace with has. Remove array, replace with list. Fix array spacing to match other Series examples. Replace long param info with only affects sentence, based off DataFrame documentation. Reword example explanation. Change numpy.array to 1d ndarray to match other documentation, like DataFrame. --- pandas/core/series.py | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index ea36383deb1c8..ad3f969125bad 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -223,10 +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. If False and the Series returns a `copy` - of the data, the memory location for the values is not shared. - If False and the Series returns a `view` on the data, - the memory location for the values is shared. + Copy input data. Only affects Series or 1d ndarray input. See examples. Examples -------- @@ -255,9 +252,9 @@ class Series(base.IndexOpsMixin, generic.NDFrame): After this the Series is reindexed with the given Index values, hence we get all NaN as a result. - Constructing Series from an array with `copy=False`. - - >>> r = [1,2] + Constructing Series from a list with `copy=False`. + + >>> r = [1, 2] >>> ser = pd.Series(r, copy=False) >>> ser.iloc[0] = 999 >>> r @@ -266,13 +263,13 @@ class Series(base.IndexOpsMixin, generic.NDFrame): 0 999 1 2 dtype: int64 - - The Series returns a `copy` of the original data, so - the original data is unchanged. - - Constructing Series from a `numpy.array` with `copy=False`. - - >>> r = np.array([1,2]) + + 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 @@ -281,9 +278,9 @@ class Series(base.IndexOpsMixin, generic.NDFrame): 0 999 1 2 dtype: int32 - - The Series returns a `view` on the original data, so - the original data is changed as well. + + Due to input data type the Series has a `view` on the original data, so + the data is changed as well. """ _typ = "series" From ac82b6bd22ff391c4f1b505495a2df33c013b616 Mon Sep 17 00:00:00 2001 From: Michael Hsieh Date: Mon, 17 May 2021 23:43:32 -0700 Subject: [PATCH 5/9] DOC: Try fix PEP8 spacing issue. --- pandas/core/series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index ad3f969125bad..3b7530eecaf1f 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -251,7 +251,7 @@ 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] From 0e147a15e8b8234dbb6122777b3ce8ce6a8ea26d Mon Sep 17 00:00:00 2001 From: Michael Hsieh Date: Tue, 18 May 2021 00:45:25 -0700 Subject: [PATCH 6/9] DOC: Try fix one line which is too long. --- pandas/core/series.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 01c33497c4a8a..0b942136e1248 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -264,8 +264,8 @@ class Series(base.IndexOpsMixin, generic.NDFrame): 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. + 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`. From dfd10c8a99f3e2c14ce167557de6cebeaed9130c Mon Sep 17 00:00:00 2001 From: Michael Hsieh Date: Tue, 18 May 2021 10:52:26 -0700 Subject: [PATCH 7/9] Revert "Merge remote-tracking branch 'upstream/master' into 41423-doc-series-copy" This reverts commit 5eab8f9967d632d7d2500a3cf1b82d3cc3fbce4e, reversing changes made to 671cf86a78e931a9c98ad72571ec65cd3c35d8a7. Need to revert merge commit to find out why build is failing after pushing branches. These were the commands run to do the revert, at previous commit: check parent branches of the merge commit git cat-file -p 5eab8f9967d632d7d2500a3cf1b82d3cc3fbce4e then revert commit git revert --no-commit -m 2 5eab8f9967d632d7d2500a3cf1b82d3cc3fbce4e Then accepted incoming change in series.py, which removed my info and examples added. --- pandas/core/series.py | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 0b942136e1248..d0ff50cca5355 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -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. Only affects Series or 1d ndarray input. See examples. + Copy input data. Examples -------- @@ -251,36 +251,6 @@ 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: int32 - - Due to input data type the Series has a `view` on the original data, so - the data is changed as well. """ _typ = "series" From 52ce3ba7b7e62e73820711854a5a33a798733330 Mon Sep 17 00:00:00 2001 From: Michael Hsieh Date: Tue, 18 May 2021 13:58:13 -0700 Subject: [PATCH 8/9] DOC: Add reworded parameter info and and 2 examples again (#41423). Remove whitespace on blank lines and line break sentences to avoid style errors. Previous commit had 1 failing check. --- pandas/core/series.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index d0ff50cca5355..e38f93b2396ea 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -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 -------- @@ -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: int32 + + Due to input data type the Series has a `view` on + the original data, so + the data is changed as well. """ _typ = "series" From 818d5d694c237c433e4e83768e7bba7b4361336f Mon Sep 17 00:00:00 2001 From: Michael Hsieh Date: Wed, 19 May 2021 17:37:59 -0700 Subject: [PATCH 9/9] DOC: Change type output from int32 to int64 in ndarray data Series code example. --- pandas/core/series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index e38f93b2396ea..530750f8bd27f 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -278,7 +278,7 @@ class Series(base.IndexOpsMixin, generic.NDFrame): >>> ser 0 999 1 2 - dtype: int32 + dtype: int64 Due to input data type the Series has a `view` on the original data, so