From b07d34515528e87b14cd3d43c4806883876cce03 Mon Sep 17 00:00:00 2001 From: bl Date: Wed, 5 Jul 2017 20:15:00 -0700 Subject: [PATCH] Bugfix for add_seasonality --- R/tests/testthat/test_prophet.R | 4 +++- python/fbprophet/forecaster.py | 2 +- python/fbprophet/tests/test_prophet.py | 10 +++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/R/tests/testthat/test_prophet.R b/R/tests/testthat/test_prophet.R index 258ad73..c8d0c91 100644 --- a/R/tests/testthat/test_prophet.R +++ b/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)) }) diff --git a/python/fbprophet/forecaster.py b/python/fbprophet/forecaster.py index 3a6c054..5e3ce02 100644 --- a/python/fbprophet/forecaster.py +++ b/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) diff --git a/python/fbprophet/tests/test_prophet.py b/python/fbprophet/tests/test_prophet.py index 41059bc..23183ca 100644 --- a/python/fbprophet/tests/test_prophet.py +++ b/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))