From 0c30f6efcf7c74b434f7a44c02e4668a91eb78fc Mon Sep 17 00:00:00 2001 From: Ben Letham Date: Fri, 20 Apr 2018 18:48:21 -0700 Subject: [PATCH] Merge in some minor fixes from master --- R/R/prophet.R | 6 +++++- README.md | 2 +- python/fbprophet/forecaster.py | 10 ++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/R/R/prophet.R b/R/R/prophet.R index 6e6d85c..0eb4525 100644 --- a/R/R/prophet.R +++ b/R/R/prophet.R @@ -321,7 +321,8 @@ setup_dataframe <- function(m, df, initialize_scales = FALSE) { df$ds <- set_date(df$ds) if (anyNA(df$ds)) { stop(paste('Unable to parse date format in column ds. Convert to date ', - 'format. Either %Y-%m-%d or %Y-%m-%d %H:%M:%S')) + 'format (%Y-%m-%d or %Y-%m-%d %H:%M:%S) and check that there', + 'are no NAs.')) } for (name in names(m$extra_regressors)) { if (!(name %in% colnames(df))) { @@ -1361,6 +1362,9 @@ make_future_dataframe <- function(m, periods, freq = 'day', if (freq == 'm') { freq <- 'month' } + if (is.null(m$history.dates)) { + stop('Model must be fit before this can be used.') + } dates <- seq(max(m$history.dates), length.out = periods + 1, by = freq) dates <- dates[2:(periods + 1)] # Drop the first, which is max(history$ds) if (include_history) { diff --git a/README.md b/README.md index ec9dd9b..616394d 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ On Windows, PyStan requires a compiler so you'll need to [follow the instruction ### Linux -Make sure compilers (gcc, g++) and Python development tools (python-dev) are installed. If you are using a VM, be aware that you will need at least 4GB of memory to install fbprophet, and at least 2GB of memory to use fbprophet. +Make sure compilers (gcc, g++, build-essential) and Python development tools (python-dev, python3-dev) are installed. If you are using a VM, be aware that you will need at least 4GB of memory to install fbprophet, and at least 2GB of memory to use fbprophet. ### Anaconda diff --git a/python/fbprophet/forecaster.py b/python/fbprophet/forecaster.py index 88866ca..4f1b2fe 100644 --- a/python/fbprophet/forecaster.py +++ b/python/fbprophet/forecaster.py @@ -162,9 +162,9 @@ class Prophet(object): raise ValueError('Holidays must have both lower_window and ' + 'upper_window, or neither') if has_lower: - if max(self.holidays['lower_window']) > 0: + if self.holidays['lower_window'].max() > 0: raise ValueError('Holiday lower_window should be <= 0') - if min(self.holidays['upper_window']) < 0: + if self.holidays['upper_window'].min() < 0: raise ValueError('Holiday upper_window should be >= 0') for h in self.holidays['holiday'].unique(): self.validate_column_name(h, check_holidays=False) @@ -1218,6 +1218,8 @@ class Prophet(object): pd.Dataframe that extends forward from the end of self.history for the requested number of periods. """ + if self.history_dates is None: + raise Exception('Model must be fit before this can be used.') last_date = self.history_dates.max() dates = pd.date_range( start=last_date, @@ -1307,6 +1309,9 @@ class Prophet(object): fig, axes = plt.subplots(npanel, 1, facecolor='w', figsize=(9, 3 * npanel)) + if npanel == 1: + axes = [axes] + for ax, plot in zip(axes, components): if plot == 'trend': self.plot_forecast_component( @@ -1468,6 +1473,7 @@ class Prophet(object): Parameters ---------- + name: Seasonality name, like 'daily', 'weekly'. ax: Optional matplotlib Axes to plot on. One will be created if this is not provided. uncertainty: Optional boolean to plot uncertainty intervals.