Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def make_holidays_df(year_list, country):
"""Make dataframe of holidays for given years and countries
Parameters
----------
year_list: a list of years
country: country name
Returns
-------
Dataframe with 'ds' and 'holiday', which can directly feed
to 'holidays' params in Prophet
"""
try:
holidays = getattr(hdays_part2, country)(years=year_list)
except AttributeError:
try:
holidays = getattr(hdays_part1, country)(years=year_list)
except AttributeError:
raise AttributeError(
"Holidays in {} are not currently supported!".format(country))
holidays_df = pd.DataFrame(list(holidays.items()), columns=['ds', 'holiday'])
holidays_df.reset_index(inplace=True, drop=True)
holidays_df['ds'] = pd.to_datetime(holidays_df['ds'])
return (holidays_df)
def get_holiday_names(country):
"""Return all possible holiday names of given country
Parameters
----------
country: country name
Returns
-------
A set of all possible holiday names of given country
"""
years = np.arange(1995, 2045)
try:
with warnings.catch_warnings():
warnings.simplefilter("ignore")
holiday_names = getattr(hdays_part2, country)(years=years).values()
except AttributeError:
try:
holiday_names = getattr(hdays_part1, country)(years=years).values()
except AttributeError:
raise AttributeError(
"Holidays in {} are not currently supported!".format(country))
return set(holiday_names)
"""Generate csv file of all possible holiday names, ds,
and countries, year combination
"""
years = np.arange(1995, 2045, 1)
all_holidays = []
# class names in holiday packages which are not countries
class_to_exclude = set(['rd', 'datetime', 'date', 'HolidayBase', 'Calendar',
'LunarDate', 'timedelta', 'date'])
class_list2 = inspect.getmembers(hdays_part2, inspect.isclass)
country_set2 = set(list(zip(*class_list2))[0])
country_set2 -= class_to_exclude
for country in country_set2:
with warnings.catch_warnings():
warnings.simplefilter("ignore")
temp = getattr(hdays_part2, country)(years=years)
temp_df = pd.DataFrame(list(temp.items()),
columns=['ds', 'holiday'])
temp_df['country'] = country
all_holidays.append(temp_df)
class_list1 = inspect.getmembers(hdays_part1, inspect.isclass)
country_set1 = set(list(zip(*class_list1))[0])
country_set1 -= class_to_exclude
# Avoid overwrting holidays get from hdays_part2
country_set1 -= country_set2
for country in country_set1:
temp = getattr(hdays_part1, country)(years=years)
temp_df = pd.DataFrame(list(temp.items()),
columns=['ds', 'holiday'])
temp_df['country'] = country
all_holidays.append(temp_df)
def generate_holidays_file():
"""Generate csv file of all possible holiday names, ds,
and countries, year combination
"""
years = np.arange(1995, 2045, 1)
all_holidays = []
# class names in holiday packages which are not countries
class_to_exclude = set(['rd', 'datetime', 'date', 'HolidayBase', 'Calendar',
'LunarDate', 'timedelta', 'date'])
class_list2 = inspect.getmembers(hdays_part2, inspect.isclass)
country_set2 = set(list(zip(*class_list2))[0])
country_set2 -= class_to_exclude
for country in country_set2:
with warnings.catch_warnings():
warnings.simplefilter("ignore")
temp = getattr(hdays_part2, country)(years=years)
temp_df = pd.DataFrame(list(temp.items()),
columns=['ds', 'holiday'])
temp_df['country'] = country
all_holidays.append(temp_df)
class_list1 = inspect.getmembers(hdays_part1, inspect.isclass)
country_set1 = set(list(zip(*class_list1))[0])
country_set1 -= class_to_exclude
# Avoid overwrting holidays get from hdays_part2
country_set1 -= country_set2