From 52bc395c4efc64a66ca1d067ec71912e290bbb08 Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Sat, 1 Sep 2018 15:16:18 +0200 Subject: [PATCH 1/4] Cleaned up docstring for str_pad and corrected documentation to match behaviour. Added examples --- pandas/core/strings.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index e455c751057d1..d209a80cc4e3e 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1314,8 +1314,8 @@ def str_index(arr, sub, start=0, end=None, side='left'): def str_pad(arr, width, side='left', fillchar=' '): """ - Pad strings in the Series/Index with an additional character to - specified side. + Pad strings in the Series/Index with additional characters on + specified side to fill up to specified width. Parameters ---------- @@ -1323,12 +1323,32 @@ def str_pad(arr, width, side='left', fillchar=' '): Minimum width of resulting string; additional characters will be filled with spaces side : {'left', 'right', 'both'}, default 'left' - fillchar : str + fillchar : str, default ' ' Additional character for filling, default is whitespace Returns ------- - padded : Series/Index of objects + Series or Index of objects + + Examples + -------- + >>> s = pd.Series(["panda", "fox"]) + >>> s + 0 panda + 1 fox + + >>> s.str.pad(10) + 0 panda + 1 fox + + >>> s.str.pad(10, 'right') + 0 panda + 1 fox + + >>> s.str.pad(10, 'both', '-') + 0 --panda--- + 1 ---fox---- + """ if not isinstance(fillchar, compat.string_types): From 5d5b192f409b4c4145a133e75de571d872801833 Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Sat, 1 Sep 2018 15:18:48 +0200 Subject: [PATCH 2/4] PEP8-ing --- pandas/core/strings.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index d209a80cc4e3e..898a362ad586a 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1336,7 +1336,7 @@ def str_pad(arr, width, side='left', fillchar=' '): >>> s 0 panda 1 fox - + >>> s.str.pad(10) 0 panda 1 fox @@ -1348,7 +1348,6 @@ def str_pad(arr, width, side='left', fillchar=' '): >>> s.str.pad(10, 'both', '-') 0 --panda--- 1 ---fox---- - """ if not isinstance(fillchar, compat.string_types): From 28ec7b0b4d170025a2c8813fadf88842f74dcad2 Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Sat, 1 Sep 2018 15:25:16 +0200 Subject: [PATCH 3/4] PEP8-ing example --- 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 898a362ad586a..9d9ed65b5ffcb 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1341,9 +1341,9 @@ def str_pad(arr, width, side='left', fillchar=' '): 0 panda 1 fox - >>> s.str.pad(10, 'right') - 0 panda - 1 fox + >>> s.str.pad(10, 'right', '-') + 0 panda----- + 1 fox------- >>> s.str.pad(10, 'both', '-') 0 --panda--- From 8337a530f1145c13ad1a2335270669b444756b0a Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Sat, 1 Sep 2018 15:54:09 +0200 Subject: [PATCH 4/4] Explicit names and some fixes --- 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 9d9ed65b5ffcb..98216c3a7455e 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1321,14 +1321,16 @@ def str_pad(arr, width, side='left', fillchar=' '): ---------- width : int Minimum width of resulting string; additional characters will be filled - with spaces + with character defined in fillchar side : {'left', 'right', 'both'}, default 'left' + Side from which to fill resulting string fillchar : str, default ' ' Additional character for filling, default is whitespace Returns ------- - Series or Index of objects + Series or Index of object + Returns Series or Index with minimum number of char in object Examples -------- @@ -1337,15 +1339,15 @@ def str_pad(arr, width, side='left', fillchar=' '): 0 panda 1 fox - >>> s.str.pad(10) + >>> s.str.pad(width=10) 0 panda 1 fox - >>> s.str.pad(10, 'right', '-') + >>> s.str.pad(width=10, side='right', fillchar='-') 0 panda----- 1 fox------- - >>> s.str.pad(10, 'both', '-') + >>> s.str.pad(width=10, side='both', fillchar='-') 0 --panda--- 1 ---fox---- """