code: def infer_freq(index) -> str | None:
      """
      Infer the most likely frequency given the input index.
  
      Parameters
      ----------
      index : DatetimeIndex or TimedeltaIndex
        If passed a Series will use the values of the series (NOT THE INDEX).
  
      Returns
      -------
      str or None
          None if no discernible frequency.
  
      Raises
      ------
      TypeError
          If the index is not datetime-like.
      ValueError
          If there are fewer than three values.
  
      Examples
      --------
      >>> idx = pd.date_range(start='2020/12/01', end='2020/12/30', periods=30)
      >>> pd.infer_freq(idx)
      'D'
      """
      from pandas.core.api import (
          DatetimeIndex,
          Index,
      )
  
      if isinstance(index, ABCSeries):
          values = index._values
          if not (
              is_datetime64_dtype(values)
              or is_timedelta64_dtype(values)
              or values.dtype == object
          ):
              raise TypeError(
                  "cannot infer freq from a non-convertible dtype "
                  f"on a Series of {index.dtype}"
              )
          index = values
  
      inferer: _FrequencyInferer
  
      if not hasattr(index, "dtype"):
          pass
      elif is_period_dtype(index.dtype):
          raise TypeError(
              "PeriodIndex given. Check the `freq` attribute "
              "instead of using infer_freq."
          )
      elif is_timedelta64_dtype(index.dtype):
          # Allow TimedeltaIndex and TimedeltaArray
          inferer = _TimedeltaFrequencyInferer(index)
          return inferer.get_freq()
  
      if isinstance(index, Index) and not isinstance(
          index, DatetimeIndex
      ):
          if is_numeric_dtype(index):
              raise TypeError(
                  f"cannot infer freq from a non-convertible index of dtype {index.dtype}"
              )
          index = index._values
  
      if not isinstance(index, DatetimeIndex):
          index = DatetimeIndex(index)
  
      inferer = _FrequencyInferer(index)
      return inferer.get_freq()
  
imports: from __future__ import annotations
  import numpy
  from pandas._libs.algos import unique_deltas
  from pandas._libs.tslibs import Timestamp, get_unit_from_dtype, periods_per_day, tz_convert_from_utc
  from pandas._libs.tslibs.ccalendar import DAYS, MONTH_ALIASES, MONTH_NUMBERS, MONTHS, int_to_weekday
  from pandas._libs.tslibs.fields import build_field_sarray, month_position_check
  from pandas._libs.tslibs.offsets import DateOffset, Day, to_offset
  from pandas._libs.tslibs.parsing import get_rule_month
  from pandas._typing import npt
  from pandas.util._decorators import cache_readonly
  from pandas.core.dtypes.common import is_datetime64_dtype, is_numeric_dtype, is_period_dtype, is_timedelta64_dtype
  from pandas.core.dtypes.generic import ABCIndex, ABCSeries
  from pandas.core.algorithms import unique
label_desc: Use image node_id 2 for calling a global function with example usage: infer_freq(index) and returns: inferer, inferer