fix for comma-separated holidays (#1638)

* use holidays.get_list() to return list of holidays

* make_holidays_df now accepts states
This commit is contained in:
Greg Rafferty 2020-08-27 17:49:19 -07:00 committed by GitHub
parent e992e0b7b6
commit 3d0bb6e081
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -40,7 +40,7 @@ def get_holiday_names(country):
return set(holiday_names)
def make_holidays_df(year_list, country, province=None):
def make_holidays_df(year_list, country, province=None, state=None):
"""Make dataframe of holidays for given years and countries
Parameters
@ -57,11 +57,12 @@ def make_holidays_df(year_list, country, province=None):
holidays = getattr(hdays_part2, country)(years=year_list)
except AttributeError:
try:
holidays = getattr(hdays_part1, country)(prov=province,years=year_list)
holidays = getattr(hdays_part1, country)(prov=province, state=state, years=year_list)
except AttributeError as e:
raise AttributeError(
"Holidays in {} are not currently supported!".format(country)) from e
holidays_df = pd.DataFrame(list(holidays.items()), columns=['ds', 'holiday'])
holidays_df = pd.DataFrame([(date, holidays.get_list(date)) for date in holidays], columns=['ds', 'holiday'])
holidays_df = holidays_df.explode('holiday')
holidays_df.reset_index(inplace=True, drop=True)
holidays_df['ds'] = pd.to_datetime(holidays_df['ds'])
return (holidays_df)