From 8956341f0244816a3d03fdd11ac936b97d7c1195 Mon Sep 17 00:00:00 2001 From: jpgianfaldoni Date: Mon, 30 Oct 2023 08:41:28 -0300 Subject: [PATCH 01/12] fix replace docs --- pandas/core/shared_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/shared_docs.py b/pandas/core/shared_docs.py index ec219941a3afc..5d3526ba00bfd 100644 --- a/pandas/core/shared_docs.py +++ b/pandas/core/shared_docs.py @@ -570,7 +570,7 @@ .. deprecated:: 2.1.0 regex : bool or same types as `to_replace`, default False Whether to interpret `to_replace` and/or `value` as regular - expressions. If this is ``True`` then `to_replace` *must* be a + expressions. If this is ``True`` and value is not ``None``, then `to_replace` *must* be a string. Alternatively, this could be a regular expression or a list, dict, or array of regular expressions in which case `to_replace` must be ``None``. From 80334ca48cbf499d0387983c43ba495e6def07a1 Mon Sep 17 00:00:00 2001 From: jpgianfaldoni Date: Mon, 30 Oct 2023 09:04:28 -0300 Subject: [PATCH 02/12] fix replace docs --- pandas/core/shared_docs.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pandas/core/shared_docs.py b/pandas/core/shared_docs.py index 5d3526ba00bfd..b45ef76f0563e 100644 --- a/pandas/core/shared_docs.py +++ b/pandas/core/shared_docs.py @@ -570,8 +570,11 @@ .. deprecated:: 2.1.0 regex : bool or same types as `to_replace`, default False Whether to interpret `to_replace` and/or `value` as regular - expressions. If this is ``True`` and value is not ``None``, then `to_replace` *must* be a - string. Alternatively, this could be a regular expression or a + expressions. If this is ``True``, `value` is not ``None`` and `to_replace` is a string, + then the replacement will be applied in all columns of the DataFrame. + If `value` is not ``None`` and `to_replace` is a dictionary, the dictionary keys will be + the DataFrame columns that the replacement will be applied. + Alternatively, this could be a regular expression or a list, dict, or array of regular expressions in which case `to_replace` must be ``None``. method : {{'pad', 'ffill', 'bfill'}} From 7324c3fbbdca852828f20fb8c4b1882e3d2e5a9a Mon Sep 17 00:00:00 2001 From: jpgianfaldoni Date: Tue, 31 Oct 2023 09:36:03 -0300 Subject: [PATCH 03/12] move description to examples --- pandas/core/shared_docs.py | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/pandas/core/shared_docs.py b/pandas/core/shared_docs.py index b45ef76f0563e..b4ad2c11399b3 100644 --- a/pandas/core/shared_docs.py +++ b/pandas/core/shared_docs.py @@ -570,11 +570,7 @@ .. deprecated:: 2.1.0 regex : bool or same types as `to_replace`, default False Whether to interpret `to_replace` and/or `value` as regular - expressions. If this is ``True``, `value` is not ``None`` and `to_replace` is a string, - then the replacement will be applied in all columns of the DataFrame. - If `value` is not ``None`` and `to_replace` is a dictionary, the dictionary keys will be - the DataFrame columns that the replacement will be applied. - Alternatively, this could be a regular expression or a + expressions. Alternatively, this could be a regular expression or a list, dict, or array of regular expressions in which case `to_replace` must be ``None``. method : {{'pad', 'ffill', 'bfill'}} @@ -793,6 +789,34 @@ .. versionchanged:: 1.4.0 Previously the explicit ``None`` was silently ignored. + + When `Regex`is ``True``, `value` is not ``None`` and `to_replace` is a string, + the replacement will be applied in all columns of the DataFrame. + + >>> df = pd.DataFrame({'A': [0, 1, 2, 3, 4], + 'B': ['a', 'b', 'c', 'd', 'e'], + 'C': ['f', 'g', 'h', 'i', 'j']}) + + >>> df.replace(to_replace='^[a-g]', value = 'e', regex=True) + A B C + 0 0 e e + 1 1 e e + 2 2 e h + 3 3 e i + 4 4 e j + + + + If `value` is not ``None`` and `to_replace` is a dictionary, the dictionary keys will be + the DataFrame columns that the replacement will be applied. + + >>> df.replace(to_replace={'B': '^[a-c]', 'C': '^[h-j]'}, value = 'e', regex=True) + A B C + 0 0 e f + 1 1 e g + 2 2 e e + 3 3 d e + 4 4 e e """ _shared_docs[ From 7332fb055f3d86745ca99ce8ccd81daf95d445fc Mon Sep 17 00:00:00 2001 From: jpgianfaldoni Date: Wed, 1 Nov 2023 13:40:49 -0300 Subject: [PATCH 04/12] fix spacing --- pandas/core/shared_docs.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/core/shared_docs.py b/pandas/core/shared_docs.py index b4ad2c11399b3..a01f62a0eacdb 100644 --- a/pandas/core/shared_docs.py +++ b/pandas/core/shared_docs.py @@ -805,8 +805,6 @@ 3 3 e i 4 4 e j - - If `value` is not ``None`` and `to_replace` is a dictionary, the dictionary keys will be the DataFrame columns that the replacement will be applied. From bca9c567c23161a11d5f8eeb664b75d68840ca43 Mon Sep 17 00:00:00 2001 From: jpgianfaldoni Date: Wed, 1 Nov 2023 13:49:54 -0300 Subject: [PATCH 05/12] fix dicts --- pandas/core/shared_docs.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/shared_docs.py b/pandas/core/shared_docs.py index a01f62a0eacdb..bd2371534fc56 100644 --- a/pandas/core/shared_docs.py +++ b/pandas/core/shared_docs.py @@ -793,9 +793,9 @@ When `Regex`is ``True``, `value` is not ``None`` and `to_replace` is a string, the replacement will be applied in all columns of the DataFrame. - >>> df = pd.DataFrame({'A': [0, 1, 2, 3, 4], + >>> df = pd.DataFrame({{'A': [0, 1, 2, 3, 4], 'B': ['a', 'b', 'c', 'd', 'e'], - 'C': ['f', 'g', 'h', 'i', 'j']}) + 'C': ['f', 'g', 'h', 'i', 'j']}}) >>> df.replace(to_replace='^[a-g]', value = 'e', regex=True) A B C @@ -808,7 +808,7 @@ If `value` is not ``None`` and `to_replace` is a dictionary, the dictionary keys will be the DataFrame columns that the replacement will be applied. - >>> df.replace(to_replace={'B': '^[a-c]', 'C': '^[h-j]'}, value = 'e', regex=True) + >>> df.replace(to_replace={{'B': '^[a-c]', 'C': '^[h-j]'}}, value = 'e', regex=True) A B C 0 0 e f 1 1 e g From 5c0609b328fcd5c93bbb19a5af43bd14d94bd9af Mon Sep 17 00:00:00 2001 From: jpgianfaldoni Date: Wed, 1 Nov 2023 14:03:05 -0300 Subject: [PATCH 06/12] fix line size --- pandas/core/shared_docs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/shared_docs.py b/pandas/core/shared_docs.py index bd2371534fc56..5cc3959734c4d 100644 --- a/pandas/core/shared_docs.py +++ b/pandas/core/shared_docs.py @@ -805,8 +805,8 @@ 3 3 e i 4 4 e j - If `value` is not ``None`` and `to_replace` is a dictionary, the dictionary keys will be - the DataFrame columns that the replacement will be applied. + If `value` is not ``None`` and `to_replace` is a dictionary, the dictionary + keys will be the DataFrame columns that the replacement will be applied. >>> df.replace(to_replace={{'B': '^[a-c]', 'C': '^[h-j]'}}, value = 'e', regex=True) A B C From 43146f27645914f68d279354eb3322e11b6f8699 Mon Sep 17 00:00:00 2001 From: jpgianfaldoni Date: Wed, 1 Nov 2023 15:18:31 -0300 Subject: [PATCH 07/12] fix whitespace --- pandas/core/shared_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/shared_docs.py b/pandas/core/shared_docs.py index 5cc3959734c4d..1a8b444ea07f5 100644 --- a/pandas/core/shared_docs.py +++ b/pandas/core/shared_docs.py @@ -805,7 +805,7 @@ 3 3 e i 4 4 e j - If `value` is not ``None`` and `to_replace` is a dictionary, the dictionary + If `value` is not ``None`` and `to_replace` is a dictionary, the dictionary keys will be the DataFrame columns that the replacement will be applied. >>> df.replace(to_replace={{'B': '^[a-c]', 'C': '^[h-j]'}}, value = 'e', regex=True) From 470e6f16de67d86c118ca500a21e1c2d91e1177d Mon Sep 17 00:00:00 2001 From: jpgianfaldoni Date: Wed, 1 Nov 2023 16:58:31 -0300 Subject: [PATCH 08/12] remove trailling whitespaces --- pandas/core/shared_docs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/shared_docs.py b/pandas/core/shared_docs.py index 1a8b444ea07f5..81af7a6042eb4 100644 --- a/pandas/core/shared_docs.py +++ b/pandas/core/shared_docs.py @@ -789,14 +789,14 @@ .. versionchanged:: 1.4.0 Previously the explicit ``None`` was silently ignored. - + When `Regex`is ``True``, `value` is not ``None`` and `to_replace` is a string, the replacement will be applied in all columns of the DataFrame. >>> df = pd.DataFrame({{'A': [0, 1, 2, 3, 4], 'B': ['a', 'b', 'c', 'd', 'e'], 'C': ['f', 'g', 'h', 'i', 'j']}}) - + >>> df.replace(to_replace='^[a-g]', value = 'e', regex=True) A B C 0 0 e e From 7d451e6988aa4c0b086bf8d22bafa0ba3b331a1c Mon Sep 17 00:00:00 2001 From: jpgianfaldoni Date: Wed, 1 Nov 2023 17:36:40 -0300 Subject: [PATCH 09/12] fix df --- pandas/core/shared_docs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/shared_docs.py b/pandas/core/shared_docs.py index 81af7a6042eb4..d60be99b90776 100644 --- a/pandas/core/shared_docs.py +++ b/pandas/core/shared_docs.py @@ -794,8 +794,8 @@ the replacement will be applied in all columns of the DataFrame. >>> df = pd.DataFrame({{'A': [0, 1, 2, 3, 4], - 'B': ['a', 'b', 'c', 'd', 'e'], - 'C': ['f', 'g', 'h', 'i', 'j']}}) + ... 'B': [a, b, c, d, e], + ... 'C': [f, g, h, i, j]}}) >>> df.replace(to_replace='^[a-g]', value = 'e', regex=True) A B C From 7310935b86993a0134442ecd9368df531a02dcbc Mon Sep 17 00:00:00 2001 From: jpgianfaldoni Date: Wed, 1 Nov 2023 18:28:41 -0300 Subject: [PATCH 10/12] fix df --- pandas/core/shared_docs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/shared_docs.py b/pandas/core/shared_docs.py index d60be99b90776..9eeb393422a4a 100644 --- a/pandas/core/shared_docs.py +++ b/pandas/core/shared_docs.py @@ -794,8 +794,8 @@ the replacement will be applied in all columns of the DataFrame. >>> df = pd.DataFrame({{'A': [0, 1, 2, 3, 4], - ... 'B': [a, b, c, d, e], - ... 'C': [f, g, h, i, j]}}) + ... 'B': ['a', 'b', 'c', 'd', 'e'], + ... 'C': ['f', 'g', 'h', 'i', 'j']}}) >>> df.replace(to_replace='^[a-g]', value = 'e', regex=True) A B C From 46343d404739db780c9f70d7ae7dfd766359e209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Andrade?= <49215007+jpgianfaldoni@users.noreply.github.com> Date: Fri, 3 Nov 2023 11:16:57 -0300 Subject: [PATCH 11/12] Update pandas/core/shared_docs.py Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> --- pandas/core/shared_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/shared_docs.py b/pandas/core/shared_docs.py index 9eeb393422a4a..64b889994a07d 100644 --- a/pandas/core/shared_docs.py +++ b/pandas/core/shared_docs.py @@ -790,7 +790,7 @@ .. versionchanged:: 1.4.0 Previously the explicit ``None`` was silently ignored. - When `Regex`is ``True``, `value` is not ``None`` and `to_replace` is a string, + When ``regex=True``, ``value`` is not ``None`` and `to_replace` is a string, the replacement will be applied in all columns of the DataFrame. >>> df = pd.DataFrame({{'A': [0, 1, 2, 3, 4], From c6a99f5d8d2225c36516b60f2c46291f309ccf19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Andrade?= <49215007+jpgianfaldoni@users.noreply.github.com> Date: Fri, 3 Nov 2023 11:17:07 -0300 Subject: [PATCH 12/12] Update pandas/core/shared_docs.py Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> --- pandas/core/shared_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/shared_docs.py b/pandas/core/shared_docs.py index 64b889994a07d..4bbbd9266a94a 100644 --- a/pandas/core/shared_docs.py +++ b/pandas/core/shared_docs.py @@ -805,7 +805,7 @@ 3 3 e i 4 4 e j - If `value` is not ``None`` and `to_replace` is a dictionary, the dictionary + If ``value`` is not ``None`` and `to_replace` is a dictionary, the dictionary keys will be the DataFrame columns that the replacement will be applied. >>> df.replace(to_replace={{'B': '^[a-c]', 'C': '^[h-j]'}}, value = 'e', regex=True)