From 17d5f83e573ae305ccd04facd8b96b76f7f65355 Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Sat, 1 Sep 2018 14:47:59 +0200 Subject: [PATCH 1/6] 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/6] 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/6] 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/6] 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/6] 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/6] 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