NaNDropper#

class openstef_models.transforms.general.nan_dropper.NaNDropper(**data: Any) None[source]

Bases: BaseConfig, TimeSeriesTransform

Transform that drops rows containing NaN values in selected columns.

This transform removes any row that has at least one NaN value in the specified columns. It operates statelessly - no fitting is required.

Example

>>> import pandas as pd
>>> import numpy as np
>>> from datetime import timedelta
>>> from openstef_core.datasets import TimeSeriesDataset
>>> from openstef_models.transforms.general import NaNDropper
>>>
>>> # Create sample dataset with NaN values
>>> data = pd.DataFrame({
...     'load': [100.0, np.nan, 110.0, 130.0],
...     'temperature': [20.0, 22.0, np.nan, 23.0],
...     'humidity': [60.0, 65.0, 70.0, 75.0]
... }, index=pd.date_range('2025-01-01', periods=4, freq='1h'))
>>> dataset = TimeSeriesDataset(data)
>>>
>>> # Drop rows with NaN in load or temperature
>>> dropper = NaNDropper(selection=FeatureSelection(include=['load', 'temperature']))
>>> transformed = dropper.transform(dataset)
>>> len(transformed.data)
2
>>> transformed.data['load'].tolist()
[100.0, 130.0]
Parameters:

data (Any)

selection: FeatureSelection
warn_threshold: float
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].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self (BaseModel) – The BaseModel instance.

  • context (Any) – The context.

  • self

  • context

Return type:

None