diff --git a/pandas/tseries/holiday.py b/pandas/tseries/holiday.py index ea85f35cd4ca2..3b3542b760d6f 100644 --- a/pandas/tseries/holiday.py +++ b/pandas/tseries/holiday.py @@ -129,10 +129,10 @@ class from pandas.tseries.offsets computes offset from date observance: function computes when holiday is given a pandas Timestamp - days_of_week: + days_of_week: provide a tuple of days e.g (0,1,2,3,) for Monday Through Thursday Monday=0,..,Sunday=6 - + Examples -------- >>> from pandas.tseries.holiday import Holiday, nearest_workday @@ -148,13 +148,13 @@ class from pandas.tseries.offsets >>> July3rd = Holiday('July 3rd', month=7, day=3, days_of_week=(0, 1, 2, 3)) """ - self.name = name - self.year = year - self.month = month - self.day = day - self.offset = offset + self.name = name + self.year = year + self.month = month + self.day = day + self.offset = offset self.start_date = start_date - self.end_date = end_date + self.end_date = end_date self.observance = observance assert (days_of_week is None or type(days_of_week) == tuple) self.days_of_week = days_of_week @@ -200,14 +200,14 @@ def dates(self, start_date, end_date, return_name=False): end_date = self.end_date start_date = Timestamp(start_date) - end_date = Timestamp(end_date) + end_date = Timestamp(end_date) year_offset = DateOffset(years=1) base_date = Timestamp(datetime(start_date.year, self.month, self.day)) dates = DatetimeIndex(start=base_date, end=end_date, freq=year_offset) holiday_dates = self._apply_rule(dates) if self.days_of_week is not None: - holiday_dates = list(filter(lambda x: x is not None and + holiday_dates = list(filter(lambda x: x is not None and x.dayofweek in self.days_of_week, holiday_dates)) else: @@ -235,9 +235,9 @@ def _apply_rule(self, dates): if self.offset is not None: if not isinstance(self.offset, list): - offsets = [self.offset] + offsets = [self.offset] else: - offsets = self.offset + offsets = self.offset for offset in offsets: dates = list(map(lambda d: d + offset, dates)) return dates @@ -275,7 +275,7 @@ class AbstractHolidayCalendar(object): __metaclass__ = HolidayCalendarMetaClass rules = [] start_date = Timestamp(datetime(1970, 1, 1)) - end_date = Timestamp(datetime(2030, 12, 31)) + end_date = Timestamp(datetime(2030, 12, 31)) _holiday_cache = None def __init__(self, name=None, rules=None): @@ -315,7 +315,7 @@ def holidays(self, start=None, end=None, return_name=False): DatetimeIndex of holidays """ if self.rules is None: - raise Exception('Holiday Calendar %s does not have any '\ + raise Exception('Holiday Calendar %s does not have any ' 'rules specified' % self.name) if start is None: @@ -325,7 +325,7 @@ def holidays(self, start=None, end=None, return_name=False): end = AbstractHolidayCalendar.end_date start = Timestamp(start) - end = Timestamp(end) + end = Timestamp(end) holidays = None # If we don't have a cache or the dates are outside the prior cache, we get them again @@ -359,7 +359,7 @@ def _cache(self, values): @staticmethod def merge_class(base, other): """ - Merge holiday calendars together. The base calendar + Merge holiday calendars together. The base calendar will take precedence to other. The merge will be done based on each holiday's name. @@ -384,7 +384,7 @@ def merge_class(base, other): if not isinstance(base, list): base = [base] - base_holidays = dict([ (holiday.name,holiday) for holiday in base ]) + base_holidays = dict([(holiday.name, holiday) for holiday in base]) other_holidays.update(base_holidays) return list(other_holidays.values()) @@ -401,30 +401,29 @@ def merge(self, other, inplace=False): inplace : bool (default=False) If True set rule_table to holidays, else return array of Holidays """ - holidays = self.merge_class(self, other) + holidays = self.merge_class(self, other) if inplace: self.rules = holidays else: return holidays -USMemorialDay = Holiday('MemorialDay', month=5, day=24, - offset=DateOffset(weekday=MO(1))) -USLaborDay = Holiday('Labor Day', month=9, day=1, - offset=DateOffset(weekday=MO(1))) -USColumbusDay = Holiday('Columbus Day', month=10, day=1, - offset=DateOffset(weekday=MO(2))) +USMemorialDay = Holiday('MemorialDay', month=5, day=24, + offset=DateOffset(weekday=MO(1))) +USLaborDay = Holiday('Labor Day', month=9, day=1, + offset=DateOffset(weekday=MO(1))) +USColumbusDay = Holiday('Columbus Day', month=10, day=1, + offset=DateOffset(weekday=MO(2))) USThanksgivingDay = Holiday('Thanksgiving', month=11, day=1, offset=DateOffset(weekday=TH(4))) USMartinLutherKingJr = Holiday('Dr. Martin Luther King Jr.', month=1, day=1, offset=DateOffset(weekday=MO(3))) -USPresidentsDay = Holiday('President''s Day', month=2, day=1, - offset=DateOffset(weekday=MO(3))) +USPresidentsDay = Holiday('President''s Day', month=2, day=1, + offset=DateOffset(weekday=MO(3))) GoodFriday = Holiday("Good Friday", month=1, day=1, offset=[Easter(), Day(-2)]) EasterMonday = Holiday("Easter Monday", month=1, day=1, offset=[Easter(), Day(1)]) - class USFederalHolidayCalendar(AbstractHolidayCalendar): """ US Federal Government Holiday Calendar based on rules specified