Skip to content

Conversation

@edzxy
Copy link

@edzxy edzxy commented Oct 25, 2025

Description

This PR fixes a bug in CustomBusinessDay where the calendar parameter validation was not properly enforced, allowing invalid calendar objects (like pandas_market_calendars objects) to be passed without raising appropriate errors.

Problem

The issue reported that CustomBusinessDay was not properly respecting calendar holiday dates when using pandas_market_calendars. The root cause was that the validation logic in _get_calendar() function was not properly checking for invalid calendar types before attempting to use them.

Solution

Added proper validation in the _get_calendar() function to:

  1. Check if the calendar parameter is a numpy.busdaycalendar instance
  2. Raise a clear TypeError with helpful error message when pandas_market_calendars objects are passed
  3. Provide guidance on the correct usage (passing .holidays() result instead)

Changes Made

  • Enhanced _get_calendar() function in pandas/_libs/tslibs/offsets.pyx to validate calendar parameter type
  • Added specific error handling for pandas_market_calendars objects with clear error message
  • Added test case in test_custom_business_day.py to verify the validation behavior

Testing

  • Added test case test_calendar_validation() to verify proper error handling
  • Existing tests continue to pass
  • All pre-commit checks pass

Impact

This is a bug fix that improves error handling and provides clearer guidance to users about proper calendar usage. It does not change the behavior for valid inputs but provides better error messages for invalid usage patterns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant