LagsAdder#

class openstef_models.transforms.time_domain.lags_adder.LagsAdder(**data: Any) None[source]

Bases: BaseConfig, TimeSeriesTransform

Transform that adds lag features to time series data.

Creates lagged copies of the target variable to capture temporal dependencies. Handles both single-horizon and multi-horizon (versioned) datasets, ensuring lags are valid for each forecast horizon.

Invariants

  • fit() must be called before transform() when add_autocorr_lags=True

  • Lags are only added if they fall within the available history window

  • For each horizon, only lags >= horizon are included (prevents data leakage)

  • All lag features use consistent naming: {target_column}_lag_{duration}

Parameters:

data (Any)

history_available: timedelta
horizons: list[LeadTime]
custom_lags: list[timedelta] | None
target_column: str
max_day_lags: int
add_trivial_lags: bool
add_autocorr_lags: bool
lag_fallback_offset: timedelta | None
property horizon_lags: dict[LeadTime, list[timedelta]]

Mapping of forecast horizons to their valid lag features.

property lags: list[timedelta]

All lag durations configured for this transform, sorted descending.

property min_horizon: timedelta

Shortest forecast horizon to determine minimum lag requirements.

model_post_init(context: Any) None[source]

Override this method to perform additional initialization after __init__ and model_construct. This is useful if you want to do some validation that requires the entire model to be initialized.

Parameters:

context (Any)

Return type:

None

property is_fitted: bool

Check if the transform has been fitted.

fit(data: TimeSeriesDataset) None[source]

Fit the transform to the input data.

This method should be called before applying the transform to the data. It allows the transform to learn any necessary parameters from the data.

Parameters:
Return type:

None

transform(data: TimeSeriesDataset) TimeSeriesDataset[source]

Transform the input data.

This method should apply a transformation to the input data and return a new instance.

Parameters:
Returns:

A new instance of the transformed data.

Raises:

NotFittedError – If the transform has not been fitted yet.

Return type:

TimeSeriesDataset

features_added() list[str][source]

List of feature names added by this transform.

Return type:

list[str]

Returns:

A list of strings representing the names of features added to the dataset by this transform. Default is an empty list.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': False, 'extra': 'ignore', 'protected_namespaces': ()}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].