From c27155907268cd55b788981cb6343de712645806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D7=9E=D7=99=D7=A8=D7=91=20=D7=91=D7=9F=20=D7=99=D7=A6?= =?UTF-8?q?=D7=97=D7=A7?= Date: Sat, 19 Jun 2021 19:59:16 +0300 Subject: [PATCH 1/2] added examples to align function's documentation --- pandas/core/generic.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 5bd845534fc96..a12222dff2da3 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8514,10 +8514,31 @@ def align( ------- (left, right) : ({klass}, type of other) Aligned objects. - """ - - method = missing.clean_fill_method(method) + Examples + -------- + >>> df1 = pd.DataFrame([[1,2,3,4], [6,7,8,9]], columns=['D', 'B', 'E', 'A'], index=[1,2]) + >>> df2 = pd.DataFrame([[10,20,30,40], [60,70,80,90], [600,700,800,900]], columns=['A', 'B', 'C', 'D'], index=[2,3,4]) + + >>> a1, a2 = df1.align(df2, join='outer', axis=1) + >>> a1 + A B C D E + 1 4 2 NaN 1 3 + 2 9 7 NaN 6 8 + >>> a2 + A B C D E + 2 10 20 30 40 NaN + 3 60 70 80 90 NaN + 4 600 700 800 900 NaN + + >>> a1, a2 = df1.align(df2, join='inner', axis=None) + >>> a1 + D B A + 2 6 7 9 + >>> a2 + D B A + 2 40 20 10 + """ if broadcast_axis == 1 and self.ndim != other.ndim: if isinstance(self, ABCSeries): # this means other is a DataFrame, and we need to broadcast From 7116772be261cf7eb117e64b3dd3abd87e25fe46 Mon Sep 17 00:00:00 2001 From: meiruv Date: Tue, 13 Jul 2021 14:54:01 +0300 Subject: [PATCH 2/2] Addressed CR --- pandas/core/generic.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a12222dff2da3..4059aa547163f 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8514,11 +8514,16 @@ def align( ------- (left, right) : ({klass}, type of other) Aligned objects. + """ + method = missing.clean_fill_method(method) + """ Examples -------- - >>> df1 = pd.DataFrame([[1,2,3,4], [6,7,8,9]], columns=['D', 'B', 'E', 'A'], index=[1,2]) - >>> df2 = pd.DataFrame([[10,20,30,40], [60,70,80,90], [600,700,800,900]], columns=['A', 'B', 'C', 'D'], index=[2,3,4]) + >>> df1 = pd.DataFrame([[1,2,3,4], [6,7,8,9]], + columns=['D', 'B', 'E', 'A'], index=[1,2]) + >>> df2 = pd.DataFrame([[10,20,30,40], [60,70,80,90], [600,700,800,900]], + columns=['A', 'B', 'C', 'D'], index=[2,3,4]) >>> a1, a2 = df1.align(df2, join='outer', axis=1) >>> a1 @@ -8539,6 +8544,7 @@ def align( D B A 2 40 20 10 """ + if broadcast_axis == 1 and self.ndim != other.ndim: if isinstance(self, ABCSeries): # this means other is a DataFrame, and we need to broadcast