code: def _coerce_duration_to_int(
      duration: Union[
          int, pd.Timedelta, pd.tseries.offsets.BaseOffset, pd.Index
      ],
      freq: str = None,
  ) -> Union[int, pd.Index]:
      """Coerce durations into integer representations for a given unit of duration.
  
      Parameters
      ----------
      duration : pd.DateOffset, pd.Timedelta, pd.TimedeltaIndex, pd.Index, int
          Duration type or collection of duration types
      freq : str
          Frequency of the above duration type.
  
      Returns
      -------
      ret : int
          Duration in integer values for given unit
      """
      if isinstance(duration, int):
          return duration
      elif isinstance(duration, pd.tseries.offsets.BaseOffset):
          return int(
              duration.n / _get_intervals_count_and_unit(freq)[0]
          )
      elif isinstance(duration, pd.Index) and isinstance(
          duration[0], pd.tseries.offsets.BaseOffset
      ):
          count = _get_intervals_count_and_unit(freq)[0]
          return pd.Index([d.n / count for d in duration], dtype=int)
      elif isinstance(duration, (pd.Timedelta, pd.TimedeltaIndex)):
          count, unit = _get_intervals_count_and_unit(freq)
          # integer conversion only works reliably with non-ambiguous units (
          # e.g. days, seconds but not months, years)
          try:
              if isinstance(duration, pd.Timedelta):
                  return int(duration / pd.Timedelta(count, unit))
              if isinstance(duration, pd.TimedeltaIndex):
                  return (duration / pd.Timedelta(count, unit)).astype(
                      int
                  )
          except ValueError:
              raise ValueError(
                  "Index type not supported. Please consider using pd.PeriodIndex."
              )
      else:
          raise TypeError("`duration` type not understood.")
  
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 1 for calling a global function with example usage: _coerce_duration_to_int(duration, freq) and returns: duration, int, pd, int, unknown