mirror of
https://github.com/saymrwulf/prophet.git
synced 2026-11-19 09:00:59 +00:00
Clean up script for R holidays, and regenerate
This commit is contained in:
parent
3d0bb6e081
commit
2061f251f8
4 changed files with 5751 additions and 56048 deletions
|
|
@ -7,4 +7,4 @@
|
||||||
|
|
||||||
|
|
||||||
generated_holidays <- read.csv("data-raw/generated_holidays.csv")
|
generated_holidays <- read.csv("data-raw/generated_holidays.csv")
|
||||||
devtools::use_data(generated_holidays, overwrite = TRUE)
|
usethis::use_data(generated_holidays, overwrite = TRUE)
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
Binary file not shown.
|
|
@ -17,6 +17,7 @@ import numpy as np
|
||||||
|
|
||||||
import holidays as hdays_part1
|
import holidays as hdays_part1
|
||||||
import fbprophet.hdays as hdays_part2
|
import fbprophet.hdays as hdays_part2
|
||||||
|
from fbprophet.make_holidays import make_holidays_df
|
||||||
|
|
||||||
|
|
||||||
def utf8_to_ascii(text):
|
def utf8_to_ascii(text):
|
||||||
|
|
@ -41,39 +42,23 @@ def generate_holidays_file():
|
||||||
"""Generate csv file of all possible holiday names, ds,
|
"""Generate csv file of all possible holiday names, ds,
|
||||||
and countries, year combination
|
and countries, year combination
|
||||||
"""
|
"""
|
||||||
years = np.arange(1995, 2045, 1)
|
year_list = np.arange(1995, 2045, 1).tolist()
|
||||||
all_holidays = []
|
all_holidays = []
|
||||||
# class names in holiday packages which are not countries
|
# class names in holiday packages which are not countries
|
||||||
# Also cut out countries with utf-8 holidays that don't parse to ascii
|
# Also cut out countries with utf-8 holidays that don't parse to ascii
|
||||||
class_to_exclude = set([
|
class_to_exclude = set(['rd', 'BY', 'BG', 'JP', 'RS', 'UA', 'KR'])
|
||||||
'rd', 'date', 'Lunar', 'timedelta', 'Calendar', 'Converter', 'HolidayBase',
|
|
||||||
'DateNotExist', 'Belarus', 'BY', 'Bulgaria', 'BG', 'Japan', 'JP', 'Serbia',
|
|
||||||
'RS', 'Ukraine', 'UA',
|
|
||||||
])
|
|
||||||
|
|
||||||
class_list2 = inspect.getmembers(hdays_part2, inspect.isclass)
|
class_list2 = inspect.getmembers(hdays_part2, inspect.isclass)
|
||||||
country_set2 = set(list(zip(*class_list2))[0])
|
country_set = set([name for name in list(zip(*class_list2))[0] if len(name) == 2])
|
||||||
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)
|
class_list1 = inspect.getmembers(hdays_part1, inspect.isclass)
|
||||||
country_set1 = set(list(zip(*class_list1))[0])
|
country_set1 = set([name for name in list(zip(*class_list1))[0] if len(name) == 2])
|
||||||
country_set1 -= class_to_exclude
|
country_set.update(country_set1)
|
||||||
# Avoid overwrting holidays get from hdays_part2
|
country_set -= class_to_exclude
|
||||||
country_set1 -= country_set2
|
|
||||||
for country in country_set1:
|
for country in country_set:
|
||||||
temp = getattr(hdays_part1, country)(years=years)
|
df = make_holidays_df(year_list=year_list, country=country)
|
||||||
temp_df = pd.DataFrame(list(temp.items()),
|
df['country'] = country
|
||||||
columns=['ds', 'holiday'])
|
all_holidays.append(df)
|
||||||
temp_df['country'] = country
|
|
||||||
all_holidays.append(temp_df)
|
|
||||||
|
|
||||||
generated_holidays = pd.concat(all_holidays, axis=0, ignore_index=True)
|
generated_holidays = pd.concat(all_holidays, axis=0, ignore_index=True)
|
||||||
generated_holidays['year'] = generated_holidays.ds.apply(lambda x: x.year)
|
generated_holidays['year'] = generated_holidays.ds.apply(lambda x: x.year)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue