diff --git a/python/prophet/forecaster.py b/python/prophet/forecaster.py index 261776c85..ac1144fdd 100644 --- a/python/prophet/forecaster.py +++ b/python/prophet/forecaster.py @@ -2211,6 +2211,8 @@ def make_future_dataframe( """ if self.history_dates is None: raise Exception('Model has not been fit.') + if not isinstance(periods, (int, np.integer)) or periods < 0: + raise ValueError('periods must be a non-negative integer.') if freq is None: # taking the tail makes freq inference more reliable freq = pd.infer_freq(self.history_dates.tail(5)) diff --git a/python/prophet/tests/test_prophet.py b/python/prophet/tests/test_prophet.py index 0c5e9d0e2..bb3438e0d 100644 --- a/python/prophet/tests/test_prophet.py +++ b/python/prophet/tests/test_prophet.py @@ -261,6 +261,9 @@ def test_make_future_dataframe(self, daily_univariate_ts, backend): assert len(future) == 3 assert np.all(future["ds"].values == correct.values) + with pytest.raises(ValueError, match='periods must be a non-negative integer'): + forecaster.make_future_dataframe(periods=-1) + def test_make_future_dataframe_include_history(self, daily_univariate_ts, backend): train = daily_univariate_ts.head(468 // 2).copy() #cover history with NAs