Bläddra i källkod

Better error messaging for required columns ds and y

Ben Letham 7 år sedan
förälder
incheckning
7277e6c3b2
2 ändrade filer med 11 tillägg och 0 borttagningar
  1. 6 0
      R/R/prophet.R
  2. 5 0
      python/fbprophet/forecaster.py

+ 6 - 0
R/R/prophet.R

@@ -1043,6 +1043,12 @@ fit.prophet <- function(m, df, ...) {
   if (!is.null(m$history)) {
     stop("Prophet object can only be fit once. Instantiate a new object.")
   }
+  if (!(exists('ds', where = df)) | !(exists('y', where = df))) {
+    stop(paste(
+      "Dataframe must have columns 'ds' and 'y' with the dates and values",
+      "respectively."
+    ))
+  }
   history <- df %>%
     dplyr::filter(!is.na(y))
   if (nrow(history) < 2) {

+ 5 - 0
python/fbprophet/forecaster.py

@@ -927,6 +927,11 @@ class Prophet(object):
         if self.history is not None:
             raise Exception('Prophet object can only be fit once. '
                             'Instantiate a new object.')
+        if ('ds' not in df) or ('y' not in df):
+            raise ValueError(
+                "Dataframe must have columns 'ds' and 'y' with the dates and "
+                "values respectively."
+            )
         history = df[df['y'].notnull()].copy()
         if history.shape[0] < 2:
             raise ValueError('Dataframe has less than 2 non-NaN rows.')