From ec497ffba8574a0670306001aaa7c168cb1a6d54 Mon Sep 17 00:00:00 2001 From: bl Date: Tue, 4 Jul 2017 20:32:42 -0700 Subject: [PATCH] Handle holidays with subdaily data --- python/fbprophet/forecaster.py | 3 ++- python/fbprophet/tests/test_prophet.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/python/fbprophet/forecaster.py b/python/fbprophet/forecaster.py index 154be29..3fbb696 100644 --- a/python/fbprophet/forecaster.py +++ b/python/fbprophet/forecaster.py @@ -311,7 +311,8 @@ class Prophet(object): # Holds columns of our future matrix. expanded_holidays = defaultdict(lambda: np.zeros(dates.shape[0])) # Makes an index so we can perform `get_loc` below. - row_index = pd.DatetimeIndex(dates) + # Strip to just dates. + row_index = pd.DatetimeIndex(dates.apply(lambda x:x.date())) for _ix, row in self.holidays.iterrows(): dt = row.ds.date() diff --git a/python/fbprophet/tests/test_prophet.py b/python/fbprophet/tests/test_prophet.py index 879e6fc..6d15efe 100644 --- a/python/fbprophet/tests/test_prophet.py +++ b/python/fbprophet/tests/test_prophet.py @@ -326,3 +326,13 @@ class TestProphet(TestCase): m = Prophet() m.fit(DATA) self.assertNotIn('daily', m.seasonalities) + + def test_subdaily_holidays(self): + holidays = pd.DataFrame({ + 'ds': pd.to_datetime(['2017-01-02']), + 'holiday': ['new_years'], + }) + m = Prophet(holidays=holidays) + m.fit(DATA2) + fcst = m.predict() + self.assertEqual(sum(fcst['new_years'] == 0), 575)