code: def set_hier_freq(x):
      """Set frequency for multiindex dataframes without frequency.
  
      As of pandas 1.5.1, only a pd.PeriodIndex time index can have freq other None in
      a pandas multiindex data set. A DatetimeIndex will always have a frequency equal
      to None.
      This function converts the DatetimeIndex to a PeriodIndex, which supports
      frequency arguments.
  
      Parameters
      ----------
      y : Panel, or Hierarchical object, or VectorizedDF with timeindex as
          pd.DatetimeIndex or pd.PeriodIndex
  
      Returns
      -------
      Series, Panel, or Hierarchical object, or VectorizedDF with pd.PeriodIndex as
      time index and freq set.
      """
      if not isinstance(x.index, pd.MultiIndex):
          raise ValueError("Only intended for use with MultiIndex.")
  
      timepoints = get_time_index(x)
      if not isinstance(timepoints, (pd.DatetimeIndex)):
          raise ValueError("Set_freq only supported for DatetimeIndex.")
  
      if timepoints.freq is not None:
          warnings.warn("Frequency already set.", stacklevel=2)
      else:
          time_names = x.index.names[-1]
          x = (
              x.reset_index(-1)
              .groupby(level=0, group_keys=True)
              .apply(lambda df: df.set_index(time_names).to_period())
          )
      return x
  
file_path: sktime/sktime/utils/datetime.py
imports: import warnings
  from functools import singledispatch
  from typing import Optional, Tuple, Union
  import numpy
  import pandas
  from sktime.datatypes import VectorizedDF
  from sktime.datatypes._utilities import get_time_index
  from sktime.utils.validation.series import check_time_index, is_integer_index
label_desc: Use image node_id 4 for calling a global function with example usage: set_hier_freq(x) and returns: x