Skip to content

CLN: PEP8 cleanup of holiday.py #8085

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

Merged
merged 1 commit into from
Aug 22, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 26 additions & 27 deletions pandas/tseries/holiday.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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.

Expand All @@ -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())
Expand All @@ -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
Expand Down