From 35d470cbffe81b161b1b948fa056f48f85c49523 Mon Sep 17 00:00:00 2001 From: Ben Letham Date: Thu, 2 May 2019 14:53:57 -0700 Subject: [PATCH] Meaningful error message if predict is called before fit (for #462) --- R/R/prophet.R | 3 +++ python/fbprophet/forecaster.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/R/R/prophet.R b/R/R/prophet.R index 591fd16..74ab976 100644 --- a/R/R/prophet.R +++ b/R/R/prophet.R @@ -1305,6 +1305,9 @@ fit.prophet <- function(m, df, ...) { #' #' @export predict.prophet <- function(object, df = NULL, ...) { + if (is.null(object$history)) { + stop("Model must be fit before predictions can be made.") + } if (is.null(df)) { df <- object$history } else { diff --git a/python/fbprophet/forecaster.py b/python/fbprophet/forecaster.py index 1cc6144..8c3afd3 100644 --- a/python/fbprophet/forecaster.py +++ b/python/fbprophet/forecaster.py @@ -1147,6 +1147,9 @@ class Prophet(object): ------- A pd.DataFrame with the forecast components. """ + if self.history is None: + raise Exception('Model must be fit before predictions can be made.') + if df is None: df = self.history.copy() else: