mirror of
https://github.com/saymrwulf/prophet.git
synced 2026-11-17 08:40:56 +00:00
Graceful error on empty input dataframes
This commit is contained in:
parent
8066634cb4
commit
439efb7209
2 changed files with 10 additions and 0 deletions
|
|
@ -926,6 +926,9 @@ fit.prophet <- function(m, df, ...) {
|
||||||
}
|
}
|
||||||
history <- df %>%
|
history <- df %>%
|
||||||
dplyr::filter(!is.na(y))
|
dplyr::filter(!is.na(y))
|
||||||
|
if (nrow(history) < 2) {
|
||||||
|
stop("Dataframe has less than 2 non-NA rows.")
|
||||||
|
}
|
||||||
m$history.dates <- sort(set_date(df$ds))
|
m$history.dates <- sort(set_date(df$ds))
|
||||||
|
|
||||||
out <- setup_dataframe(m, history, initialize_scales = TRUE)
|
out <- setup_dataframe(m, history, initialize_scales = TRUE)
|
||||||
|
|
@ -1047,6 +1050,9 @@ predict.prophet <- function(object, df = NULL, ...) {
|
||||||
if (is.null(df)) {
|
if (is.null(df)) {
|
||||||
df <- object$history
|
df <- object$history
|
||||||
} else {
|
} else {
|
||||||
|
if (nrow(df) == 0) {
|
||||||
|
stop("Dataframe has no rows.")
|
||||||
|
}
|
||||||
out <- setup_dataframe(object, df)
|
out <- setup_dataframe(object, df)
|
||||||
df <- out$df
|
df <- out$df
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -769,6 +769,8 @@ class Prophet(object):
|
||||||
raise Exception('Prophet object can only be fit once. '
|
raise Exception('Prophet object can only be fit once. '
|
||||||
'Instantiate a new object.')
|
'Instantiate a new object.')
|
||||||
history = df[df['y'].notnull()].copy()
|
history = df[df['y'].notnull()].copy()
|
||||||
|
if history.shape[0] < 2:
|
||||||
|
raise ValueError('Dataframe has less than 2 non-NaN rows.')
|
||||||
self.history_dates = pd.to_datetime(df['ds']).sort_values()
|
self.history_dates = pd.to_datetime(df['ds']).sort_values()
|
||||||
|
|
||||||
history = self.setup_dataframe(history, initialize_scales=True)
|
history = self.setup_dataframe(history, initialize_scales=True)
|
||||||
|
|
@ -863,6 +865,8 @@ class Prophet(object):
|
||||||
if df is None:
|
if df is None:
|
||||||
df = self.history.copy()
|
df = self.history.copy()
|
||||||
else:
|
else:
|
||||||
|
if df.shape[0] == 0:
|
||||||
|
raise ValueError('Dataframe has no rows.')
|
||||||
df = self.setup_dataframe(df.copy())
|
df = self.setup_dataframe(df.copy())
|
||||||
|
|
||||||
df['trend'] = self.predict_trend(df)
|
df['trend'] = self.predict_trend(df)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue