Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[typing] Add ConfigEvents type annotations #989

Merged
merged 3 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion neuralprophet/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def init_data_params(
df,
config_lagged_regressors: Optional[ConfigLaggedRegressors] = None,
config_regressors=None,
config_events=None,
config_events: Optional[ConfigEvents] = None,
):
if len(df["ID"].unique()) == 1:
if not self.global_normalization:
Expand Down
17 changes: 12 additions & 5 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 ConfigLaggedRegressors
from neuralprophet.configure import ConfigEvents, ConfigLaggedRegressors


log = logging.getLogger("NP.df_utils")
Expand Down Expand Up @@ -140,7 +140,7 @@ def data_params_definition(
normalize,
config_lagged_regressors: Optional[ConfigLaggedRegressors] = None,
config_regressors=None,
config_events=None,
config_events: Optional[ConfigEvents] = None,
):
"""
Initialize data scaling values.
Expand Down Expand Up @@ -229,7 +229,7 @@ def init_data_params(
normalize="auto",
config_lagged_regressors: Optional[ConfigLaggedRegressors] = None,
config_regressors=None,
config_events=None,
config_events: Optional[ConfigEvents] = None,
global_normalization=False,
global_time_normalization=False,
):
Expand Down Expand Up @@ -947,7 +947,14 @@ def split_df(df, n_lags, n_forecasts, valid_p=0.2, inputs_overbleed=True, local_


def make_future_df(
df_columns, last_date, periods, freq, config_events=None, events_df=None, config_regressors=None, regressors_df=None
df_columns,
last_date,
periods,
freq,
config_events: Optional[ConfigEvents] = None,
events_df=None,
config_regressors=None,
regressors_df=None,
):
"""Extends df periods number steps into future.

Expand Down Expand Up @@ -996,7 +1003,7 @@ def make_future_df(
return future_df


def convert_events_to_features(df, config_events, events_df):
def convert_events_to_features(df, config_events: Optional[ConfigEvents], events_df):
"""
Converts events information into binary features of the df

Expand Down
4 changes: 2 additions & 2 deletions neuralprophet/time_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def tabularize_univariate_datetime(
n_forecasts=1,
predict_steps=1,
config_season=None,
config_events=None,
config_events: Optional[configure.ConfigEvents] = None,
config_country_holidays=None,
config_lagged_regressors: Optional[configure.ConfigLaggedRegressors] = None,
config_regressors: Optional[configure.ConfigFutureRegressors] = None,
Expand Down Expand Up @@ -477,7 +477,7 @@ def make_country_specific_holidays_df(year_list, country):
return country_specific_holidays_dict


def make_events_features(df, config_events=None, config_country_holidays=None):
def make_events_features(df, config_events: Optional[configure.ConfigEvents] = None, config_country_holidays=None):
"""
Construct arrays of all event features

Expand Down
6 changes: 3 additions & 3 deletions neuralprophet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from neuralprophet import utils_torch

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

log = logging.getLogger("NP.utils")

Expand Down Expand Up @@ -116,7 +116,7 @@ def reg_func_season(weights):
return reg_func_abs(weights)


def reg_func_events(config_events, config_country_holidays, model):
def reg_func_events(config_events: Optional[ConfigEvents], config_country_holidays, model):
"""
Regularization of events coefficients to induce sparcity

Expand Down Expand Up @@ -307,7 +307,7 @@ def get_holidays_from_country(country, df=None):
return set(holiday_names)


def config_events_to_model_dims(config_events, config_country_holidays):
def config_events_to_model_dims(config_events: Optional[ConfigEvents], config_country_holidays):
"""
Convert user specified events configurations along with country specific
holidays to input dims for TimeNet model.
Expand Down