Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: New boundary inputs #40628

Merged
merged 89 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
89259db
if/else changes test
Mar 19, 2021
eda20a1
Series.between changes to inclusive boundaries
Mar 21, 2021
7af55a7
changes to date_range parameters
Mar 24, 2021
85a33cc
Changed series.between error handling to throw value error instead of…
Mar 24, 2021
c87e240
changes to series.between documentation and error message
Mar 24, 2021
4ebfa59
parameters as either booleans or strings
Mar 25, 2021
ad3670e
full range of options in documentation
Mar 25, 2021
1dc37b1
Order of parameters in documentation
Mar 25, 2021
d3f6a56
changes to if statement format
Mar 25, 2021
70fb076
Corrections to line length linting errors in ValueError messages
Mar 25, 2021
3382a7e
Format of ValueError statements
Mar 25, 2021
f693b90
Format of spaces in ValueError statements
Mar 25, 2021
895b20a
Delete Pipfile
hewittk Mar 25, 2021
d35263c
Delete Pipfile.lock
hewittk Mar 25, 2021
13648d2
parameters for standard values and backwards compatibility
Mar 26, 2021
5ec615e
Merge branch 'new-boundary-inputs' of github.com:hewittk/pandas into …
Mar 26, 2021
b924926
ENH: parameters for standard values and backwards compatibility
Mar 26, 2021
42e4209
ENH: corrections about parameter arguments in method docstrings
Mar 26, 2021
1570eb6
add passing test case for test_between.py
declanjcasey Mar 26, 2021
3edd556
Merge branch 'new-boundary-inputs' of github.com:hewittk/pandas into …
declanjcasey Mar 26, 2021
b524523
ENH: corrections to placements of both/neither in datetime if/else st…
Mar 26, 2021
20cfeed
Merge branch 'new-boundary-inputs' of github.com:hewittk/pandas into …
Mar 26, 2021
991b238
ENH: reformatting of series ValueError message
Mar 26, 2021
6009878
add asset statemente to new method test_between_inclusive_is_boolean_…
declanjcasey Mar 26, 2021
9e16ecd
Merge branch 'new-boundary-inputs' of github.com:hewittk/pandas into …
declanjcasey Mar 26, 2021
944c28a
ENH: changed default parameter of inclusive to string
Mar 26, 2021
e0f9ef6
Merge branch 'new-boundary-inputs' of github.com:hewittk/pandas into …
Mar 26, 2021
9dced10
add macth variable for pytest.raises()
declanjcasey Mar 26, 2021
af62054
Merge branch 'new-boundary-inputs' of github.com:hewittk/pandas into …
declanjcasey Mar 26, 2021
8a79155
edit variable declration in test_between_inclusive_is_boolean_string()
declanjcasey Mar 26, 2021
d9a4130
ENH: Correction to closed argument documentation formatting
Mar 26, 2021
062c58b
ENH: whatsnew message about issue enhancements
Mar 26, 2021
bed87e3
reformat for black
declanjcasey Mar 26, 2021
651f717
Merge branch 'new-boundary-inputs' of github.com:hewittk/pandas into …
declanjcasey Mar 26, 2021
86a8961
ENH: whatsnew message about issue enhancements
Mar 26, 2021
7d77a0a
Merge branch 'new-boundary-inputs' of github.com:hewittk/pandas into …
Mar 26, 2021
3f04091
Improved formatting of whatsnew message
Mar 26, 2021
163a08c
Code block in whatsnew message
Mar 26, 2021
8240763
Formatting on whatsnew issue
Mar 26, 2021
9f7da88
Merge branch 'master' into new-boundary-inputs
hewittk Mar 26, 2021
d62bcc3
Documentation representing standard and backwards compatibility bound…
Mar 26, 2021
5745731
Merge branch 'new-boundary-inputs' of github.com:hewittk/pandas into …
Mar 26, 2021
9761c21
Reformatting of relevant addition and removal of unnecessary additions
Mar 26, 2021
2f35f81
Update pandas/core/arrays/datetimelike.py
hewittk Mar 26, 2021
10d5594
Revert validate_endpoints
May 3, 2021
1c7a17d
Revert whatsnew to include all previous entries on branch
May 4, 2021
e03ed0d
Move whatsnew entry to deprecation section
May 4, 2021
1ae01cb
Reorganize inclusive arg documentation and add version changed
May 4, 2021
171e212
Test cases for all provided arguments
May 4, 2021
ef9350f
ValueError test case
May 4, 2021
873e669
Remove redundant line
May 4, 2021
8104413
Add issue number to added test
May 4, 2021
a9380c5
Revert username in Dockerfile
May 4, 2021
0c974ca
Revert remaining changes to validate_endpoints
hewittk May 4, 2021
0da4509
Fully revert to original validate_endpoints
hewittk May 4, 2021
17317f7
Merge branch 'master' into new-boundary-inputs
hewittk May 9, 2021
0056f82
Remove validate_periods
hewittk Jun 3, 2021
a34ae5e
Update pandas/core/series.py ValueError message
hewittk Jun 3, 2021
8279545
Separate handling of individual inclusive parameters
hewittk Jun 3, 2021
2aed02f
Deprecate parameter description in inclusive
hewittk Jun 3, 2021
88e6de8
Merge branch 'new-boundary-inputs' of github.com:hewittk/pandas into …
hewittk Jun 3, 2021
e8ba805
Black reformatting
hewittk Jun 7, 2021
83d79f1
Split up line too long
hewittk Jun 7, 2021
c2399cc
Add FutureWarning for inclusive is true
hewittk Jun 7, 2021
842aaf7
Black reformatting
hewittk Jun 7, 2021
8d68363
Add FutureWarning test case
hewittk Jun 7, 2021
b4dc979
Between inclusive warning test
hewittk Jun 7, 2021
ee59447
Merge branch 'master' into new-boundary-inputs
hewittk Jun 7, 2021
6564c4d
Move inclusive tests
hewittk Jun 9, 2021
c017ab1
Merge branch 'new-boundary-inputs' of github.com:hewittk/pandas into …
hewittk Jun 9, 2021
3321e57
Rename test_between_inclusive_is_boolean_string
hewittk Jun 9, 2021
697a5e9
Handle boolean statements separately first
hewittk Jun 9, 2021
98b6c8d
Add code backtics
hewittk Jun 9, 2021
30fbf0b
Merge branch 'pandas-dev:master' into new-boundary-inputs
hewittk Jun 9, 2021
2465b31
Merge branch 'pandas-dev:master' into new-boundary-inputs
hewittk Jun 10, 2021
f57abf1
Remove depracation sentence from docstring
hewittk Jun 13, 2021
b1a600b
Merge branch 'new-boundary-inputs' of github.com:hewittk/pandas into …
hewittk Jun 13, 2021
13e2b6a
Add issue number to whatsnew
hewittk Jun 17, 2021
eb49358
Merge branch 'master' into new-boundary-inputs
hewittk Jun 17, 2021
f11a078
Revert whatsnew to main
hewittk Jun 19, 2021
9508c15
Readd entry to enhancements
hewittk Jun 19, 2021
10a609c
Readd entry to deprecations
hewittk Jun 19, 2021
238bd1d
Remove extraneous lines
hewittk Jun 19, 2021
575a4ce
Merge branch 'master' into new-boundary-inputs
hewittk Jun 21, 2021
b92bbda
Update v1.3.0.rst
hewittk Jun 21, 2021
7911883
Remove double line from docstring
hewittk Jun 24, 2021
f6f7c4a
Merge branch 'pandas-dev:master' into new-boundary-inputs
hewittk Jun 24, 2021
733b5b2
Change inclusive argument in test suite
hewittk Jun 25, 2021
869850b
Merge branch 'new-boundary-inputs' of github.com:hewittk/pandas into …
hewittk Jun 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM quay.io/condaforge/miniforge3

# if you forked pandas, you can pass in your own GitHub username to use your fork
# i.e. gh_username=myname
ARG gh_username=pandas-dev
ARG gh_username=hewittk
hewittk marked this conversation as resolved.
Show resolved Hide resolved
ARG pandas_home="/home/pandas"

# Avoid warnings by switching to noninteractive
Expand Down
4 changes: 4 additions & 0 deletions doc/source/whatsnew/v1.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ Other enhancements
- :meth:`pandas.read_stata` and :class:`StataReader` support reading data from compressed files.
- Add support for parsing ``ISO 8601``-like timestamps with negative signs to :meth:`pandas.Timedelta` (:issue:`37172`)
- Add support for unary operators in :class:`FloatingArray` (:issue:`38749`)
- :class:`RangeIndex` can now be constructed by passing a ``range`` object directly e.g. ``pd.RangeIndex(range(3))`` (:issue:`12067`)
- :meth:`round` being enabled for the nullable integer and floating dtypes (:issue:`38844`)
- :meth:`pandas.read_csv` and :meth:`pandas.read_json` expose the argument ``encoding_errors`` to control how encoding errors are handled (:issue:`39450`)
hewittk marked this conversation as resolved.
Show resolved Hide resolved
- Add consistency of arguments in `series.between` and `datetimelike.validate_endpoints` to have ``["left", "right", "neither", "both"]` as standard argument values for both methods (:issue:`40628`)
hewittk marked this conversation as resolved.
Show resolved Hide resolved

.. ---------------------------------------------------------------------------

Expand Down
16 changes: 11 additions & 5 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1812,11 +1812,12 @@ def validate_periods(periods):

def validate_endpoints(closed):
"""
Check that the `closed` argument is among [None, "left", "right"]
Check that the `closed` argument is among ["neither", "left", "right",
None, or backwards compatibility argument of True, False, or None]
hewittk marked this conversation as resolved.
Show resolved Hide resolved

Parameters
----------
closed : {None, "left", "right"}
closed : {"neither", "left", "right", "both"}

Returns
-------
Expand All @@ -1830,16 +1831,21 @@ def validate_endpoints(closed):
left_closed = False
right_closed = False

if closed is None:
if closed == "both" or closed is True or closed is None:
hewittk marked this conversation as resolved.
Show resolved Hide resolved
left_closed = True
right_closed = True
elif closed == "left":
left_closed = True
elif closed == "right":
right_closed = True
elif closed == "neither" or closed is False:
left_closed = False
right_closed = False
else:
raise ValueError("Closed has to be either 'left', 'right' or None")

raise ValueError(
"Closed has to be either 'left', 'right', 'neither', 'both' or "
"None, or a boolean value"
)
return left_closed, right_closed


Expand Down
21 changes: 17 additions & 4 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4670,7 +4670,7 @@ def isin(self, values) -> Series:
self, method="isin"
)

def between(self, left, right, inclusive=True) -> Series:
def between(self, left, right, inclusive="both") -> Series:
"""
Return boolean Series equivalent to left <= series <= right.

Expand All @@ -4684,7 +4684,8 @@ def between(self, left, right, inclusive=True) -> Series:
Left boundary.
right : scalar or list-like
Right boundary.
inclusive : bool, default True
inclusive : str or boolean, default "both"

hewittk marked this conversation as resolved.
Show resolved Hide resolved
Include boundaries.

Returns
Expand Down Expand Up @@ -4736,12 +4737,24 @@ def between(self, left, right, inclusive=True) -> Series:
3 False
dtype: bool
"""
if inclusive:

if inclusive == "both" or inclusive is True:
hewittk marked this conversation as resolved.
Show resolved Hide resolved
lmask = self >= left
rmask = self <= right
else:
elif inclusive == "left":
lmask = self >= left
rmask = self < right
elif inclusive == "right":
lmask = self > left
rmask = self <= right
elif inclusive == "neither" or inclusive is False:
lmask = self > left
rmask = self < right
hewittk marked this conversation as resolved.
Show resolved Hide resolved
else:
raise ValueError(
hewittk marked this conversation as resolved.
Show resolved Hide resolved
"Inclusive has to be either string of 'both','left', 'right', "
"or 'neither', or a boolean value"
hewittk marked this conversation as resolved.
Show resolved Hide resolved
)

return lmask & rmask

Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/series/methods/test_between.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import pytest

from pandas import (
Series,
Expand Down Expand Up @@ -38,3 +39,12 @@ def test_between_period_values(self):
result = ser.between(left, right)
expected = (ser >= left) & (ser <= right)
tm.assert_series_equal(result, expected)

def test_between_inclusive_is_boolean_string(self):
hewittk marked this conversation as resolved.
Show resolved Hide resolved
msg_1 = "Inclusive has to be either string of 'both','left', "
msg_2 = "'right', or 'neither', or a boolean value"
msg = msg_1 + msg_2
hewittk marked this conversation as resolved.
Show resolved Hide resolved
with pytest.raises(ValueError, match=msg):
ser = Series(period_range("2000-01-01", periods=10, freq="D"))
left, right = ser[[2, 7]]
assert ser.between(left, right, 8)