From 27173587f18a1a5cd855609e17f67827a73bd099 Mon Sep 17 00:00:00 2001 From: ahmedibrhm <81244897+ahmedibrhm@users.noreply.github.com> Date: Thu, 7 Jul 2022 10:39:09 -0700 Subject: [PATCH 1/7] "#45443 edited the documentation of where/mask functions" --- pandas/core/generic.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index ba3474a2513fb..933fb320b7a4a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9570,7 +9570,9 @@ def where( ---------- cond : bool {klass}, array-like, or callable Where `cond` is {cond}, keep the original value. Where - {cond_rev}, replace with corresponding value from `other`. + {cond_rev}, replace with corresponding value from `other`. + if `cond` {klass} is less in size than `other`, the default bool + for the missing value is {cond_rev}. If `cond` is callable, it is computed on the {klass} and should return boolean {klass} or array. The callable must not change input {klass} (though pandas doesn't check it). From 7e70e76fe3f3dd64b79166fdb0f8f4a7c4ff894f Mon Sep 17 00:00:00 2001 From: Ahmed Ibrahim <81244897+ahmedibrhm@users.noreply.github.com> Date: Thu, 7 Jul 2022 14:49:23 -0700 Subject: [PATCH 2/7] Update generic.py --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 933fb320b7a4a..20e0479be4856 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9570,7 +9570,7 @@ def where( ---------- cond : bool {klass}, array-like, or callable Where `cond` is {cond}, keep the original value. Where - {cond_rev}, replace with corresponding value from `other`. + {cond_rev}, replace with corresponding value from `other`. if `cond` {klass} is less in size than `other`, the default bool for the missing value is {cond_rev}. If `cond` is callable, it is computed on the {klass} and From 3c5b51b86fec7f9c22d171428d1a7b8550fda88c Mon Sep 17 00:00:00 2001 From: Ahmed Ibrahim <81244897+ahmedibrhm@users.noreply.github.com> Date: Thu, 7 Jul 2022 23:28:10 -0700 Subject: [PATCH 3/7] Update generic.py --- pandas/core/generic.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 20e0479be4856..2135e3b25bbd3 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9616,7 +9616,8 @@ def where( The {name} method is an application of the if-then idiom. For each element in the calling DataFrame, if ``cond`` is ``{cond}`` the element is used; otherwise the corresponding element from the DataFrame - ``other`` is used. + ``other`` is used. If `cond` {klass} is less in size than `other`, the default bool + for the missing value is {cond_rev}. The signature for :func:`DataFrame.where` differs from :func:`numpy.where`. Roughly ``df1.where(m, df2)`` is equivalent to @@ -9643,6 +9644,23 @@ def where( 4 NaN dtype: float64 + >>> s = pd.Series(range(5)) + >>> t = pd.Series([True, False]) + >>> s.where(t,99) + 0 0 + 1 99 + 2 99 + 3 99 + 4 99 + dtype: int64 + >>> s.mask(t, 99) + 0 99 + 1 1 + 2 99 + 3 99 + 4 99 + dtype: int64 + >>> s.where(s > 1, 10) 0 10 1 10 From f229bd3cd3df04e40bbc3dbba03620834d5a3b46 Mon Sep 17 00:00:00 2001 From: Ahmed Ibrahim <81244897+ahmedibrhm@users.noreply.github.com> Date: Thu, 7 Jul 2022 23:30:14 -0700 Subject: [PATCH 4/7] Update generic.py --- pandas/core/generic.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 2135e3b25bbd3..b46eff137394c 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9571,8 +9571,6 @@ def where( cond : bool {klass}, array-like, or callable Where `cond` is {cond}, keep the original value. Where {cond_rev}, replace with corresponding value from `other`. - if `cond` {klass} is less in size than `other`, the default bool - for the missing value is {cond_rev}. If `cond` is callable, it is computed on the {klass} and should return boolean {klass} or array. The callable must not change input {klass} (though pandas doesn't check it). From 70dac6fbf463c5d3707ba816a98cd402bc0534d5 Mon Sep 17 00:00:00 2001 From: Ahmed Ibrahim <81244897+ahmedibrhm@users.noreply.github.com> Date: Fri, 8 Jul 2022 09:52:13 -0700 Subject: [PATCH 5/7] Update pandas/core/generic.py Co-authored-by: Matthew Roeschke --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index b46eff137394c..11444d4929ff4 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9644,7 +9644,7 @@ def where( >>> s = pd.Series(range(5)) >>> t = pd.Series([True, False]) - >>> s.where(t,99) + >>> s.where(t, 99) 0 0 1 99 2 99 From 4fd16d160b0738909d56fa5b7649bf61142885bc Mon Sep 17 00:00:00 2001 From: Ahmed Ibrahim <81244897+ahmedibrhm@users.noreply.github.com> Date: Fri, 8 Jul 2022 09:56:11 -0700 Subject: [PATCH 6/7] Update generic.py --- pandas/core/generic.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 11444d4929ff4..dab1c45fb2fcc 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9614,8 +9614,9 @@ def where( The {name} method is an application of the if-then idiom. For each element in the calling DataFrame, if ``cond`` is ``{cond}`` the element is used; otherwise the corresponding element from the DataFrame - ``other`` is used. If `cond` {klass} is less in size than `other`, the default bool - for the missing value is {cond_rev}. + ``other`` is used. If the axis of ``other`` does not align with axis of + ``cond`` {klass}, the misaligned index positions will be filled with + {cond_rev} The signature for :func:`DataFrame.where` differs from :func:`numpy.where`. Roughly ``df1.where(m, df2)`` is equivalent to From 51347f010e2c9bdbaf5bbbe3e820014ff01243d2 Mon Sep 17 00:00:00 2001 From: Ahmed Ibrahim <81244897+ahmedibrhm@users.noreply.github.com> Date: Fri, 8 Jul 2022 10:08:23 -0700 Subject: [PATCH 7/7] Update generic.py --- pandas/core/generic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index dab1c45fb2fcc..8089fc58db07d 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9614,9 +9614,9 @@ def where( The {name} method is an application of the if-then idiom. For each element in the calling DataFrame, if ``cond`` is ``{cond}`` the element is used; otherwise the corresponding element from the DataFrame - ``other`` is used. If the axis of ``other`` does not align with axis of - ``cond`` {klass}, the misaligned index positions will be filled with - {cond_rev} + ``other`` is used. If the axis of ``other`` does not align with axis of + ``cond`` {klass}, the misaligned index positions will be filled with + {cond_rev}. The signature for :func:`DataFrame.where` differs from :func:`numpy.where`. Roughly ``df1.where(m, df2)`` is equivalent to