From 1339aada960c6d49a319d6f70ebed14f5604d994 Mon Sep 17 00:00:00 2001 From: bl Date: Tue, 4 Jul 2017 01:12:22 -0700 Subject: [PATCH] Check for Inf values in history; roxygen version bump. --- R/DESCRIPTION | 2 +- R/R/prophet.R | 3 +++ R/man/compile_stan_model.Rd | 1 - R/man/df_for_plotting.Rd | 1 - R/man/fit.prophet.Rd | 1 - R/man/fourier_series.Rd | 1 - R/man/get_changepoint_matrix.Rd | 1 - R/man/get_prophet_stan_model.Rd | 1 - R/man/linear_growth_init.Rd | 1 - R/man/logistic_growth_init.Rd | 1 - R/man/make_all_seasonality_features.Rd | 1 - R/man/make_future_dataframe.Rd | 1 - R/man/make_holiday_features.Rd | 1 - R/man/make_seasonality_features.Rd | 1 - R/man/piecewise_linear.Rd | 1 - R/man/piecewise_logistic.Rd | 1 - R/man/plot.prophet.Rd | 1 - R/man/plot_holidays.Rd | 1 - R/man/plot_trend.Rd | 1 - R/man/plot_weekly.Rd | 1 - R/man/plot_yearly.Rd | 1 - R/man/predict.prophet.Rd | 1 - R/man/predict_seasonal_components.Rd | 1 - R/man/predict_trend.Rd | 1 - R/man/predict_uncertainty.Rd | 1 - R/man/prophet.Rd | 1 - R/man/prophet_plot_components.Rd | 1 - R/man/sample_model.Rd | 1 - R/man/sample_predictive_trend.Rd | 1 - R/man/set_auto_seasonalities.Rd | 1 - R/man/set_changepoints.Rd | 1 - R/man/setup_dataframe.Rd | 1 - R/man/validate_inputs.Rd | 1 - python/fbprophet/forecaster.py | 2 ++ 34 files changed, 6 insertions(+), 32 deletions(-) diff --git a/R/DESCRIPTION b/R/DESCRIPTION index 71e7d94..8ce199b 100644 --- a/R/DESCRIPTION +++ b/R/DESCRIPTION @@ -31,5 +31,5 @@ Suggests: readr License: BSD_3_clause + file LICENSE LazyData: true -RoxygenNote: 5.0.1 +RoxygenNote: 6.0.1 VignetteBuilder: knitr diff --git a/R/R/prophet.R b/R/R/prophet.R index 93dc61b..d705169 100644 --- a/R/R/prophet.R +++ b/R/R/prophet.R @@ -514,6 +514,9 @@ fit.prophet <- function(m, df, ...) { } history <- df %>% dplyr::filter(!is.na(y)) + if (any(is.infinite(history$y))) { + stop("Found infinity in column y.") + } m$history.dates <- sort(zoo::as.Date(df$ds)) out <- setup_dataframe(m, history, initialize_scales = TRUE) diff --git a/R/man/compile_stan_model.Rd b/R/man/compile_stan_model.Rd index bee119b..fca4f98 100644 --- a/R/man/compile_stan_model.Rd +++ b/R/man/compile_stan_model.Rd @@ -16,4 +16,3 @@ Stan model. \description{ Compile Stan model } - diff --git a/R/man/df_for_plotting.Rd b/R/man/df_for_plotting.Rd index 8b241b2..772709c 100644 --- a/R/man/df_for_plotting.Rd +++ b/R/man/df_for_plotting.Rd @@ -14,4 +14,3 @@ df_for_plotting(m, fcst) \description{ Merge history and forecast for plotting. } - diff --git a/R/man/fit.prophet.Rd b/R/man/fit.prophet.Rd index fd6a8e0..31fb71a 100644 --- a/R/man/fit.prophet.Rd +++ b/R/man/fit.prophet.Rd @@ -24,4 +24,3 @@ with the following elements: sigma_obs (M array): Noise level. Note that M=1 if MAP estimation. } - diff --git a/R/man/fourier_series.Rd b/R/man/fourier_series.Rd index a3cf3d6..546bce6 100644 --- a/R/man/fourier_series.Rd +++ b/R/man/fourier_series.Rd @@ -19,4 +19,3 @@ Matrix with seasonality features. \description{ Provides Fourier series components with the specified frequency and order. } - diff --git a/R/man/get_changepoint_matrix.Rd b/R/man/get_changepoint_matrix.Rd index c0d7405..7d52d99 100644 --- a/R/man/get_changepoint_matrix.Rd +++ b/R/man/get_changepoint_matrix.Rd @@ -15,4 +15,3 @@ array of indexes. \description{ Gets changepoint matrix for history dataframe. } - diff --git a/R/man/get_prophet_stan_model.Rd b/R/man/get_prophet_stan_model.Rd index 181a812..0b61230 100644 --- a/R/man/get_prophet_stan_model.Rd +++ b/R/man/get_prophet_stan_model.Rd @@ -16,4 +16,3 @@ Stan model. \description{ Load compiled Stan model } - diff --git a/R/man/linear_growth_init.Rd b/R/man/linear_growth_init.Rd index f4c6c17..02a413a 100644 --- a/R/man/linear_growth_init.Rd +++ b/R/man/linear_growth_init.Rd @@ -19,4 +19,3 @@ Provides a strong initialization for linear growth by calculating the growth and offset parameters that pass the function through the first and last points in the time series. } - diff --git a/R/man/logistic_growth_init.Rd b/R/man/logistic_growth_init.Rd index 863bd11..5fa65a6 100644 --- a/R/man/logistic_growth_init.Rd +++ b/R/man/logistic_growth_init.Rd @@ -19,4 +19,3 @@ Provides a strong initialization for logistic growth by calculating the growth and offset parameters that pass the function through the first and last points in the time series. } - diff --git a/R/man/make_all_seasonality_features.Rd b/R/man/make_all_seasonality_features.Rd index 21c14ac..cfd81d7 100644 --- a/R/man/make_all_seasonality_features.Rd +++ b/R/man/make_all_seasonality_features.Rd @@ -17,4 +17,3 @@ Dataframe with seasonality. \description{ Dataframe with seasonality features. } - diff --git a/R/man/make_future_dataframe.Rd b/R/man/make_future_dataframe.Rd index 35a0221..295d121 100644 --- a/R/man/make_future_dataframe.Rd +++ b/R/man/make_future_dataframe.Rd @@ -23,4 +23,3 @@ Dataframe that extends forward from the end of m$history for the \description{ Make dataframe with future dates for forecasting. } - diff --git a/R/man/make_holiday_features.Rd b/R/man/make_holiday_features.Rd index dd6f73a..18688c9 100644 --- a/R/man/make_holiday_features.Rd +++ b/R/man/make_holiday_features.Rd @@ -17,4 +17,3 @@ A dataframe with a column for each holiday. \description{ Construct a matrix of holiday features. } - diff --git a/R/man/make_seasonality_features.Rd b/R/man/make_seasonality_features.Rd index e76980b..28aba00 100644 --- a/R/man/make_seasonality_features.Rd +++ b/R/man/make_seasonality_features.Rd @@ -21,4 +21,3 @@ Dataframe with seasonality. \description{ Data frame with seasonality features. } - diff --git a/R/man/piecewise_linear.Rd b/R/man/piecewise_linear.Rd index 0a31ce5..c9c4d08 100644 --- a/R/man/piecewise_linear.Rd +++ b/R/man/piecewise_linear.Rd @@ -23,4 +23,3 @@ Vector y(t). \description{ Evaluate the piecewise linear function. } - diff --git a/R/man/piecewise_logistic.Rd b/R/man/piecewise_logistic.Rd index ab9936a..0251ebd 100644 --- a/R/man/piecewise_logistic.Rd +++ b/R/man/piecewise_logistic.Rd @@ -25,4 +25,3 @@ Vector y(t). \description{ Evaluate the piecewise logistic function. } - diff --git a/R/man/plot.prophet.Rd b/R/man/plot.prophet.Rd index 324a32f..25c520e 100644 --- a/R/man/plot.prophet.Rd +++ b/R/man/plot.prophet.Rd @@ -41,4 +41,3 @@ plot(m, forecast) } } - diff --git a/R/man/plot_holidays.Rd b/R/man/plot_holidays.Rd index 75420a7..93de11b 100644 --- a/R/man/plot_holidays.Rd +++ b/R/man/plot_holidays.Rd @@ -19,4 +19,3 @@ A ggplot2 plot. \description{ Plot the holidays component of the forecast. } - diff --git a/R/man/plot_trend.Rd b/R/man/plot_trend.Rd index 8e74a11..f837baa 100644 --- a/R/man/plot_trend.Rd +++ b/R/man/plot_trend.Rd @@ -20,4 +20,3 @@ A ggplot2 plot. \description{ Plot the prophet trend. } - diff --git a/R/man/plot_weekly.Rd b/R/man/plot_weekly.Rd index e95e68a..ba6e3a2 100644 --- a/R/man/plot_weekly.Rd +++ b/R/man/plot_weekly.Rd @@ -21,4 +21,3 @@ A ggplot2 plot. \description{ Plot the weekly component of the forecast. } - diff --git a/R/man/plot_yearly.Rd b/R/man/plot_yearly.Rd index 50169b8..4f7e3ea 100644 --- a/R/man/plot_yearly.Rd +++ b/R/man/plot_yearly.Rd @@ -21,4 +21,3 @@ A ggplot2 plot. \description{ Plot the yearly component of the forecast. } - diff --git a/R/man/predict.prophet.Rd b/R/man/predict.prophet.Rd index ba69efc..c9cad3c 100644 --- a/R/man/predict.prophet.Rd +++ b/R/man/predict.prophet.Rd @@ -32,4 +32,3 @@ plot(m, forecast) } } - diff --git a/R/man/predict_seasonal_components.Rd b/R/man/predict_seasonal_components.Rd index 30cf3f2..f28df7f 100644 --- a/R/man/predict_seasonal_components.Rd +++ b/R/man/predict_seasonal_components.Rd @@ -17,4 +17,3 @@ Dataframe with seasonal components. \description{ Predict seasonality broken down into components. } - diff --git a/R/man/predict_trend.Rd b/R/man/predict_trend.Rd index 98eff57..d668995 100644 --- a/R/man/predict_trend.Rd +++ b/R/man/predict_trend.Rd @@ -17,4 +17,3 @@ Vector with trend on prediction dates. \description{ Predict trend using the prophet model. } - diff --git a/R/man/predict_uncertainty.Rd b/R/man/predict_uncertainty.Rd index 6f163a7..a6409c0 100644 --- a/R/man/predict_uncertainty.Rd +++ b/R/man/predict_uncertainty.Rd @@ -17,4 +17,3 @@ Dataframe with uncertainty intervals. \description{ Prophet uncertainty intervals. } - diff --git a/R/man/prophet.Rd b/R/man/prophet.Rd index 273172c..3c67466 100644 --- a/R/man/prophet.Rd +++ b/R/man/prophet.Rd @@ -79,4 +79,3 @@ m <- prophet(history) } } - diff --git a/R/man/prophet_plot_components.Rd b/R/man/prophet_plot_components.Rd index 34ce1ee..eeeea29 100644 --- a/R/man/prophet_plot_components.Rd +++ b/R/man/prophet_plot_components.Rd @@ -36,4 +36,3 @@ Plot the components of a prophet forecast. Prints a ggplot2 with panels for trend, weekly and yearly seasonalities if present, and holidays if present. } - diff --git a/R/man/sample_model.Rd b/R/man/sample_model.Rd index 74bfc6c..5aecfce 100644 --- a/R/man/sample_model.Rd +++ b/R/man/sample_model.Rd @@ -21,4 +21,3 @@ List of trend, seasonality, and yhat, each a vector like df$t. \description{ Simulate observations from the extrapolated generative model. } - diff --git a/R/man/sample_predictive_trend.Rd b/R/man/sample_predictive_trend.Rd index 522f551..8409059 100644 --- a/R/man/sample_predictive_trend.Rd +++ b/R/man/sample_predictive_trend.Rd @@ -19,4 +19,3 @@ Vector of simulated trend over df$t. \description{ Simulate the trend using the extrapolated generative model. } - diff --git a/R/man/set_auto_seasonalities.Rd b/R/man/set_auto_seasonalities.Rd index 838a66a..2deaab8 100644 --- a/R/man/set_auto_seasonalities.Rd +++ b/R/man/set_auto_seasonalities.Rd @@ -17,4 +17,3 @@ Turns on yearly seasonality if there is >=2 years of history. Turns on weekly seasonality if there is >=2 weeks of history, and the spacing between dates in the history is <7 days. } - diff --git a/R/man/set_changepoints.Rd b/R/man/set_changepoints.Rd index 4235508..5cbea29 100644 --- a/R/man/set_changepoints.Rd +++ b/R/man/set_changepoints.Rd @@ -20,4 +20,3 @@ Sets m$changepoints to the dates of changepoints. Either: 2) We are generating a grid of them. 3) The user prefers no changepoints be used. } - diff --git a/R/man/setup_dataframe.Rd b/R/man/setup_dataframe.Rd index 87678c4..4486f4b 100644 --- a/R/man/setup_dataframe.Rd +++ b/R/man/setup_dataframe.Rd @@ -21,4 +21,3 @@ Adds a time index and scales y. Creates auxillary columns 't', 't_ix', 'y_scaled', and 'cap_scaled'. These columns are used during both fitting and predicting. } - diff --git a/R/man/validate_inputs.Rd b/R/man/validate_inputs.Rd index fd47da5..1f26fac 100644 --- a/R/man/validate_inputs.Rd +++ b/R/man/validate_inputs.Rd @@ -12,4 +12,3 @@ validate_inputs(m) \description{ Validates the inputs to Prophet. } - diff --git a/python/fbprophet/forecaster.py b/python/fbprophet/forecaster.py index 01ae798..a662211 100644 --- a/python/fbprophet/forecaster.py +++ b/python/fbprophet/forecaster.py @@ -490,6 +490,8 @@ class Prophet(object): raise Exception('Prophet object can only be fit once. ' 'Instantiate a new object.') history = df[df['y'].notnull()].copy() + if np.isinf(history['y'].values).any(): + raise ValueError('Found infinity in column y.') self.history_dates = pd.to_datetime(df['ds']).sort_values() history = self.setup_dataframe(history, initialize_scales=True)