code: def _split(
      y,
      X,
      train,
      test,
      freq=None,
  ):
      # split data according to cv
      y_train, y_test = y.iloc[train], y.iloc[test]
      X_train, X_test = None, None
  
      if X is not None:
          # For X_test, we select the full range of test/train values.
          # for those transformers that change the size of input.
          test_plus_train = np.append(train, test)
          X_train, X_test = (
              X.iloc[train].sort_index(),
              X.iloc[test_plus_train].sort_index(),
          )  # Defensive sort
  
      # Defensive assignment of freq
      if freq is not None:
          try:
              if y_train.index.nlevels == 1:
                  y_train.index.freq = freq
                  y_test.index.freq = freq
              else:
                  # See: https://github.com/pandas-dev/pandas/issues/33647
                  y_train.index.levels[-1].freq = freq
                  y_test.index.levels[-1].freq = freq
          except (
              AttributeError
          ):  # Can't set attribute for range or period index
              pass
  
          if X is not None:
              try:
                  if X.index.nlevels == 1:
                      X_train.index.freq = freq
                      X_test.index.freq = freq
                  else:
                      X_train.index.levels[-1].freq = freq
                      X_test.index.levels[-1].freq = freq
              except (
                  AttributeError
              ):  # Can't set attribute for range or period index
                  pass
  
      return y_train, y_test, X_train, X_test
  
file_path: sktime/sktime/forecasting/model_evaluation/_functions.py
imports: import time
  import warnings
  from typing import Dict, List, Optional, Union
  import numpy
  import pandas
  from sktime.datatypes import check_is_scitype, convert_to
  from sktime.exceptions import FitFailedWarning
  from sktime.forecasting.base import ForecastingHorizon
  from sktime.utils.parallel import parallelize
  from sktime.utils.validation._dependencies import _check_soft_dependencies
  from sktime.utils.validation.forecasting import check_cv, check_scoring
label_desc: Use image node_id 4 for calling a global function with example usage: _split(y, X, train, test, freq) and returns: y_train,  y_test,  X_train,  X_test