From a57a02c2e49b86e03b0c2102e06de00cf002d67c Mon Sep 17 00:00:00 2001 From: tyuyoshi Date: Tue, 10 Aug 2021 08:04:23 +0900 Subject: [PATCH 1/7] BUG: erroneous initialization of a DataFrame with Series objects #42818 --- pandas/core/frame.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 823de2133f0b3..d0abd497f77d2 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -463,7 +463,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. + data is a dict, column order follows insertion-order. If dict contain Series + which has an index defined, it is aligned by its index. .. versionchanged:: 0.25.0 If data is a list of dicts, column order follows insertion-order. @@ -518,11 +519,22 @@ class DataFrame(NDFrame, OpsMixin): col2 int8 dtype: object + Constructing DataFrame from a dictionary including Series. + + >>> d = {'col1': [1, 2, 3, 4], 'col2': pd.Series([3, 4], index=[3, 4])} + >>> df2 = pd.DataFrame(data=d, index=[1, 2, 3, 4]) + >>> df2 + col1 col2 + 1 1 NaN + 2 2 NaN + 3 3 3 + 4 4 4 + Constructing DataFrame from numpy ndarray: - >>> df2 = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), + >>> df3 = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), ... columns=['a', 'b', 'c']) - >>> df2 + >>> df3 a b c 0 1 2 3 1 4 5 6 @@ -532,9 +544,9 @@ class DataFrame(NDFrame, OpsMixin): >>> data = np.array([(1, 2, 3), (4, 5, 6), (7, 8, 9)], ... dtype=[("a", "i4"), ("b", "i4"), ("c", "i4")]) - >>> df3 = pd.DataFrame(data, columns=['c', 'a']) + >>> df4 = pd.DataFrame(data, columns=['c', 'a']) ... - >>> df3 + >>> df4 c a 0 3 1 1 6 4 From c479fae6f44bcbae44bc4bb60e1a7d4cb3053ebd Mon Sep 17 00:00:00 2001 From: tyuyoshi Date: Tue, 10 Aug 2021 14:39:16 +0900 Subject: [PATCH 2/7] Modify: NaN is float object --- pandas/core/frame.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index d0abd497f77d2..b4ad573f8b130 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -527,8 +527,8 @@ class DataFrame(NDFrame, OpsMixin): col1 col2 1 1 NaN 2 2 NaN - 3 3 3 - 4 4 4 + 3 3 3.0 + 4 4 4.0 Constructing DataFrame from numpy ndarray: From a79e05b55a9e178f65889977259a78c030b93658 Mon Sep 17 00:00:00 2001 From: tyuyoshi Date: Tue, 10 Aug 2021 15:47:08 +0900 Subject: [PATCH 3/7] Modify: decrease objects --- pandas/core/frame.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index b4ad573f8b130..6d2945fe42fd7 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -522,8 +522,7 @@ class DataFrame(NDFrame, OpsMixin): Constructing DataFrame from a dictionary including Series. >>> d = {'col1': [1, 2, 3, 4], 'col2': pd.Series([3, 4], index=[3, 4])} - >>> df2 = pd.DataFrame(data=d, index=[1, 2, 3, 4]) - >>> df2 + >>> pd.DataFrame(data=d, index=[1, 2, 3, 4]) col1 col2 1 1 NaN 2 2 NaN @@ -532,9 +531,9 @@ class DataFrame(NDFrame, OpsMixin): Constructing DataFrame from numpy ndarray: - >>> df3 = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), + >>> df2 = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), ... columns=['a', 'b', 'c']) - >>> df3 + >>> df2 a b c 0 1 2 3 1 4 5 6 @@ -544,9 +543,9 @@ class DataFrame(NDFrame, OpsMixin): >>> data = np.array([(1, 2, 3), (4, 5, 6), (7, 8, 9)], ... dtype=[("a", "i4"), ("b", "i4"), ("c", "i4")]) - >>> df4 = pd.DataFrame(data, columns=['c', 'a']) + >>> df3 = pd.DataFrame(data, columns=['c', 'a']) ... - >>> df4 + >>> df3 c a 0 3 1 1 6 4 From 112c438b4c7c0a044d20e47927b38af59def2f76 Mon Sep 17 00:00:00 2001 From: tyuyoshi Date: Fri, 13 Aug 2021 15:42:23 +0900 Subject: [PATCH 4/7] Modify: format : --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 6d2945fe42fd7..68a9647e4fc66 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -519,7 +519,7 @@ class DataFrame(NDFrame, OpsMixin): col2 int8 dtype: object - Constructing DataFrame from a dictionary including Series. + Constructing DataFrame from a dictionary including Series: >>> d = {'col1': [1, 2, 3, 4], 'col2': pd.Series([3, 4], index=[3, 4])} >>> pd.DataFrame(data=d, index=[1, 2, 3, 4]) From 5e0374301648fb82e380033a85739653107eb878 Mon Sep 17 00:00:00 2001 From: tyuyoshi Date: Mon, 16 Aug 2021 17:20:20 +0900 Subject: [PATCH 5/7] Modify: start index from 0 --- pandas/core/frame.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 68a9647e4fc66..a1fb3d48b7e88 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -521,13 +521,13 @@ class DataFrame(NDFrame, OpsMixin): Constructing DataFrame from a dictionary including Series: - >>> d = {'col1': [1, 2, 3, 4], 'col2': pd.Series([3, 4], index=[3, 4])} - >>> pd.DataFrame(data=d, index=[1, 2, 3, 4]) + >>> d = {'col1': [0, 1, 2, 3], 'col2': pd.Series([2, 3], index=[2, 3])} + >>> pd.DataFrame(data=d, index=[0, 1, 2, 3]) col1 col2 + 0 0 NaN 1 1 NaN - 2 2 NaN + 2 2 2.0 3 3 3.0 - 4 4 4.0 Constructing DataFrame from numpy ndarray: From 84d767d20a448c21f35ff2ce1ddf0e588fbec696 Mon Sep 17 00:00:00 2001 From: tyuyoshi Date: Wed, 25 Aug 2021 15:52:09 +0900 Subject: [PATCH 6/7] Modify: grammar error --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index a1fb3d48b7e88..92ffe9edf4fb1 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -463,7 +463,7 @@ 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 dict contain Series + data is a dict, column order follows insertion-order. If a dict contains Series which has an index defined, it is aligned by its index. .. versionchanged:: 0.25.0 From 8b214974fdbd3133583ee319704f8167b4a16ba3 Mon Sep 17 00:00:00 2001 From: tyuyoshi Date: Mon, 30 Aug 2021 21:47:25 +0900 Subject: [PATCH 7/7] Modify: singular -> plural --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 92ffe9edf4fb1..b50c6fd629e5e 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -464,7 +464,7 @@ 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 has an index defined, it is aligned by its index. + which have an index defined, it is aligned by its index. .. versionchanged:: 0.25.0 If data is a list of dicts, column order follows insertion-order.