From 17d5f83e573ae305ccd04facd8b96b76f7f65355 Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Sat, 1 Sep 2018 14:47:59 +0200 Subject: [PATCH 1/9] Cleaned up DocString for str_repeat and added examples --- pandas/core/strings.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index e455c751057d1..edcadc981ae73 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -680,12 +680,33 @@ def str_repeat(arr, repeats): Parameters ---------- - repeats : int or array + repeats : int or array of int Same value for all (int) or different value per (array) Returns ------- - repeated : Series/Index of objects + Series or Index of objects + + Examples + -------- + + >>> s = pd.Series(['a', 'b', 'c']) + >>> s + 0 a + 1 b + 2 c + + Single int repeats string in Series + >>> s.str.repeat(2) + 0 aa + 1 bb + 2 cc + + Array of int repeats corresponding string in Series + >>> s.str.repeat([1, 2, 3]) + 0 a + 1 bb + 2 ccc """ if is_scalar(repeats): From 6e9a86991c7e768329ae1fe4e0eda5fbf1cf6170 Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Sat, 1 Sep 2018 15:19:55 +0200 Subject: [PATCH 2/9] PEP8-ing --- pandas/core/strings.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index edcadc981ae73..fca7a9aa3dbc7 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -689,20 +689,20 @@ def str_repeat(arr, repeats): Examples -------- - + >>> s = pd.Series(['a', 'b', 'c']) >>> s 0 a 1 b 2 c - + Single int repeats string in Series >>> s.str.repeat(2) 0 aa 1 bb 2 cc - Array of int repeats corresponding string in Series + Array of int repeats corresponding string in Series >>> s.str.repeat([1, 2, 3]) 0 a 1 bb From 55dcbb2f75eb84a110d702bcc463c6f1f48b2e0d Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Sat, 1 Sep 2018 15:45:13 +0200 Subject: [PATCH 3/9] Suggested changes implemented --- pandas/core/strings.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index fca7a9aa3dbc7..45ad9e87a8262 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -680,12 +680,12 @@ def str_repeat(arr, repeats): Parameters ---------- - repeats : int or array of int - Same value for all (int) or different value per (array) + repeats : int or sequence of int + Same value for all (int) or different value per (sequence) Returns ------- - Series or Index of objects + Series or Index of object Examples -------- @@ -697,13 +697,15 @@ def str_repeat(arr, repeats): 2 c Single int repeats string in Series - >>> s.str.repeat(2) + + >>> s.str.repeat(repeats=2) 0 aa 1 bb 2 cc Array of int repeats corresponding string in Series - >>> s.str.repeat([1, 2, 3]) + + >>> s.str.repeat(repeats=[1, 2, 3]) 0 a 1 bb 2 ccc From ba258a9a665a7965abb65d97897e5568801064c8 Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Sat, 1 Sep 2018 15:45:40 +0200 Subject: [PATCH 4/9] blank line --- pandas/core/strings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 45ad9e87a8262..ffff6a81f9dba 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -689,7 +689,6 @@ def str_repeat(arr, repeats): Examples -------- - >>> s = pd.Series(['a', 'b', 'c']) >>> s 0 a From c2dbb94cfbd7ef2dda79059ec2ff9d039a6254c0 Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Sat, 1 Sep 2018 15:48:47 +0200 Subject: [PATCH 5/9] Explanation --- pandas/core/strings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index ffff6a81f9dba..333f7321ba33f 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -686,6 +686,7 @@ def str_repeat(arr, repeats): Returns ------- Series or Index of object + Series or Index of repeated string object specified by input parameter repeats Examples -------- From 1f43f874eec176e12cc148c54cf2ac1f7442055c Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Sat, 1 Sep 2018 15:49:41 +0200 Subject: [PATCH 6/9] Array -> Sequence --- pandas/core/strings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 333f7321ba33f..6720510f19626 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -703,7 +703,7 @@ def str_repeat(arr, repeats): 1 bb 2 cc - Array of int repeats corresponding string in Series + Sequence of int repeats corresponding string in Series >>> s.str.repeat(repeats=[1, 2, 3]) 0 a From 6a86ba2c7240065e72a611ec7a563c978bcbb395 Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Sat, 1 Sep 2018 16:35:07 +0200 Subject: [PATCH 7/9] missing s --- pandas/core/strings.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 6720510f19626..2591990db27b1 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -686,7 +686,8 @@ def str_repeat(arr, repeats): Returns ------- Series or Index of object - Series or Index of repeated string object specified by input parameter repeats + Series or Index of repeated string objects specified by + input parameter repeats Examples -------- From 974cc68d861985bed83c5879f8d08e050bac2f9d Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Sun, 2 Sep 2018 11:33:18 +0200 Subject: [PATCH 8/9] Single string doc start --- pandas/core/strings.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 2591990db27b1..1006fafdc1cf5 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -675,8 +675,7 @@ def str_replace(arr, pat, repl, n=-1, case=None, flags=0, regex=True): def str_repeat(arr, repeats): """ - Duplicate each string in the Series/Index by indicated number - of times. + Duplicate each string in the Series or Index Parameters ---------- @@ -686,7 +685,7 @@ def str_repeat(arr, repeats): Returns ------- Series or Index of object - Series or Index of repeated string objects specified by + Series or Index of repeated string objects specified by input parameter repeats Examples From a252aa75ebef8bfab1cf2f38e0098d101b99c408 Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Sun, 2 Sep 2018 11:54:10 +0200 Subject: [PATCH 9/9] Added periods --- pandas/core/strings.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 1006fafdc1cf5..776058bd45d22 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -675,18 +675,18 @@ def str_replace(arr, pat, repl, n=-1, case=None, flags=0, regex=True): def str_repeat(arr, repeats): """ - Duplicate each string in the Series or Index + Duplicate each string in the Series or Index. Parameters ---------- repeats : int or sequence of int - Same value for all (int) or different value per (sequence) + Same value for all (int) or different value per (sequence). Returns ------- Series or Index of object Series or Index of repeated string objects specified by - input parameter repeats + input parameter repeats. Examples -------- @@ -711,7 +711,6 @@ def str_repeat(arr, repeats): 2 ccc """ if is_scalar(repeats): - def rep(x): try: return compat.binary_type.__mul__(x, repeats)