MCPcopy
hub / github.com/facebook/prophet / construct_holiday_dataframe

Method construct_holiday_dataframe

python/prophet/forecaster.py:513–558  ·  view source on GitHub ↗

Construct a dataframe of holiday dates. Will combine self.holidays with the built-in country holidays corresponding to input dates, if self.country_holidays is set. Parameters ---------- dates: pd.Series containing timestamps used for computing seasonality.

(self, dates)

Source from the content-addressed store, hash-verified

511 return pd.DataFrame(features, columns=columns)
512
513 def construct_holiday_dataframe(self, dates):
514 """Construct a dataframe of holiday dates.
515
516 Will combine self.holidays with the built-in country holidays
517 corresponding to input dates, if self.country_holidays is set.
518
519 Parameters
520 ----------
521 dates: pd.Series containing timestamps used for computing seasonality.
522
523 Returns
524 -------
525 dataframe of holiday dates, in holiday dataframe format used in
526 initialization.
527 """
528 all_holidays = pd.DataFrame()
529 if self.holidays is not None:
530 all_holidays = self.holidays.copy()
531 if self.country_holidays is not None:
532 year_list = list({x.year for x in dates})
533 country_holidays_df = make_holidays_df(
534 year_list=year_list, country=self.country_holidays
535 )
536 all_holidays = pd.concat((all_holidays, country_holidays_df),
537 sort=False)
538 all_holidays.reset_index(drop=True, inplace=True)
539 # Drop future holidays not previously seen in training data
540 if self.train_holiday_names is not None:
541 # Remove holiday names didn't show up in fit
542 index_to_drop = all_holidays.index[
543 np.logical_not(
544 all_holidays.holiday.isin(self.train_holiday_names)
545 )
546 ]
547 all_holidays = all_holidays.drop(index_to_drop)
548 # Add holiday names in fit but not in predict with ds as NA
549 holidays_to_add = pd.DataFrame({
550 'holiday': self.train_holiday_names[
551 np.logical_not(self.train_holiday_names
552 .isin(all_holidays.holiday))
553 ]
554 })
555 all_holidays = pd.concat((all_holidays, holidays_to_add),
556 sort=False)
557 all_holidays.reset_index(drop=True, inplace=True)
558 return all_holidays
559
560 def make_holiday_features(self, dates, holidays):
561 """Construct a dataframe of holiday features.

Calls 1

make_holidays_dfFunction · 0.90

Tested by

no test coverage detected