-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: #29049 make holiday support offsets of offsets #57938
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
mroeschke
merged 18 commits into
pandas-dev:main
from
dontgoto:#29049_make_holiday_support_offsets_of_offsets
Mar 28, 2024
Merged
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7bee907
support offsets of offsets in holiday creation
dontgoto aaa781f
update whatsnew
dontgoto 0cf929e
add type annotations
dontgoto 8a9a4b6
update type annotation
dontgoto 8e572bb
make types compatible
dontgoto 0548ddf
update docstring
dontgoto a3d44e5
Merge branch 'main' into #29049_make_holiday_support_offsets_of_offsets
dontgoto 98f3d96
Merge branch 'main' into #29049_make_holiday_support_offsets_of_offsets
dontgoto d18187c
Merge branch 'main' into #29049_make_holiday_support_offsets_of_offsets
dontgoto bb6e2b5
Merge branch 'main' into #29049_make_holiday_support_offsets_of_offsets
dontgoto c24b143
don't accept, only raise with more informative exception
dontgoto 8bc29a3
Merge remote-tracking branch 'origin/#29049_make_holiday_support_offs…
dontgoto af3f19e
add attribute type hint
dontgoto a1b9854
change array to list in docstring
dontgoto b80523a
broaden if check; specify error message
dontgoto 6a723f3
Merge remote-tracking branch 'origin/#29049_make_holiday_support_offs…
dontgoto 085a740
update test raises message
dontgoto b779c75
Merge branch 'main' into #29049_make_holiday_support_offsets_of_offsets
dontgoto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,6 +4,10 @@ | |||||||||||||||
datetime, | ||||||||||||||||
timedelta, | ||||||||||||||||
) | ||||||||||||||||
from typing import ( | ||||||||||||||||
TYPE_CHECKING, | ||||||||||||||||
Callable, | ||||||||||||||||
) | ||||||||||||||||
import warnings | ||||||||||||||||
|
||||||||||||||||
from dateutil.relativedelta import ( | ||||||||||||||||
|
@@ -33,6 +37,9 @@ | |||||||||||||||
Easter, | ||||||||||||||||
) | ||||||||||||||||
|
||||||||||||||||
if TYPE_CHECKING: | ||||||||||||||||
from pandas._libs.tslibs.offsets import BaseOffset | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
def next_monday(dt: datetime) -> datetime: | ||||||||||||||||
""" | ||||||||||||||||
|
@@ -149,6 +156,7 @@ class Holiday: | |||||||||||||||
for observance. | ||||||||||||||||
""" | ||||||||||||||||
|
||||||||||||||||
offset: BaseOffset | list[BaseOffset] | None | ||||||||||||||||
start_date: Timestamp | None | ||||||||||||||||
end_date: Timestamp | None | ||||||||||||||||
days_of_week: tuple[int, ...] | None | ||||||||||||||||
|
@@ -159,24 +167,34 @@ def __init__( | |||||||||||||||
year=None, | ||||||||||||||||
month=None, | ||||||||||||||||
day=None, | ||||||||||||||||
offset=None, | ||||||||||||||||
observance=None, | ||||||||||||||||
offset: BaseOffset | list[BaseOffset] | None = None, | ||||||||||||||||
observance: Callable | None = None, | ||||||||||||||||
start_date=None, | ||||||||||||||||
end_date=None, | ||||||||||||||||
days_of_week=None, | ||||||||||||||||
days_of_week: tuple | None = None, | ||||||||||||||||
) -> None: | ||||||||||||||||
""" | ||||||||||||||||
Parameters | ||||||||||||||||
---------- | ||||||||||||||||
name : str | ||||||||||||||||
Name of the holiday , defaults to class name | ||||||||||||||||
year : int, default None | ||||||||||||||||
Year of the holiday | ||||||||||||||||
month : int, default None | ||||||||||||||||
Month of the holiday | ||||||||||||||||
day : int, default None | ||||||||||||||||
Day of the holiday | ||||||||||||||||
offset : array of pandas.tseries.offsets or | ||||||||||||||||
dontgoto marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
class from pandas.tseries.offsets | ||||||||||||||||
computes offset from date | ||||||||||||||||
observance: function | ||||||||||||||||
computes when holiday is given a pandas Timestamp | ||||||||||||||||
days_of_week: | ||||||||||||||||
provide a tuple of days e.g (0,1,2,3,) for Monday Through Thursday | ||||||||||||||||
class from pandas.tseries.offsets, default None | ||||||||||||||||
Computes offset from date | ||||||||||||||||
observance : function, default None | ||||||||||||||||
Computes when holiday is given a pandas Timestamp | ||||||||||||||||
start_date : datetime-like, default None | ||||||||||||||||
First date the holiday is observed | ||||||||||||||||
end_date : datetime-like, default None | ||||||||||||||||
Last date the holiday is observed | ||||||||||||||||
days_of_week : tuple of int or dateutil.relativedelta weekday strs, default None | ||||||||||||||||
Provide a tuple of days e.g (0,1,2,3,) for Monday Through Thursday | ||||||||||||||||
Monday=0,..,Sunday=6 | ||||||||||||||||
|
||||||||||||||||
Examples | ||||||||||||||||
|
@@ -218,6 +236,11 @@ class from pandas.tseries.offsets | |||||||||||||||
""" | ||||||||||||||||
if offset is not None and observance is not None: | ||||||||||||||||
raise NotImplementedError("Cannot use both offset and observance.") | ||||||||||||||||
if isinstance(offset, list) and any(isinstance(off, list) for off in offset): | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
raise ValueError( | ||||||||||||||||
"Nested lists are not supported for offset. " | ||||||||||||||||
"Flatten composite offsets of `Holiday.offset`s first." | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably just say what is allowed for |
||||||||||||||||
) | ||||||||||||||||
|
||||||||||||||||
self.name = name | ||||||||||||||||
self.year = year | ||||||||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't mypy be able to infer this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does. I removed this part.