Skip to content

Commit

Permalink
[Fix] Accessing None type config_refgressors (#1536)
Browse files Browse the repository at this point in the history
* fix accessing None config_regressors 1535

* fix accessing None config_regressors 1535
  • Loading branch information
ourownstory authored Feb 19, 2024
1 parent 0f034bb commit ce94e56
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tests/metrics/*.json
tests/metrics/*.svg
.vscode/launch.json
.vscode/settings.json
source/
/source/

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
5 changes: 5 additions & 0 deletions docs/source/code/event_utils.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Core Module Documentation
==========================

.. automodule:: neuralprophet.event_utils
:members:
127 changes: 63 additions & 64 deletions docs/source/tutorials/tutorial06.ipynb

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion neuralprophet/data/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def _maybe_extend_df(
periods=periods_add[df_name],
freq=freq,
config_events=config_events,
config_regressors=config_regressors,
)
future_df["ID"] = df_name
df_i = pd.concat([df_i, future_df])
Expand Down Expand Up @@ -173,7 +174,9 @@ def _make_future_dataframe(
# Receives df with single ID column
assert len(df["ID"].unique()) == 1
if periods == 0 and n_historic_predictions is True:
log.warning("Not extending df into future as no periods specified." "You can call predict directly instead.")
log.warning(
"Not extending df into future as no periods specified. You can skip this and predict directly instead."
)
df = df.copy(deep=True)
_ = df_utils.infer_frequency(df, n_lags=max_lags, freq=freq)
last_date = pd.to_datetime(df["ds"].copy(deep=True).dropna()).sort_values().max()
Expand Down
30 changes: 15 additions & 15 deletions neuralprophet/df_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pandas as pd

if TYPE_CHECKING:
from neuralprophet.configure import ConfigEvents, ConfigLaggedRegressors, ConfigSeasonality
from neuralprophet.configure import ConfigEvents, ConfigFutureRegressors, ConfigLaggedRegressors, ConfigSeasonality


log = logging.getLogger("NP.df_utils")
Expand Down Expand Up @@ -140,7 +140,7 @@ def data_params_definition(
df,
normalize,
config_lagged_regressors: Optional[ConfigLaggedRegressors] = None,
config_regressors=None,
config_regressors: Optional[ConfigFutureRegressors] = None,
config_events: Optional[ConfigEvents] = None,
config_seasonality: Optional[ConfigSeasonality] = None,
local_run_despite_global: Optional[bool] = None,
Expand Down Expand Up @@ -248,7 +248,7 @@ def init_data_params(
df,
normalize="auto",
config_lagged_regressors: Optional[ConfigLaggedRegressors] = None,
config_regressors=None,
config_regressors: Optional[ConfigFutureRegressors] = None,
config_events: Optional[ConfigEvents] = None,
config_seasonality: Optional[ConfigSeasonality] = None,
global_normalization=False,
Expand Down Expand Up @@ -324,13 +324,13 @@ def init_data_params(
for df_name, df_i in df.groupby("ID"):
df_i.drop("ID", axis=1, inplace=True)
local_data_params[df_name] = data_params_definition(
df_i,
normalize,
config_lagged_regressors,
config_regressors,
config_events,
config_seasonality,
local_run_despite_global,
df=df_i,
normalize=normalize,
config_lagged_regressors=config_lagged_regressors,
config_regressors=config_regressors,
config_events=config_events,
config_seasonality=config_seasonality,
local_run_despite_global=local_run_despite_global,
)
if global_time_normalization:
# Overwrite local time normalization data_params with global values (pointer)
Expand Down Expand Up @@ -948,9 +948,9 @@ def make_future_df(
last_date,
periods,
freq,
config_events: Optional[ConfigEvents] = None,
config_events: ConfigEvents,
config_regressors: ConfigFutureRegressors,
events_df=None,
config_regressors=None,
regressors_df=None,
):
"""Extends df periods number steps into future.
Expand Down Expand Up @@ -988,9 +988,9 @@ def make_future_df(
if config_events is not None:
future_df = convert_events_to_features(future_df, config_events=config_events, events_df=events_df)
# set the regressors features
if config_regressors.regressors is not None and regressors_df is not None:
for regressor in regressors_df:
# Todo: iterate over config_regressors instead
if config_regressors is not None and config_regressors.regressors is not None and regressors_df is not None:
for regressor in config_regressors.regressors.keys():
assert regressor in regressors_df.columns, f"Regressor {regressor} not found in regressors_df"
future_df[regressor] = regressors_df[regressor]
for column in df_columns:
if column not in future_df.columns:
Expand Down

0 comments on commit ce94e56

Please sign in to comment.