Created
January 15, 2019 21:35
-
-
Save ianepreston/83755e6b7740e4a5c2b5302e5c28608c to your computer and use it in GitHub Desktop.
Pandas holiday calendar for Alberta
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Define holidays | |
""" | |
from pandas.tseries.holiday import ( | |
AbstractHolidayCalendar, DateOffset, EasterMonday, GoodFriday, Holiday, MO, | |
next_monday, next_monday_or_tuesday | |
) | |
class AlbertaHolidayCalendar(AbstractHolidayCalendar): | |
""" | |
Uses the pandas AbstractHolidayCalendar class to create a class for | |
Alberta holidays: | |
Adjusts for observance date if set holidays fall on weekends | |
New years - Jan 1 | |
Family Day - 3rd Monday in February | |
Good Friday | |
Easter Monday | |
Victoria Day - Last Monday before May 25 | |
Canada Day - July 1 | |
Heritage Day - August 1 | |
Labour Day - September 1 | |
Thanksgiving - Second Monday in October | |
Remembrance Day - November 11 | |
Christmas Day - December 25 | |
Boxing Day - December 26 | |
See Pandas documentation for more information on holiday calendars | |
http://pandas.pydata.org/pandas-docs/stable/timeseries.html#holidays-holiday-calendars | |
Some sample code is here: | |
http://mapleoin.github.io/perma/python-uk-business-days | |
http://stackoverflow.com/documentation/pandas/7976/holiday-calendars#t=201703131711384942824 | |
""" | |
rules = [ | |
Holiday('New Years Day', month=1, day=1, observance=next_monday), | |
Holiday('Family Day', | |
month=2, day=1, offset=DateOffset(weekday=MO(3))), | |
GoodFriday, | |
EasterMonday, | |
Holiday('Victoria Day', | |
month=5, day=25, offset=DateOffset(weekday=MO(-1))), | |
Holiday('Canada Day', month=7, day=1, observance=next_monday), | |
Holiday('Heritage Day', | |
month=8, day=1, offset=DateOffset(weekday=MO(1))), | |
Holiday('Labour Day', | |
month=9, day=1, offset=DateOffset(weekday=MO(1))), | |
Holiday('Thanksgiving', | |
month=10, day=1, offset=DateOffset(weekday=MO(2))), | |
Holiday('Remembrance Day', | |
month=11, day=11, observance=next_monday), | |
Holiday('Christmas Day', month=12, day=25, observance=next_monday), | |
Holiday('Boxing Day', | |
month=12, day=26, observance=next_monday_or_tuesday) | |
] | |
# ab_holiday_calendar = AlbertaHolidayCalendar() | |
# ab_holiday_calendar.holidays(start=date(2016, 1, 1), end=date(2017, 12, 31)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment