From 476c5bfc37d23e50b912967fdb6115bd89c72791 Mon Sep 17 00:00:00 2001 From: dcreekp Date: Thu, 22 Mar 2018 21:03:43 +0000 Subject: [PATCH 1/5] DOC: update the pandas.Series.str.startswith docstring --- pandas/core/strings.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index b98fa106336fc..0cfdd7b2b3ef1 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -328,19 +328,42 @@ def str_contains(arr, pat, case=True, flags=0, na=np.nan, regex=True): def str_startswith(arr, pat, na=np.nan): """ - Return boolean Series/``array`` indicating whether each string in the - Series/Index starts with passed pattern. Equivalent to - :meth:`str.startswith`. + Test if the start of each string element matches a pattern. + + Return a Series of booleans indicating whether the given pattern matches + the start of each string element. + Equivalent to :meth: `str.startswith`. Parameters ---------- pat : string - Character sequence - na : bool, default NaN + Character sequence. + na : object, default NaN + Character sequence shown if element tested is not a string. Returns ------- startswith : Series/array of boolean values + + Examples + -------- + >>> s = pd.Series(['bat', 'bear', 'cat']) + >>> s.str.startswith('b') + 0 True + 1 True + 2 False + dtype: bool + >>> s = pd.Series(['bat', 'bear', 'cat', np.nan]) + >>> s.str.startswith('b', na='not_a_string') + 0 True + 1 True + 2 False + 3 not_a_string + dtype: object + + See Also + -------- + endswith : same as startswith, but tests the end of string """ f = lambda x: x.startswith(pat) return _na_map(f, arr, na, dtype=bool) From 39f76413374109d8c34021a6b61d121d3d05c9a0 Mon Sep 17 00:00:00 2001 From: dcreekp Date: Sat, 24 Mar 2018 12:57:13 +0000 Subject: [PATCH 2/5] DOC: update the pandas.Series.str.startswith docstring --- pandas/core/strings.py | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 0cfdd7b2b3ef1..f11a12cda6ad9 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -330,40 +330,41 @@ def str_startswith(arr, pat, na=np.nan): """ Test if the start of each string element matches a pattern. - Return a Series of booleans indicating whether the given pattern matches - the start of each string element. - Equivalent to :meth: `str.startswith`. + Equivalent to :meth:`str.startswith`. Parameters ---------- - pat : string - Character sequence. + pat : str + Character sequence. Regular expressions are not accepted. na : object, default NaN - Character sequence shown if element tested is not a string. + Object shown if element tested is not a string. Returns ------- - startswith : Series/array of boolean values + startswith : Series or array-like of bool + A Series of booleans indicating whether the given pattern matches + the start of each string element. + + See Also + -------- + str_endswith : Same as startswith, but tests the end of string. + str.startswith : Python standard library string method. Examples -------- - >>> s = pd.Series(['bat', 'bear', 'cat']) + >>> s = pd.Series(['bat', 'Bear', 'cat', np.nan]) >>> s.str.startswith('b') 0 True - 1 True + 1 False 2 False - dtype: bool - >>> s = pd.Series(['bat', 'bear', 'cat', np.nan]) - >>> s.str.startswith('b', na='not_a_string') - 0 True - 1 True - 2 False - 3 not_a_string + 3 NaN dtype: object - - See Also - -------- - endswith : same as startswith, but tests the end of string + >>> s.str.startswith('b', na=False) + 0 True + 1 False + 2 False + 3 False + dtype: bool """ f = lambda x: x.startswith(pat) return _na_map(f, arr, na, dtype=bool) From 702286be174c128f44c7fe80e5143b3b3d67cae7 Mon Sep 17 00:00:00 2001 From: dcreekp Date: Sat, 24 Mar 2018 15:41:25 +0000 Subject: [PATCH 3/5] DOC: update the pandas.Series.str.startswith docstring 2 --- 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 f11a12cda6ad9..ece1bbcd1c646 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -347,8 +347,9 @@ def str_startswith(arr, pat, na=np.nan): See Also -------- - str_endswith : Same as startswith, but tests the end of string. str.startswith : Python standard library string method. + Series.str.endswith : Same as startswith, but tests the end of string. + Series.str.contains : Tests if string element contains a pattern. Examples -------- From 27bc6796685ae53b437206adeb452044718e9958 Mon Sep 17 00:00:00 2001 From: dcreekp Date: Sun, 25 Mar 2018 08:31:54 +0100 Subject: [PATCH 4/5] DOC: update the pandas.Series.str.startswith docstring 3 --- pandas/core/strings.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index ece1bbcd1c646..dad871c0e277e 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -341,7 +341,7 @@ def str_startswith(arr, pat, na=np.nan): Returns ------- - startswith : Series or array-like of bool + Series or Index of bool A Series of booleans indicating whether the given pattern matches the start of each string element. @@ -360,6 +360,10 @@ def str_startswith(arr, pat, na=np.nan): 2 False 3 NaN dtype: object + + Specifying `na` to be `False` instead of `NaN`. + + >>> s = pd.Series(['bat', 'Bear', 'cat', np.nan]) >>> s.str.startswith('b', na=False) 0 True 1 False From 9a6d0183818e9aa1142d7e68a3e3be8fb5867eb7 Mon Sep 17 00:00:00 2001 From: dcreekp Date: Sun, 25 Mar 2018 22:14:12 +0100 Subject: [PATCH 5/5] DOC: update the pandas.Series.str.startswith docstring 4 --- pandas/core/strings.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index dad871c0e277e..d6a67435aeb09 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -354,6 +354,13 @@ def str_startswith(arr, pat, na=np.nan): Examples -------- >>> s = pd.Series(['bat', 'Bear', 'cat', np.nan]) + >>> s + 0 bat + 1 Bear + 2 cat + 3 NaN + dtype: object + >>> s.str.startswith('b') 0 True 1 False @@ -363,7 +370,6 @@ def str_startswith(arr, pat, na=np.nan): Specifying `na` to be `False` instead of `NaN`. - >>> s = pd.Series(['bat', 'Bear', 'cat', np.nan]) >>> s.str.startswith('b', na=False) 0 True 1 False