Browse Source

Bugfix for add_seasonality

bl 8 years ago
parent
commit
b07d345155

+ 3 - 1
R/tests/testthat/test_prophet.R

@@ -263,7 +263,9 @@ test_that("auto_yearly_seasonality", {
 
 test_that("custom_seasonality", {
   skip_if_not(Sys.getenv('R_ARCH') != '/i386')
-  m <- prophet()
+  holidays <- data.frame(ds = zoo::as.Date(c('2017-01-02')),
+                         holiday = c('special_day'))
+  m <- prophet(holidays=holidays)
   m <- add_seasonality(m, name='monthly', period=30, fourier.order=5)
   expect_equal(m$seasonalities[['monthly']], c(30, 5))
 })

+ 1 - 1
python/fbprophet/forecaster.py

@@ -357,7 +357,7 @@ class Prophet(object):
         fourier_order: int number of Fourier components to use.
         """
         if self.holidays is not None:
-            if name in set(holidays['holiday']):
+            if name in set(self.holidays['holiday']):
                 raise ValueError(
                     'Name "{}" already used for holiday'.format(name))
         self.seasonalities[name] = (period, fourier_order)

+ 7 - 3
python/fbprophet/tests/test_prophet.py

@@ -330,14 +330,18 @@ class TestProphet(TestCase):
     def test_subdaily_holidays(self):
         holidays = pd.DataFrame({
             'ds': pd.to_datetime(['2017-01-02']),
-            'holiday': ['new_years'],
+            'holiday': ['special_day'],
         })
         m = Prophet(holidays=holidays)
         m.fit(DATA2)
         fcst = m.predict()
-        self.assertEqual(sum(fcst['new_years'] == 0), 575)
+        self.assertEqual(sum(fcst['special_day'] == 0), 575)
 
     def test_custom_seasonality(self):
-        m = Prophet()
+        holidays = pd.DataFrame({
+            'ds': pd.to_datetime(['2017-01-02']),
+            'holiday': ['special_day'],
+        })
+        m = Prophet(holidays=holidays)
         m.add_seasonality(name='monthly', period=30, fourier_order=5)
         self.assertEqual(m.seasonalities['monthly'], (30, 5))