def extract_subseries(
    series: TimeSeries, min_gap_size: Optional[int] = 1, mode: str = "all"
) -> list[TimeSeries]:
    """
    Partitions the series into a sequence of sub-series by using significant gaps of missing values

    Parameters
    ----------
    series
        The TimeSeries to partition into sub-series

    min_gap_size
        The minimum number of contiguous missing values to consider a gap as significant. Defaults to 1.

    mode
        Only for multivariate TimeSeries. The definition of a gap; presence of a NaN in any column ("any")
        or NaNs in all the columns ("all") for a given timestamp. Defaults to "all".

    Returns
    -------
    subseries
        A list of TimeSeries, sub-series without significant gaps of missing values

    See Also
    --------
    TimeSeries.gaps : return the gaps in the TimeSeries
    """

    # Remove null values from the series extremes
    series = series.strip()
    freq = series.freq

    if series.to_dataframe().isna().sum().sum() == 0:
        return [series]

    # Get start/end times of sub-series without gaps of missing values
    gaps_df = series.gaps(mode=mode)
    if gaps_df.empty:
        return series
    else:
        gaps_df = gaps_df.query(f"gap_size>={min_gap_size}")
        start_times = [series.start_time()] + (gaps_df["gap_end"] + freq).to_list()
        end_times = (gaps_df["gap_start"] - freq).to_list() + [series.end_time() + freq]

        subseries = []
        for start, end in zip(start_times, end_times):
            subseries.append(series[start:end])

        return subseries

    Partitions the series into a sequence of sub-series by using significant gaps of missing values

    Parameters
    ----------
    series
        The TimeSeries to partition into sub-series

    min_gap_size
        The minimum number of contiguous missing values to consider a gap as significant. Defaults to 1.

    mode
        Only for multivariate TimeSeries. The definition of a gap; presence of a NaN in any column ("any")
        or NaNs in all the columns ("all") for a given timestamp. Defaults to "all".

    Returns
    -------
    subseries
        A list of TimeSeries, sub-series without significant gaps of missing values

    See Also
    --------
    TimeSeries.gaps : return the gaps in the TimeSeries
    
darts/utils/missing_values.py