code: def _get_index_freq(index: Index) -> BaseOffset | None:
      freq = getattr(index, "freq", None)
      if freq is None:
          freq = getattr(index, "inferred_freq", None)
          if freq == "B":
              # error: "Index" has no attribute "dayofweek"
              weekdays = np.unique(index.dayofweek)  # type: ignore[attr-defined]
              if (5 in weekdays) or (6 in weekdays):
                  freq = None
  
      freq = to_offset(freq)
      return freq
  
imports: from __future__ import annotations
  from datetime import timedelta
  import functools
  from typing import TYPE_CHECKING, cast
  import numpy
  from pandas._libs.tslibs import BaseOffset, Period, to_offset
  from pandas._libs.tslibs.dtypes import FreqGroup
  from pandas.core.dtypes.generic import ABCDatetimeIndex, ABCPeriodIndex, ABCTimedeltaIndex
  from pandas.io.formats.printing import pprint_thing
  from pandas.plotting._matplotlib.converter import TimeSeries_DateFormatter, TimeSeries_DateLocator, TimeSeries_TimedeltaFormatter
  from pandas.tseries.frequencies import get_period_alias, is_subperiod, is_superperiod
label_desc: Use image node_id 11 for calling a global function with example usage: _get_index_freq(index) and returns: freq