class_docstr: Forecasting horizon.
  
  Parameters
  ----------
  values : pd.Index, pd.TimedeltaIndex, np.array, list, pd.Timedelta, or int
      Values of forecasting horizon
  is_relative : bool, optional (default=None)
      - If True, a relative ForecastingHorizon is created:
              values are relative to end of training series.
      - If False, an absolute ForecastingHorizon is created:
              values are absolute.
      - if None, the flag is determined automatically:
          relative, if values are of supported relative index type
          absolute, if not relative and values of supported absolute index type
  freq : str, pd.Index, pandas offset, or sktime forecaster, optional (default=None)
      object carrying frequency information on values
      ignored unless values is without inferable freq
  
  Examples
  --------
  >>> from sktime.forecasting.base import ForecastingHorizon
  >>> from sktime.forecasting.naive import NaiveForecaster
  >>> from sktime.datasets import load_airline
  >>> from sktime.split import temporal_train_test_split
  >>> import numpy as np
  >>> y = load_airline()
  >>> y_train, y_test = temporal_train_test_split(y, test_size=6)
  
      List as ForecastingHorizon
  
  >>> ForecastingHorizon([1, 2, 3])  # doctest: +SKIP
  >>> # ForecastingHorizon([1, 2, 3], is_relative=True)
  
      Numpy as ForecastingHorizon
  
  >>> ForecastingHorizon(np.arange(1, 7))  # doctest: +SKIP
  >>> # ForecastingHorizon([1, 2, 3, 4, 5, 6], is_relative=True)
  
      Absolute ForecastingHorizon with a pandas Index
  
  >>> ForecastingHorizon(y_test.index, is_relative=False) # doctest: +SKIP
  >>> # ForecastingHorizon(['1960-07', ..., '1960-12'], is_relative=False)
  
      Converting
  
  >>> # set cutoff (last time point of training data)
  >>> cutoff = y_train.index[-1]
  >>> cutoff
  Period('1960-06', 'M')
  >>> # to_relative
  >>> fh = ForecastingHorizon(y_test.index, is_relative=False)
  >>> fh.to_relative(cutoff=cutoff)  # doctest: +SKIP
  >>> # ForecastingHorizon([1, 2, 3, 4, 5, 6], is_relative=True)
  
  >>> # to_absolute
  >>> fh = ForecastingHorizon([1, 2, 3, 4, 5, 6], is_relative=True)
  >>> fh = fh.to_absolute(cutoff=cutoff) # doctest: +SKIP
  >>> # ForecastingHorizon(['1960-07', ..., '1960-12'], is_relative=False)
  
      Automatically casted ForecastingHorizon from list when calling predict()
  
  >>> forecaster = NaiveForecaster(strategy="drift")
  >>> forecaster.fit(y_train)
  NaiveForecaster(...)
  >>> y_pred = forecaster.predict(fh=[1,2,3])
  >>> forecaster.fh  # doctest: +SKIP
  >>> # ForecastingHorizon([1, 2, 3], dtype='int64', is_relative=True)
  
      This is identical to give an object of ForecastingHorizon
  
  >>> y_pred = forecaster.predict(fh=ForecastingHorizon([1,2,3]))
  >>> forecaster.fh  # doctest: +SKIP
  >>> # ForecastingHorizon([1, 2, 3], dtype='int64', is_relative=True)
class_docstr_tok: ["Forecasting","horizon",".","Parameters","--","--","--","--","--","values",":","pd.Index",",","pd.TimedeltaIndex",",","np.array",",","list",",","pd.Timedelta",",","or","int","Values","of","forecasting","horizon","is_relative",":","bool",",","optional","(","default=None",")","-","If","True",",","a","relative","ForecastingHorizon","is","created",":","values","are","relative","to","end","of","training","series",".","-","If","False",",","an","absolute","ForecastingHorizon","is","created",":","values","are","absolute",".","-","if","None",",","the","flag","is","determined","automatically",":","relative",",","if","values","are","of","supported","relative","index","type","absolute",",","if","not","relative","and","values","of","supported","absolute","index","type","freq",":","str",",","pd.Index",",","pandas","offset",",","or","sktime","forecaster",",","optional","(","default=None",")","object","carrying","frequency","information","on","values","ignored","unless","values","is","without","inferable","freq","Examples","--","--","--","--",">",">",">","from","sktime.forecasting.base","import","ForecastingHorizon",">",">",">","from","sktime.forecasting.naive","import","NaiveForecaster",">",">",">","from","sktime.datasets","import","load_airline",">",">",">","from","sktime.split","import","temporal_train_test_split",">",">",">","import","numpy","as","np",">",">",">","y","=","load_airline","(",")",">",">",">","y_train",",","y_test","=","temporal_train_test_split","(","y",",","test_size=6",")","List","as","ForecastingHorizon",">",">",">","ForecastingHorizon","(","[","1",",","2",",","3","]",")","#","doctest",":","+SKIP",">",">",">","#","ForecastingHorizon","(","[","1",",","2",",","3","]",",","is_relative=True",")","Numpy","as","ForecastingHorizon",">",">",">","ForecastingHorizon","(","np.arange","(","1",",","7",")",")","#","doctest",":","+SKIP",">",">",">","#","ForecastingHorizon","(","[","1",",","2",",","3",",","4",",","5",",","6","]",",","is_relative=True",")","Absolute","ForecastingHorizon","with","a","pandas","Index",">",">",">","ForecastingHorizon","(","y_test.index",",","is_relative=False",")","#","doctest",":","+SKIP",">",">",">","#","ForecastingHorizon","(","[","'1960-07","'",",","...",",","'1960-12","'","]",",","is_relative=False",")","Converting",">",">",">","#","set","cutoff","(","last","time","point","of","training","data",")",">",">",">","cutoff","=","y_train.index","[","-1","]",">",">",">","cutoff","Period","(","'1960-06","'",",","'M","'",")",">",">",">","#","to_relative",">",">",">","fh","=","ForecastingHorizon","(","y_test.index",",","is_relative=False",")",">",">",">","fh.to_relative","(","cutoff=cutoff",")","#","doctest",":","+SKIP",">",">",">","#","ForecastingHorizon","(","[","1",",","2",",","3",",","4",",","5",",","6","]",",","is_relative=True",")",">",">",">","#","to_absolute",">",">",">","fh","=","ForecastingHorizon","(","[","1",",","2",",","3",",","4",",","5",",","6","]",",","is_relative=True",")",">",">",">","fh","=","fh.to_absolute","(","cutoff=cutoff",")","#","doctest",":","+SKIP",">",">",">","#","ForecastingHorizon","(","[","'1960-07","'",",","...",",","'1960-12","'","]",",","is_relative=False",")","Automatically","casted","ForecastingHorizon","from","list","when","calling","predict","(",")",">",">",">","forecaster","=","NaiveForecaster","(","strategy=","''","drift","''",")",">",">",">","forecaster.fit","(","y_train",")","NaiveForecaster","(","...",")",">",">",">","y_pred","=","forecaster.predict","(","fh=","[","1,2,3","]",")",">",">",">","forecaster.fh","#","doctest",":","+SKIP",">",">",">","#","ForecastingHorizon","(","[","1",",","2",",","3","]",",","dtype='int64","'",",","is_relative=True",")","This","is","identical","to","give","an","object","of","ForecastingHorizon",">",">",">","y_pred","=","forecaster.predict","(","fh=ForecastingHorizon","(","[","1,2,3","]",")",")",">",">",">","forecaster.fh","#","doctest",":","+SKIP",">",">",">","#","ForecastingHorizon","(","[","1",",","2",",","3","]",",","dtype='int64","'",",","is_relative=True",")"]
docstr: Construct DataFrame Index expected in y_pred, return of _predict.
  
  Parameters
  ----------
  y : pd.DataFrame, pd.Series, pd.Index, or None
      data to compute fh relative to,
      assumed in sktime pandas based mtype or index thereof
      if None, assumes no MultiIndex
  cutoff : pd.Period, pd.Timestamp, int, or pd.Index, optional (default=None)
      Cutoff value to use in computing resulting index.
      If cutoff is not provided, is computed from ``y`` via ``get_cutoff``.
  sort_by_time : bool, optional (default=False)
      for MultiIndex returns, whether to sort by time index (level -1)
      - If True, result Index is sorted by time index (level -1)
      - If False, result Index is sorted overall
  
  Returns
  -------
  fh_idx : pd.Index, expected index of y_pred returned by predict
      assumes pandas based return mtype
code: def get_expected_pred_idx(
      self, y=None, cutoff=None, sort_by_time=False
  ):
      """Construct DataFrame Index expected in y_pred, return of _predict.
  
      Parameters
      ----------
      y : pd.DataFrame, pd.Series, pd.Index, or None
          data to compute fh relative to,
          assumed in sktime pandas based mtype or index thereof
          if None, assumes no MultiIndex
      cutoff : pd.Period, pd.Timestamp, int, or pd.Index, optional (default=None)
          Cutoff value to use in computing resulting index.
          If cutoff is not provided, is computed from ``y`` via ``get_cutoff``.
      sort_by_time : bool, optional (default=False)
          for MultiIndex returns, whether to sort by time index (level -1)
          - If True, result Index is sorted by time index (level -1)
          - If False, result Index is sorted overall
  
      Returns
      -------
      fh_idx : pd.Index, expected index of y_pred returned by predict
          assumes pandas based return mtype
      """
      from sktime.datatypes import get_cutoff
  
      def _make_y_pred(y_single):
          """Make y_pred from single instance y, used in list comprehension."""
          cutoff = get_cutoff(y_single)
          return pd.Index(self.to_absolute_index(cutoff))
  
      if hasattr(y, "index"):
          y_index = y.index
      elif isinstance(y, pd.Index):
          y_index = y
          y = pd.DataFrame(index=y_index)
      elif cutoff is None:
          y_index = pd.Index(y)
          y = pd.DataFrame(index=y_index)
      else:
          y_index = None
  
      if cutoff is None and not isinstance(y_index, pd.MultiIndex):
          _cutoff = get_cutoff(y)
      else:
          _cutoff = cutoff
  
      if cutoff is not None or not isinstance(y_index, pd.MultiIndex):
          fh_idx = pd.Index(self.to_absolute_index(_cutoff))
  
      if cutoff is not None and isinstance(y_index, pd.MultiIndex):
          y_inst_idx = y_index.droplevel(-1).unique().sort_values()
          if isinstance(y_inst_idx, pd.MultiIndex) and sort_by_time:
              fh_list = [x + (y,) for y in fh_idx for x in y_inst_idx]
          elif (
              isinstance(y_inst_idx, pd.MultiIndex) and not sort_by_time
          ):
              fh_list = [x + (y,) for x in y_inst_idx for y in fh_idx]
          elif (
              sort_by_time
          ):  # and not isinstance(y_inst_idx, pd.MultiIndex):
              fh_list = [(x, y) for y in fh_idx for x in y_inst_idx]
          else:  # not sort_by_time and not isinstance(y_inst_idx, pd.MultiIndex):
              fh_list = [(x, y) for x in y_inst_idx for y in fh_idx]
  
          fh_idx = pd.Index(fh_list)
  
      elif isinstance(y_index, pd.MultiIndex):
          y_inst_idx = y_index.droplevel(-1).unique()
  
          if isinstance(y_inst_idx, pd.MultiIndex):
              fh_list = [
                  x + (z,)
                  for x in y_inst_idx
                  for z in _make_y_pred(y.loc[x])
              ]
          else:
              fh_list = [
                  (x, z)
                  for x in y_inst_idx
                  for z in _make_y_pred(y.loc[x])
              ]
  
          fh_idx = pd.Index(fh_list)
  
          if sort_by_time:
              fh_df = pd.DataFrame(index=fh_idx)
              fh_idx = fh_df.sort_index(level=-1).index
  
      # replicating index names
      if hasattr(y_index, "names") and y_index.names is not None:
          fh_idx.names = y_index.names
  
      return fh_idx
  
imports: from functools import lru_cache
  from typing import Optional, Union
  import numpy
  import pandas
  from pandas.tseries.frequencies import to_offset
  from sktime.utils.datetime import _coerce_duration_to_int
  from sktime.utils.validation import array_is_int, array_is_timedelta_or_date_offset, is_array, is_int, is_timedelta_or_date_offset
  from sktime.utils.validation._dependencies import _check_soft_dependencies
  from sktime.utils.validation.series import VALID_INDEX_TYPES, is_in_valid_absolute_index_types, is_in_valid_index_types, is_in_valid_relative_index_types, is_integer_index
label_desc: Use image node_id 21 for calling the ForecastingHorizon obj's underlying member method code with example usage: obj.get_expected_pred_idx(y, cutoff, sort_by_time) and returns: fh_idx, pd