From c25f3af839325f6c787ce64fa29b7b6bfbf518ec Mon Sep 17 00:00:00 2001 From: minat-hub Date: Mon, 24 Oct 2022 15:32:59 +0100 Subject: [PATCH 1/4] issue #48674 index constructor updates to the frame.py file --- .gitignore | 1 + pandas/core/frame.py | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 07b1f056d511b..3c2eb0bc56cfe 100644 --- a/.gitignore +++ b/.gitignore @@ -121,6 +121,7 @@ doc/build/html/index.html # Windows specific leftover: doc/tmp.sv env/ +pandas-env doc/source/savefig/ # Interactive terminal generated files # diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 592b0f0ba62b8..91ae433fd6e70 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -490,7 +490,8 @@ class DataFrame(NDFrame, OpsMixin): data : ndarray (structured or homogeneous), Iterable, dict, or DataFrame Dict can contain Series, arrays, constants, dataclass or list-like objects. If data is a dict, column order follows insertion-order. If a dict contains Series - which have an index defined, it is aligned by its index. + which have an index defined, it is aligned by its index. This alignment also occurs + if data is a Series or a DataFrame itself. Alignment is done on Series/DataFrame inputs. .. versionchanged:: 0.25.0 If data is a list of dicts, column order follows insertion-order. @@ -592,6 +593,25 @@ class DataFrame(NDFrame, OpsMixin): 0 0 0 1 0 3 2 2 3 + + Constructing DataFrame from Series/DataFrame: + + >>> ser = pd.Series([1, 2, 3], index=["a", "b", "c"]) + >>> df = pd.DataFrame(data=ser, index=["a", "c"]) + >>> print(df) + + 0 + a 1 + c 3 + + >>> df1 = pd.DataFrame([1, 2, 3], index=["a", "b", "c"], columns=["x"]) + >>> df2 = pd.DataFrame(data=df1, index=["a", "c"]) + >>> print(df2) + + x + a 1 + c 3 + """ _internal_names_set = {"columns", "index"} | NDFrame._internal_names_set From 97addf39cd494e0ea5c847bbae2903935ba253f2 Mon Sep 17 00:00:00 2001 From: minat-hub Date: Tue, 25 Oct 2022 16:28:11 +0100 Subject: [PATCH 2/4] remove pandas-env in gitignore file and print from frame.py --- .gitignore | 1 - pandas/core/frame.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 3c2eb0bc56cfe..07b1f056d511b 100644 --- a/.gitignore +++ b/.gitignore @@ -121,7 +121,6 @@ doc/build/html/index.html # Windows specific leftover: doc/tmp.sv env/ -pandas-env doc/source/savefig/ # Interactive terminal generated files # diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 91ae433fd6e70..1ccee5b6cfda7 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -598,7 +598,7 @@ class DataFrame(NDFrame, OpsMixin): >>> ser = pd.Series([1, 2, 3], index=["a", "b", "c"]) >>> df = pd.DataFrame(data=ser, index=["a", "c"]) - >>> print(df) + >>> df 0 a 1 @@ -606,7 +606,7 @@ class DataFrame(NDFrame, OpsMixin): >>> df1 = pd.DataFrame([1, 2, 3], index=["a", "b", "c"], columns=["x"]) >>> df2 = pd.DataFrame(data=df1, index=["a", "c"]) - >>> print(df2) + >>> df2 x a 1 From ac03affa50cc82679b1b0fe46de766b682066f44 Mon Sep 17 00:00:00 2001 From: minat-hub Date: Wed, 26 Oct 2022 00:59:10 +0100 Subject: [PATCH 3/4] remove blank line before closing docstring --- pandas/core/frame.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 9a4193e1a0680..2e3e2f432fd32 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -599,7 +599,6 @@ class DataFrame(NDFrame, OpsMixin): >>> ser = pd.Series([1, 2, 3], index=["a", "b", "c"]) >>> df = pd.DataFrame(data=ser, index=["a", "c"]) >>> df - 0 a 1 c 3 @@ -607,11 +606,9 @@ class DataFrame(NDFrame, OpsMixin): >>> df1 = pd.DataFrame([1, 2, 3], index=["a", "b", "c"], columns=["x"]) >>> df2 = pd.DataFrame(data=df1, index=["a", "c"]) >>> df2 - x a 1 c 3 - """ _internal_names_set = {"columns", "index"} | NDFrame._internal_names_set From f15469887b34006d03ed826898034a1570a324b0 Mon Sep 17 00:00:00 2001 From: minat-hub Date: Wed, 26 Oct 2022 13:44:51 +0100 Subject: [PATCH 4/4] reduce character count in changes made --- pandas/core/frame.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 2e3e2f432fd32..eef86ce7294a7 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -490,8 +490,9 @@ class DataFrame(NDFrame, OpsMixin): data : ndarray (structured or homogeneous), Iterable, dict, or DataFrame Dict can contain Series, arrays, constants, dataclass or list-like objects. If data is a dict, column order follows insertion-order. If a dict contains Series - which have an index defined, it is aligned by its index. This alignment also occurs - if data is a Series or a DataFrame itself. Alignment is done on Series/DataFrame inputs. + which have an index defined, it is aligned by its index. This alignment also + occurs if data is a Series or a DataFrame itself. Alignment is done on + Series/DataFrame inputs. .. versionchanged:: 0.25.0 If data is a list of dicts, column order follows insertion-order.