mirror of
https://github.com/saymrwulf/prophet.git
synced 2026-07-12 17:57:46 +00:00
Speed up make_holiday_features by up to 35% (#1962)
This commit is contained in:
parent
4d807f60d1
commit
17dbb86ab0
2 changed files with 6 additions and 6 deletions
|
|
@ -534,17 +534,17 @@ class Prophet(object):
|
|||
prior_scales = {}
|
||||
# Makes an index so we can perform `get_loc` below.
|
||||
# Strip to just dates.
|
||||
row_index = pd.DatetimeIndex(dates.apply(lambda x: x.date()))
|
||||
row_index = pd.DatetimeIndex(dates.dt.date)
|
||||
|
||||
for _ix, row in holidays.iterrows():
|
||||
for row in holidays.itertuples():
|
||||
dt = row.ds.date()
|
||||
try:
|
||||
lw = int(row.get('lower_window', 0))
|
||||
uw = int(row.get('upper_window', 0))
|
||||
lw = int(getattr(row, 'lower_window', 0))
|
||||
uw = int(getattr(row, 'upper_window', 0))
|
||||
except ValueError:
|
||||
lw = 0
|
||||
uw = 0
|
||||
ps = float(row.get('prior_scale', self.holidays_prior_scale))
|
||||
ps = float(getattr(row, 'prior_scale', self.holidays_prior_scale))
|
||||
if np.isnan(ps):
|
||||
ps = float(self.holidays_prior_scale)
|
||||
if row.holiday in prior_scales and prior_scales[row.holiday] != ps:
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ def generate_holidays_file():
|
|||
all_holidays.append(df)
|
||||
|
||||
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.dt.year
|
||||
generated_holidays.sort_values(['country', 'ds', 'holiday'], inplace=True)
|
||||
|
||||
# Convert to ASCII, and drop holidays that fail to convert
|
||||
|
|
|
|||
Loading…
Reference in a new issue