Skip to content

ENH: consistency of input args for boundaries (pd.date_range) #43504

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

Merged
merged 10 commits into from
Oct 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
to use validate_inclusive in util
  • Loading branch information
zyc09 committed Sep 14, 2021
commit 05def2263b0f98cc01924f7d3ac861bda02a4ce7
65 changes: 0 additions & 65 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1823,71 +1823,6 @@ def validate_periods(periods):
return periods


def validate_inclusiveness(inclusive):
"""
Check that the `inclusive` argument is among {"both", "neither", "left", "right"}.

Parameters
----------
inclusive : {"both", "neither", "left", "right"}

Returns
-------
left_inclusive : bool
right_inclusive : bool

Raises
------
ValueError : if argument is not among valid values
"""
left_right_inclusive: tuple[bool, bool] | None = {
"both": (True, True),
"left": (True, False),
"right": (False, True),
"neither": (False, False),
}.get(inclusive)

if left_right_inclusive is None:
raise ValueError(
"Inclusive has to be either 'both', 'neither', 'left', 'right'"
)
left_inclusive, right_inclusive = left_right_inclusive
return left_inclusive, right_inclusive


def validate_endpoints(closed):
"""
Check that the `closed` argument is among [None, "left", "right"]

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

Returns
-------
left_closed : bool
right_closed : bool

Raises
------
ValueError : if argument is not among valid values
"""
left_closed = False
right_closed = False

if closed is None:
left_closed = True
right_closed = True
elif closed == "left":
left_closed = True
elif closed == "right":
right_closed = True
else:
raise ValueError("Closed has to be either 'left', 'right' or None")

return left_closed, right_closed


def validate_inferred_freq(freq, inferred_freq, freq_infer):
"""
If the user passes a freq and another freq is inferred from passed data,
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
)
from pandas._typing import npt
from pandas.errors import PerformanceWarning
from pandas.util._validators import validate_endpoints
from pandas.util._validators import validate_inclusive

from pandas.core.dtypes.cast import astype_dt64_to_dt64tz
from pandas.core.dtypes.common import (
Expand Down Expand Up @@ -417,7 +417,7 @@ def _generate_range(
if start is NaT or end is NaT:
raise ValueError("Neither `start` nor `end` can be NaT")

left_inclusive, right_inclusive = dtl.validate_inclusiveness(inclusive)
left_inclusive, right_inclusive = validate_inclusive(inclusive)
start, end, _normalized = _maybe_normalize_endpoints(start, end, normalize)
tz = _infer_tz_from_endpoints(start, end, tz)

Expand Down