make_holidays.py (prophet-1.1) | : | make_holidays.py (prophet-1.1.1) | ||
---|---|---|---|---|
skipping to change at line 37 | skipping to change at line 37 | |||
""" | """ | |||
years = np.arange(1995, 2045) | years = np.arange(1995, 2045) | |||
try: | try: | |||
with warnings.catch_warnings(): | with warnings.catch_warnings(): | |||
warnings.simplefilter("ignore") | warnings.simplefilter("ignore") | |||
holiday_names = getattr(hdays_part2, country)(years=years).values() | holiday_names = getattr(hdays_part2, country)(years=years).values() | |||
except AttributeError: | except AttributeError: | |||
try: | try: | |||
holiday_names = getattr(hdays_part1, country)(years=years).values() | holiday_names = getattr(hdays_part1, country)(years=years).values() | |||
except AttributeError as e: | except AttributeError as e: | |||
raise AttributeError( | raise AttributeError(f"Holidays in {country} are not currently suppo | |||
"Holidays in {} are not currently supported!".format(country)) f | rted!") from e | |||
rom e | ||||
return set(holiday_names) | return set(holiday_names) | |||
def make_holidays_df(year_list, country, province=None, state=None): | def make_holidays_df(year_list, country, province=None, state=None): | |||
"""Make dataframe of holidays for given years and countries | """Make dataframe of holidays for given years and countries | |||
Parameters | Parameters | |||
---------- | ---------- | |||
year_list: a list of years | year_list: a list of years | |||
country: country name | country: country name | |||
skipping to change at line 60 | skipping to change at line 60 | |||
------- | ------- | |||
Dataframe with 'ds' and 'holiday', which can directly feed | Dataframe with 'ds' and 'holiday', which can directly feed | |||
to 'holidays' params in Prophet | to 'holidays' params in Prophet | |||
""" | """ | |||
try: | try: | |||
holidays = getattr(hdays_part2, country)(years=year_list, expand=False) | holidays = getattr(hdays_part2, country)(years=year_list, expand=False) | |||
except AttributeError: | except AttributeError: | |||
try: | try: | |||
holidays = getattr(hdays_part1, country)(prov=province, state=state, years=year_list, expand=False) | holidays = getattr(hdays_part1, country)(prov=province, state=state, years=year_list, expand=False) | |||
except AttributeError as e: | except AttributeError as e: | |||
raise AttributeError( | raise AttributeError(f"Holidays in {country} are not currently suppo | |||
"Holidays in {} are not currently supported!".format(country)) f | rted!") from e | |||
rom e | ||||
holidays_df = pd.DataFrame([(date, holidays.get_list(date)) for date in holi days], columns=['ds', 'holiday']) | holidays_df = pd.DataFrame([(date, holidays.get_list(date)) for date in holi days], columns=['ds', 'holiday']) | |||
holidays_df = holidays_df.explode('holiday') | holidays_df = holidays_df.explode('holiday') | |||
holidays_df.reset_index(inplace=True, drop=True) | holidays_df.reset_index(inplace=True, drop=True) | |||
holidays_df['ds'] = pd.to_datetime(holidays_df['ds']) | holidays_df['ds'] = pd.to_datetime(holidays_df['ds']) | |||
return (holidays_df) | return (holidays_df) | |||
End of changes. 2 change blocks. | ||||
6 lines changed or deleted | 6 lines changed or added |