DatetimeFeaturesAdder#

class openstef_models.transforms.time_domain.datetime_features_adder.DatetimeFeaturesAdder(**data: Any) None[source]

Bases: BaseConfig, TimeSeriesTransform

Transform that adds datetime features to time series data.

Computes features that are derived from the datetime index of the dataset.

The features added are:

  • is_week_day: 1 if the day is a weekday (Monday to Friday),

    0 otherwise (Saturday or Sunday).

  • is_weekend_day: 1 if the day is a weekend day (Saturday or Sunday),

    0 otherwise (Monday to Friday).

  • is_sunday: 1 if the day is a Sunday, 0 otherwise.

  • month_of_year: Month of the year (1 to 12).

  • quarter_of_year: Quarter of the year (1 to 4).

Example

>>> import pandas as pd
>>> from datetime import timedelta
>>> from openstef_core.datasets import TimeSeriesDataset
>>> from openstef_models.transforms.time_domain import (
...     DatetimeFeaturesAdder,
... )
>>>
>>> # Create sample dataset
>>> data = pd.DataFrame({
...     'load': [100, 120, 110]
... }, index=pd.date_range('2025-01-01', periods=3, freq='D'))
>>> dataset = TimeSeriesDataset(data, timedelta(days=1))
>>> transform = DatetimeFeaturesAdder()
>>> transformed_dataset = transform.transform(dataset)
>>> sorted(transformed_dataset.data.columns.tolist())
['is_sunday', 'is_week_day', 'is_weekend_day', 'load', 'month_of_year', 'quarter_of_year']
>>> transformed_dataset.data["is_week_day"].tolist()
[1, 1, 1]
>>> transformed_dataset.data["month_of_year"].tolist()
[1, 1, 1]
Parameters:

data (Any)

onehot_encode: bool
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].