def _apply_inverse_data_transformers(
    series: Union[TimeSeries, Sequence[TimeSeries]],
    forecasts: Union[TimeSeries, list[TimeSeries], list[list[TimeSeries]]],
    data_transformers: dict[str, Pipeline],
    series_idx: Optional[int] = None,
) -> Union[TimeSeries, list[TimeSeries], list[list[TimeSeries]]]:
    """
    Apply the inverse transform to the forecasts when defined.

    `series_idx` is used to retrieve the appropriate transformer when the data transformer was
    fitted with several series and global_fit=False.
    """
    if "series" in data_transformers and data_transformers["series"].invertible:
        called_with_single_series = get_series_seq_type(series) == SeriesType.SINGLE
        if called_with_single_series:
            forecasts = [forecasts]
        forecasts = data_transformers["series"].inverse_transform(
            forecasts, series_idx=series_idx
        )
        return forecasts[0] if called_with_single_series else forecasts
    else:
        return forecasts

    Apply the inverse transform to the forecasts when defined.

    `series_idx` is used to retrieve the appropriate transformer when the data transformer was
    fitted with several series and global_fit=False.
    
darts/utils/historical_forecasts/utils.py