From 7277e6c3b2974eee9b1e969c0ce87e26e5d94615 Mon Sep 17 00:00:00 2001 From: Ben Letham Date: Tue, 29 May 2018 16:17:59 -0700 Subject: [PATCH] Better error messaging for required columns ds and y --- R/R/prophet.R | 6 ++++++ python/fbprophet/forecaster.py | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/R/R/prophet.R b/R/R/prophet.R index 608863b..dabdcf8 100644 --- a/R/R/prophet.R +++ b/R/R/prophet.R @@ -1043,6 +1043,12 @@ fit.prophet <- function(m, df, ...) { if (!is.null(m$history)) { stop("Prophet object can only be fit once. Instantiate a new object.") } + if (!(exists('ds', where = df)) | !(exists('y', where = df))) { + stop(paste( + "Dataframe must have columns 'ds' and 'y' with the dates and values", + "respectively." + )) + } history <- df %>% dplyr::filter(!is.na(y)) if (nrow(history) < 2) { diff --git a/python/fbprophet/forecaster.py b/python/fbprophet/forecaster.py index ba801d1..acce127 100644 --- a/python/fbprophet/forecaster.py +++ b/python/fbprophet/forecaster.py @@ -927,6 +927,11 @@ class Prophet(object): if self.history is not None: raise Exception('Prophet object can only be fit once. ' 'Instantiate a new object.') + if ('ds' not in df) or ('y' not in df): + raise ValueError( + "Dataframe must have columns 'ds' and 'y' with the dates and " + "values respectively." + ) history = df[df['y'].notnull()].copy() if history.shape[0] < 2: raise ValueError('Dataframe has less than 2 non-NaN rows.')