Only allow a Prophet object to be fit once

This commit is contained in:
Ben Letham 2017-04-05 10:44:21 -07:00
parent 961716ba55
commit 34c0f80684
2 changed files with 6 additions and 0 deletions

View file

@ -473,6 +473,9 @@ logistic_growth_init <- function(df) {
#' #'
#' @export #' @export
fit.prophet <- function(m, df, ...) { fit.prophet <- function(m, df, ...) {
if (!is.null(m$history)) {
stop("Prophet object can only be fit once. Instantiate a new object.")
}
history <- df %>% history <- df %>%
dplyr::filter(!is.na(y)) dplyr::filter(!is.na(y))
m$history.dates <- sort(zoo::as.Date(df$ds)) m$history.dates <- sort(zoo::as.Date(df$ds))

View file

@ -479,6 +479,9 @@ class Prophet(object):
------- -------
The fitted Prophet object. The fitted Prophet object.
""" """
if self.history is not None:
raise Exception('Prophet object can only be fit once. '
'Instantiate a new object.')
history = df[df['y'].notnull()].copy() history = df[df['y'].notnull()].copy()
self.history_dates = pd.to_datetime(df['ds']).sort_values() self.history_dates = pd.to_datetime(df['ds']).sort_values()