code: def _crop_to_match_seasons(
      series: TimeSeries, required_matches: Optional[set]
  ) -> TimeSeries:
      """Crops TimeSeries instance to contain full periods.
  
      Crops a given TimeSeries `series` that will be used as a training set in such
      a way that its first entry has a timestamp that matches the first timestamp
      right after the end of `series` in all attributes given in `required_matches`.
      If no such timestamp can be found, the original TimeSeries instance is returned.
      If the value of `required_matches` is `None`, the original TimeSeries instance is returned.
  
      Parameters
      ----------
      series
          TimeSeries instance to be cropped.
      required_matches
          A set of pd.Timestamp attributes which will be used to choose the cropping point.
  
      Returns
      -------
      TimeSeries
          New TimeSeries instance that is cropped as described above.
      """
      if required_matches is None or len(required_matches) == 0:
          return series
  
      first_ts = series.time_index[0]
      freq = series.freq
      pred_ts = series.time_index[-1] + freq
  
      # start at first timestamp of given series and move forward until a matching timestamp is found
      curr_ts = first_ts
      while curr_ts < pred_ts - 4 * freq:
          curr_ts += freq
          if _compare_timestamps_on_attributes(
              pred_ts, curr_ts, required_matches
          ):
              new_series = series.drop_before(curr_ts)
              return new_series
  
      logger.warning(
          "No matching timestamp could be found, returning original TimeSeries."
      )
      return series
  
imports: from typing import Callable, Optional
  import numpy
  import pandas
  from statsmodels.tsa.stattools import acf
  from darts.logging import get_logger
  from darts.models.forecasting.forecasting_model import LocalForecastingModel
  from darts.timeseries import TimeSeries
  from darts.utils.missing_values import fill_missing_values
label_desc: Use image node_id 4 for calling a global function with example usage: _crop_to_match_seasons(series, required_matches) and returns: series, series, new_series