def _create_fixed_length_windows(
    ds,
    start_offset_samples,
    stop_offset_samples,
    window_size_samples,
    window_stride_samples,
    drop_last_window,
    mapping=None,
    preload=False,
    picks=None,
    reject=None,
    flat=None,
    targets_from="metadata",
    last_target_only=True,
    lazy_metadata=False,
    on_missing="error",
    verbose="error",
):
    """Create WindowsDataset from BaseDataset with sliding windows.

    Parameters
    ----------
    ds : BaseDataset
        Dataset containing continuous data and description.

    See `create_fixed_length_windows` for description of other parameters.

    Returns
    -------
    WindowsDataset :
        Windowed dataset.
    """
    # catch window_kwargs to store to dataset
    window_kwargs = [
        (create_fixed_length_windows.__name__, _get_windowing_kwargs(locals())),
    ]
    stop = ds.raw.n_times if stop_offset_samples is None else stop_offset_samples

    # assume window should be whole recording
    if window_size_samples is None:
        window_size_samples = stop - start_offset_samples
    if window_stride_samples is None:
        window_stride_samples = window_size_samples

    last_potential_start = stop - window_size_samples

    # get targets from dataset description if they exist
    target = -1 if ds.target_name is None else ds.description[ds.target_name]
    if mapping is not None:
        # in case of multiple targets
        if isinstance(target, pd.Series):
            target = target.replace(mapping).to_list()
        # in case of single value target
        else:
            target = mapping[target]

    if lazy_metadata:
        factory = _FixedLengthWindowFunctions(
            start_offset_samples,
            last_potential_start,
            window_stride_samples,
            window_size_samples,
            target,
        )
        metadata = _LazyDataFrame(
            length=factory.length,
            functions={
                "i_window_in_trial": factory.i_window_in_trial,
                "i_start_in_trial": factory.i_start_in_trial,
                "i_stop_in_trial": factory.i_stop_in_trial,
                "target": factory.target,
            },
            columns=[
                "i_window_in_trial",
                "i_start_in_trial",
                "i_stop_in_trial",
                "target",
            ],
        )
    else:
        # already includes last incomplete window start
        starts = np.arange(
            start_offset_samples, last_potential_start + 1, window_stride_samples
        )

        if not drop_last_window and starts[-1] < last_potential_start:
            # if last window does not end at trial stop, make it stop there
            starts = np.append(starts, last_potential_start)

        metadata = pd.DataFrame(
            {
                "i_window_in_trial": np.arange(len(starts)),
                "i_start_in_trial": starts,
                "i_stop_in_trial": starts + window_size_samples,
                "target": len(starts) * [target],
            }
        )

    window_kwargs.append(
        (
            EEGWindowsDataset.__name__,
            {"targets_from": targets_from, "last_target_only": last_target_only},
        )
    )
    windows_ds = EEGWindowsDataset(
        ds.raw,
        metadata=metadata,
        description=ds.description,
        targets_from=targets_from,
        last_target_only=last_target_only,
    )
    # add window_kwargs and raw_preproc_kwargs to windows dataset
    setattr(windows_ds, "window_kwargs", window_kwargs)
    kwargs_name = "raw_preproc_kwargs"
    if hasattr(ds, kwargs_name):
        setattr(windows_ds, kwargs_name, getattr(ds, kwargs_name))
    return windows_ds
Create WindowsDataset from BaseDataset with sliding windows.

    Parameters
    ----------
    ds : BaseDataset
        Dataset containing continuous data and description.

    See `create_fixed_length_windows` for description of other parameters.

    Returns
    -------
    WindowsDataset :
        Windowed dataset.
    
braindecode/preprocessing/windowers.py