From a519043f1bdc9e71647d4daad55a072133b1be0d Mon Sep 17 00:00:00 2001 From: Ben Letham Date: Mon, 17 Aug 2020 16:24:34 -0700 Subject: [PATCH] Fix bug in changepoint handling in prophet_copy (#1529) --- R/R/diagnostics.R | 3 ++- python/fbprophet/diagnostics.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/R/R/diagnostics.R b/R/R/diagnostics.R index 709bb7c..242216d 100644 --- a/R/R/diagnostics.R +++ b/R/R/diagnostics.R @@ -181,7 +181,8 @@ prophet_copy <- function(m, cutoff = NULL) { changepoints <- m$changepoints if (!is.null(cutoff)) { cutoff <- set_date(cutoff) - changepoints <- changepoints[changepoints <= cutoff] + last_history_date <- max(m$history$ds[m$history$ds <= cutoff]) + changepoints <- changepoints[changepoints < last_history_date] } } else { changepoints <- NULL diff --git a/python/fbprophet/diagnostics.py b/python/fbprophet/diagnostics.py index 5ca3159..b1d4f3f 100644 --- a/python/fbprophet/diagnostics.py +++ b/python/fbprophet/diagnostics.py @@ -268,8 +268,9 @@ def prophet_copy(m, cutoff=None): if m.specified_changepoints: changepoints = m.changepoints if cutoff is not None: - # Filter change points '<= cutoff' - changepoints = changepoints[changepoints <= cutoff] + # Filter change points '< cutoff' + last_history_date = max(m.history['ds'][m.history['ds'] <= cutoff]) + changepoints = changepoints[changepoints < last_history_date] else: changepoints = None