Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
from pandas.tseries.holiday import Holiday, AbstractHolidayCalendar, next_workday
class HolidayCalendar(AbstractHolidayCalendar):
rules = [
Holiday('Christmas Day', month=12, day=25, observance=next_workday),
]
print(HolidayCalendar().holidays('2024-01-01', '2024-12-31'))
Issue Description
In the example given, Christmas is defined as next_workday after 25th Dec. 2024-12-25 is a Wed; however the print result returns 2024-12-26. It seems to add 1 business day to 2024 Christmas even though it is a normal weekday.
Expected Behavior
Would expect holidays to return 2024-12-25 for observance=next_workday, since 2024-12-25 is a weekday.
Indeed this is what returns from a manual implementation of next_workday:
import pandas as pd
from pandas.tseries.holiday import Holiday, AbstractHolidayCalendar, next_workday
class HolidayCalendar(AbstractHolidayCalendar):
rules = [
Holiday('Christmas Day', month=12, day=25, observance=lambda d: d + pd.offsets.BDay(1) if d.weekday() >= 5 else d),
]
print(HolidayCalendar().holidays('2024-01-01', '2024-12-31'))
Installed Versions
INSTALLED VERSIONS
commit : bdc79c1
python : 3.11.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.14.0-284.18.1.el9_2.x86_64
machine : x86_64
processor : x86_64
pandas : 2.2.1
numpy : 1.24.4
pytz : 2023.3.post1
dateutil : 2.8.2