Better error messaging for required columns ds and y

This commit is contained in:
Ben Letham 2018-05-29 16:17:59 -07:00
parent 44f82f6ea1
commit 7277e6c3b2
2 changed files with 11 additions and 0 deletions

View file

@ -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) {

View file

@ -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.')