From 28cd55241f67d23ae33e0162600e660c38da25b1 Mon Sep 17 00:00:00 2001 From: Ben Letham Date: Mon, 13 May 2019 13:11:07 -0700 Subject: [PATCH] Verify that cap > floor (#807) --- R/R/prophet.R | 3 +++ python/fbprophet/forecaster.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/R/R/prophet.R b/R/R/prophet.R index 337a349..ead91ea 100644 --- a/R/R/prophet.R +++ b/R/R/prophet.R @@ -393,6 +393,9 @@ setup_dataframe <- function(m, df, initialize_scales = FALSE) { if (!(exists('cap', where=df))) { stop('Capacities must be supplied for logistic growth.') } + if (any(df$cap <= df$floor)) { + stop('cap must be greater than floor (which defaults to 0).') + } df <- df %>% dplyr::mutate(cap_scaled = (cap - floor) / m$y.scale) } diff --git a/python/fbprophet/forecaster.py b/python/fbprophet/forecaster.py index d8096ca..2433dec 100644 --- a/python/fbprophet/forecaster.py +++ b/python/fbprophet/forecaster.py @@ -274,6 +274,10 @@ class Prophet(object): "Capacities must be supplied for logistic growth in " "column 'cap'" ) + if (df['cap'] <= df['floor']).any(): + raise ValueError( + 'cap must be greater than floor (which defaults to 0).' + ) df['cap_scaled'] = (df['cap'] - df['floor']) / self.y_scale df['t'] = (df['ds'] - self.start) / self.t_scale