Skip to content

Commit

Permalink
DOC: pandas-dev#38067 add missing holiday observance rules (pandas-de…
Browse files Browse the repository at this point in the history
…v#57939)

* fix method docstrings

* add observances to user guide

* add weekend_to_monday to user guide
  • Loading branch information
dontgoto authored and pmhatre1 committed May 7, 2024
1 parent 1705016 commit af8f8f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
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"
"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

0 comments on commit af8f8f8

Please sign in to comment.