Skip to content

DOC: #38067 add missing holiday observance rules #57939

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
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions doc/source/user_guide/timeseries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1468,11 +1468,16 @@ or some other non-observed day. Defined observance rules are:
:header: "Rule", "Description"
:widths: 15, 70

"next_workday", "move Saturday and Sunday to Monday"
"previous_workday", "move Saturday and Sunday to Friday"
Copy link

@Jeitan Jeitan Mar 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one for 'previous workday' isn't quite right ... it moves to the previous workday even if the input is a weekday, not just for Sat and Sun (as opposed to what previous_friday does)

"nearest_workday", "move Saturday to Friday and Sunday to Monday"
"before_nearest_workday", "apply ``nearest_workday`` and then move to previous workday before that day"
"after_nearest_workday", "apply ``nearest_workday`` and then move to next workday after that day"
"sunday_to_monday", "move Sunday to following Monday"
"next_monday_or_tuesday", "move Saturday to Monday and Sunday/Monday to Tuesday"
"previous_friday", move Saturday and Sunday to previous Friday"
"next_monday", "move Saturday and Sunday to following Monday"
"weekend_to_monday", "same as ``next_monday``"

An example of how holidays and holiday calendars are defined:

Expand Down
6 changes: 3 additions & 3 deletions pandas/tseries/holiday.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def nearest_workday(dt: datetime) -> datetime:

def next_workday(dt: datetime) -> datetime:
"""
returns next weekday used for observances
returns next workday used for observances
"""
dt += timedelta(days=1)
while dt.weekday() > 4:
Expand All @@ -119,7 +119,7 @@ def next_workday(dt: datetime) -> datetime:

def previous_workday(dt: datetime) -> datetime:
"""
returns previous weekday used for observances
returns previous workday used for observances
"""
dt -= timedelta(days=1)
while dt.weekday() > 4:
Expand All @@ -130,7 +130,7 @@ def previous_workday(dt: datetime) -> datetime:

def before_nearest_workday(dt: datetime) -> datetime:
"""
returns previous workday after nearest workday
returns previous workday before nearest workday
"""
return previous_workday(nearest_workday(dt))

Expand Down