From 673a28e3b330639d231ac0b6025bd976945e121b Mon Sep 17 00:00:00 2001 From: Mark Woodbridge <1101318+mrw34@users.noreply.github.com> Date: Tue, 20 Mar 2018 21:13:21 +0000 Subject: [PATCH 1/3] DOC: update the Series.between docstring --- pandas/core/series.py | 53 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index e4801242073a2..2da47459bcc85 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3511,19 +3511,64 @@ def isin(self, values): def between(self, left, right, inclusive=True): """ - Return boolean Series equivalent to left <= series <= right. NA values - will be treated as False + Return boolean Series equivalent to left <= series <= right. + + This function returns a boolean vector containing `True` wherever the + corresponding Series element is between the boundary values `left` and + `right`. NA values are treated as `False`. Parameters ---------- left : scalar - Left boundary + Left boundary. right : scalar - Right boundary + Right boundary. + inclusive : bool, default True + Include boundaries. Returns ------- is_between : Series + + Examples + -------- + + >>> s = pd.Series([2, 0, 4, 8, np.nan]) + + Boundary values are included by default: + + >>> s.between(1, 4) + 0 True + 1 False + 2 True + 3 False + 4 False + dtype: bool + + With `inclusive` set to `False` boundary values are excluded: + + >>> s.between(1, 4, inclusive=False) + 0 True + 1 False + 2 False + 3 False + 4 False + dtype: bool + + `left` and `right` can be any scalar value: + + >>> s = pd.Series(['Alice', 'Bob', 'Carol', 'Eve']) + >>> s.between('Anna', 'Daniel') + 0 False + 1 True + 2 True + 3 False + dtype: bool + + See Also + -------- + DataFrame.query : Query the columns of a frame with a boolean + expression. """ if inclusive: lmask = self >= left From 14cd40f8ee237a33f426f99464370c7065ace151 Mon Sep 17 00:00:00 2001 From: Mark Woodbridge <1101318+mrw34@users.noreply.github.com> Date: Sat, 24 Mar 2018 07:57:12 +0000 Subject: [PATCH 2/3] Address PR comments --- pandas/core/series.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 2da47459bcc85..68582a9b4ab06 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3528,11 +3528,19 @@ def between(self, left, right, inclusive=True): Returns ------- - is_between : Series + Series of bool - Examples + Notes + ----- + This function is equivalent to `(left <= series) & (series <= right)` + + See Also -------- + pandas.Series.gt : Greater than of series and other + pandas.Series.lt : Less than of series and other + Examples + -------- >>> s = pd.Series([2, 0, 4, 8, np.nan]) Boundary values are included by default: @@ -3564,11 +3572,6 @@ def between(self, left, right, inclusive=True): 2 True 3 False dtype: bool - - See Also - -------- - DataFrame.query : Query the columns of a frame with a boolean - expression. """ if inclusive: lmask = self >= left From b3c44da25dca7530001f6bd72611b0a899e410cd Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Wed, 28 Mar 2018 11:36:49 -0500 Subject: [PATCH 3/3] Fixup [ci skip] [ci skip] --- pandas/core/series.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 68582a9b4ab06..1348304afafa2 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3528,11 +3528,12 @@ def between(self, left, right, inclusive=True): Returns ------- - Series of bool + Series + Each element will be a boolean. Notes ----- - This function is equivalent to `(left <= series) & (series <= right)` + This function is equivalent to ``(left <= ser) & (ser <= right)`` See Also -------- @@ -3553,7 +3554,7 @@ def between(self, left, right, inclusive=True): 4 False dtype: bool - With `inclusive` set to `False` boundary values are excluded: + With `inclusive` set to ``False`` boundary values are excluded: >>> s.between(1, 4, inclusive=False) 0 True