Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions python/prophet/forecaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,10 @@ def add_seasonality(
ps = float(prior_scale)
if ps <= 0:
raise ValueError('Prior scale must be > 0')
if not period > 0:
# Also rejects NaN. period divides the Fourier frequencies, so 0
# only failed later in fit with a ZeroDivisionError.
raise ValueError('Period must be > 0')
if fourier_order <= 0:
raise ValueError('Fourier Order must be > 0')
if mode is None:
Expand Down
8 changes: 8 additions & 0 deletions python/prophet/tests/test_prophet.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,14 @@ def test_custom_fourier_order(self, backend):
with pytest.raises(ValueError):
m.add_seasonality(name="weekly", period=7, fourier_order=-1)

def test_custom_period(self, backend):
"""Period must be > 0"""
m = Prophet(stan_backend=backend)
for period in [0, 0.0, -7, float("nan")]:
with pytest.raises(ValueError, match="Period must be > 0"):
m.add_seasonality(name="custom", period=period, fourier_order=3)
assert "custom" not in m.seasonalities

def test_custom_priors(self, daily_univariate_ts, backend):
holidays = pd.DataFrame(
{
Expand Down