# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/preprocessing/resample.ipynb.

# %% auto 0
__all__ = ['resample']

# %% ../../nbs/preprocessing/resample.ipynb 1
from typing import Optional

import joblib
from tqdm.notebook import tqdm
import nilmtk

from . import RawData


def resample(
    raw_data: RawData,
    selected_resample_rule,
    selected_resample_how_method,
    selected_resample_fill_method,
    memory: Optional[joblib.Memory] = None,
) -> RawData:
    def _resample(
        raw_data: RawData,
        selected_resample_rule,
        selected_resample_how_method,
        selected_resample_fill_method,
    ):
        data_resampled = {}
        for cat, cat_data in tqdm(raw_data.items()):
            data_resampled[cat] = nilmtk.utils.safe_resample(
                data=cat_data,
                rule=selected_resample_rule,
                how=selected_resample_how_method,
                fill_method=selected_resample_fill_method,
            )
        return data_resampled

    if memory:
        _resample = memory.cache(_resample)

    # IMPORTANT: pass params, otherwise joblib will always use the
    # same params even if the input data or params change
    return _resample(
        raw_data,
        selected_resample_rule,
        selected_resample_how_method,
        selected_resample_fill_method,
    )
