code: def _get_cutoff_from_index(
      idx, return_index=False, reverse_order=False
  ):
      """Get cutoff = latest time point of pandas index.
  
      Assumptions on obj are not checked, these should be validated separately.
      Function may return unexpected results without prior validation.
  
      Parameters
      ----------
      obj : pd.Index, possibly MultiIndex, with last level assumed timelike or integer,
          e.g., as in the pd.DataFrame, pd-multiindex, or pd_multiindex_hier mtypes
      return_index : bool, optional, default=False
          whether a pd.Index object should be returned (True)
              or a pandas compatible index element (False)
          note: return_index=True may set freq attribute of time types to None
              return_index=False will typically preserve freq attribute
      reverse_order : bool, optional, default=False
          if False, returns largest time index. If True, returns smallest time index
  
      Returns
      -------
      cutoff_index : pandas compatible index element (if return_index=False)
          pd.Index of length 1 (if return_index=True)
      """
      if not isinstance(idx, pd.Index):
          raise TypeError(
              f"idx must be a pd.Index, but found type {type(idx)}"
          )
  
      # define "first" or "last" index depending on which is desired
      if reverse_order:
          ix = 0
          agg = min
      else:
          ix = -1
          agg = max
  
      if isinstance(idx, pd.MultiIndex):
          tdf = pd.DataFrame(index=idx)
          hix = idx.droplevel(-1)
          freq = None
          cutoff = None
          for hi in hix:
              ss = tdf.loc[hi].index
              if hasattr(ss, "freq") and ss.freq is not None:
                  freq = ss.freq
              if cutoff is not None:
                  cutoff = agg(cutoff, ss[ix])
              else:
                  cutoff = ss[ix]
          time_idx = idx.get_level_values(-1).sort_values()
          time_idx = pd.Index([cutoff])
          time_idx.freq = freq
      else:
          time_idx = idx
          if hasattr(idx, "freq") and idx.freq is not None:
              freq = idx.freq
          else:
              freq = None
  
      if not return_index:
          return time_idx[ix]
      res = time_idx[[ix]]
      if hasattr(time_idx, "freq") and time_idx.freq is not None:
          res.freq = time_idx.freq
      return res
  
file_path: sktime/sktime/datatypes/_utilities.py
imports: import numpy
  import pandas
label_desc: Use image node_id 4 for calling a global function with example usage: _get_cutoff_from_index(idx, return_index, reverse_order) and returns: res, time_idx