rsheftel/pandas_market_calendars

importing this package alters the behavior of pandas

erikhansenwong opened this issue · 1 comments

This package modifies the behavior of core pandas features here in pandas_market_calendars/calendars/nyse.py

# Overwrite the default holiday calendar start_date of 1/1/70 
AbstractHolidayCalendar.start_date = '1885-01-01'

There are several other ways this can be handled without changing the behavior of classes in a third party library.

Here is an example of a test which should pass, but which currently fails with v4.3.1

def test_custom_business_day():
    import pandas as pd
    from pandas.tseries.holiday import MO, AbstractHolidayCalendar, Holiday
    from pandas.tseries.offsets import CustomBusinessDay

    USMemorialDay = Holiday(
        "Memorial Day", month=5, day=31, offset=pd.DateOffset(weekday=MO(-1))
    )

    class ExampleCalendar(AbstractHolidayCalendar):
        rules = [USMemorialDay]

    bday1 = CustomBusinessDay(calendar=ExampleCalendar())
    bday2 = CustomBusinessDay(calendar=ExampleCalendar())

    # this assertion passes
    assert bday1 == bday2

    # but then we import pandas_market_calendars and try the same thing ...
    import pandas_market_calendars

    bday3 = CustomBusinessDay(calendar=ExampleCalendar())

    # and now this assertion fails
    assert bday1 == bday3

Do you have specific suggestion on how to modify the code? Can you submit a PR?