Browse Source

Handle holidays with subdaily data

bl 8 years ago
parent
commit
ec497ffba8
2 changed files with 12 additions and 1 deletions
  1. 2 1
      python/fbprophet/forecaster.py
  2. 10 0
      python/fbprophet/tests/test_prophet.py

+ 2 - 1
python/fbprophet/forecaster.py

@@ -311,7 +311,8 @@ class Prophet(object):
         # Holds columns of our future matrix.
         # Holds columns of our future matrix.
         expanded_holidays = defaultdict(lambda: np.zeros(dates.shape[0]))
         expanded_holidays = defaultdict(lambda: np.zeros(dates.shape[0]))
         # Makes an index so we can perform `get_loc` below.
         # 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():
         for _ix, row in self.holidays.iterrows():
             dt = row.ds.date()
             dt = row.ds.date()

+ 10 - 0
python/fbprophet/tests/test_prophet.py

@@ -326,3 +326,13 @@ class TestProphet(TestCase):
         m = Prophet()
         m = Prophet()
         m.fit(DATA)
         m.fit(DATA)
         self.assertNotIn('daily', m.seasonalities)
         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)