-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: incorrectly defined Memoridal Day holiday #9763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Memorial Day was incorrectly defined. It is the last Monday in May, so the earliest it could be is the 25th (not the 24th). This change fixes the problem. >>>from pandas.tseries.holiday import AbstractHolidayCalendar, USMemorialDay >>>class MemorialDayCalendar(AbstractHolidayCalendar):rules=[USMemorialDay] >>>MemorialDayCalendar().holidays('2021','2022') Will now return Timestamp('2021-05-31 00:00:00') instead of Timestamp('2021-05-24 00:00:00')
cc @rockg this is not right either. memorial day as an example is defined as the last monday in may. IIRC you had the ability to define things like that. This is somewhat old (and function/methods different), but how I used to do this:
|
The solution in my pull request is correct. If you would like to verify that it is correct, here is a test for 500 years: from pandas import DataFrame, Timestamp, period_range
from pandas.tseries.holiday import AbstractHolidayCalendar, USMemorialDay, MO, Holiday
from pandas.tseries.offsets import DateOffset
from numpy import logical_and
from datetime import datetime
class MemorialDayCalendar(AbstractHolidayCalendar):
rules=[Holiday('Memorial Day', month=5 , day=25, offset=DateOffset(weekday=MO(1))),]
all_dates = period_range('1700','2200',freq='D')
all_may_mondays = all_dates[logical_and(all_dates.month==5, all_dates.dayofweek==0)]
check_last_monday = DataFrame({'Day':all_may_mondays.day, 'Year':all_may_mondays.year})
last_mondays = check_last_monday.groupby('Year').max()
actual_memorial_days = [datetime(year=year, month=5, day=day)
for year,day in last_mondays.Day.iteritems()]
generated_memorial_days = MemorialDayCalendar().holidays(start='1700',end='2200')\
.to_pydatetime().tolist()
actual_memorial_days == generated_memorial_days Returns True. |
|
@zegres can you update |
@zegres would have been nice to include this, but we need to have a test. |
can you update? |
closing in favor of #10282 |
closes #9760
Memorial Day was incorrectly defined.
It is the last Monday in May, so the earliest it could be is the 25th (not the 24th).
This change fixes the problem.
Will now return Timestamp('2021-05-31 00:00:00') instead of Timestamp('2021-05-24 00:00:00')