Skip to content

BUG: next_workday observance wrongly adds BDay to holidays on weekdays #58553

Open
@yaoyuan12

Description

@yaoyuan12

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions