From 3ac793832053c7cf44c52627c8281b6376c771b1 Mon Sep 17 00:00:00 2001 From: Tyler Nisonoff Date: Mon, 18 Nov 2024 11:51:21 -0800 Subject: [PATCH] Set appropriate defaults for various keys in config_dict that previously were not saved Fixes https://github.com/Nixtla/neuralforecast/issues/1206 --- nbs/core.ipynb | 19 +++++++++++++++---- nbs/nbdev.yml | 2 +- neuralforecast/core.py | 15 +++++++++++---- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/nbs/core.ipynb b/nbs/core.ipynb index c9c12bb4b..3bb61dbdc 100644 --- a/nbs/core.ipynb +++ b/nbs/core.ipynb @@ -1626,15 +1626,26 @@ " except FileNotFoundError:\n", " raise Exception('No configuration found in directory.')\n", "\n", + " # in 1.6.4, `local_scaler_type` / `scalers_` lived on the dataset.\n", + " # in order to preserve backwards-compatibility, we check to see if these are found on the dataset\n", + " # in case they cannot be found in `config_dict`\n", + " default_scalar_type = getattr(dataset, \"local_scaler_type\", None)\n", + " default_scalars_ = getattr(dataset, \"scalers_\", None)\n", + "\n", " # Create NeuralForecast object\n", " neuralforecast = NeuralForecast(\n", " models=models,\n", " freq=config_dict['freq'],\n", - " local_scaler_type=config_dict['local_scaler_type'],\n", + " local_scaler_type=config_dict.get(\"local_scaler_type\", default_scalar_type),\n", " )\n", "\n", - " for attr in ['id_col', 'time_col', 'target_col']:\n", - " setattr(neuralforecast, attr, config_dict[attr])\n", + " attr_to_default = {\n", + " \"id_col\": \"unique_id\",\n", + " \"time_col\": \"ds\",\n", + " \"target_col\": \"y\"\n", + " }\n", + " for attr, default in attr_to_default.items():\n", + " setattr(neuralforecast, attr, config_dict.get(attr, default))\n", " # only restore attribute if available\n", " for attr in ['prediction_intervals', '_cs_df']:\n", " if attr in config_dict.keys():\n", @@ -1655,7 +1666,7 @@ " # Fitted flag\n", " neuralforecast._fitted = config_dict['_fitted']\n", "\n", - " neuralforecast.scalers_ = config_dict['scalers_']\n", + " neuralforecast.scalers_ = config_dict.get(\"scalers_\", default_scalars_)\n", "\n", " return neuralforecast\n", " \n", diff --git a/nbs/nbdev.yml b/nbs/nbdev.yml index 190e738ad..768e9afbd 100644 --- a/nbs/nbdev.yml +++ b/nbs/nbdev.yml @@ -3,7 +3,7 @@ project: website: title: "neuralforecast" - site-url: "https://Nixtla.github.io/neuralforecast/" + site-url: "https://nixtlaverse.nixtla.io/neuralforecast/" description: "Time series forecasting suite using deep learning models" repo-branch: main repo-url: "https://github.com/Nixtla/neuralforecast/" diff --git a/neuralforecast/core.py b/neuralforecast/core.py index 85214f57a..fffe4bde5 100644 --- a/neuralforecast/core.py +++ b/neuralforecast/core.py @@ -1623,15 +1623,22 @@ def load(path, verbose=False, **kwargs): except FileNotFoundError: raise Exception("No configuration found in directory.") + # in 1.6.4, `local_scaler_type` / `scalers_` lived on the dataset. + # in order to preserve backwards-compatibility, we check to see if these are found on the dataset + # in case they cannot be found in `config_dict` + default_scalar_type = getattr(dataset, "local_scaler_type", None) + default_scalars_ = getattr(dataset, "scalers_", None) + # Create NeuralForecast object neuralforecast = NeuralForecast( models=models, freq=config_dict["freq"], - local_scaler_type=config_dict["local_scaler_type"], + local_scaler_type=config_dict.get("local_scaler_type", default_scalar_type), ) - for attr in ["id_col", "time_col", "target_col"]: - setattr(neuralforecast, attr, config_dict[attr]) + attr_to_default = {"id_col": "unique_id", "time_col": "ds", "target_col": "y"} + for attr, default in attr_to_default.items(): + setattr(neuralforecast, attr, config_dict.get(attr, default)) # only restore attribute if available for attr in ["prediction_intervals", "_cs_df"]: if attr in config_dict.keys(): @@ -1652,7 +1659,7 @@ def load(path, verbose=False, **kwargs): # Fitted flag neuralforecast._fitted = config_dict["_fitted"] - neuralforecast.scalers_ = config_dict["scalers_"] + neuralforecast.scalers_ = config_dict.get("scalers_", default_scalars_) return neuralforecast