code: def raise_on_incompatible(left, right) -> IncompatibleFrequency:
      """
      Helper function to render a consistent error message when raising
      IncompatibleFrequency.
  
      Parameters
      ----------
      left : PeriodArray
      right : None, DateOffset, Period, ndarray, or timedelta-like
  
      Returns
      -------
      IncompatibleFrequency
          Exception to be raised by the caller.
      """
      # GH#24283 error message format depends on whether right is scalar
      if (
          isinstance(right, (np.ndarray, ABCTimedeltaArray))
          or right is None
      ):
          other_freq = None
      elif isinstance(right, BaseOffset):
          other_freq = freq_to_period_freqstr(right.n, right.name)
      elif isinstance(right, (ABCPeriodIndex, PeriodArray, Period)):
          other_freq = right.freqstr
      else:
          other_freq = delta_to_tick(Timedelta(right)).freqstr
  
      own_freq = freq_to_period_freqstr(left.freq.n, left.freq.name)
      msg = DIFFERENT_FREQ.format(
          cls=type(left).__name__,
          own_freq=own_freq,
          other_freq=other_freq,
      )
      return IncompatibleFrequency(msg)
  
imports: from __future__ import annotations
  from datetime import timedelta
  import operator
  from typing import TYPE_CHECKING, Any, Callable, Literal, TypeVar, cast, overload
  import warnings
  import numpy
  from pandas._libs import algos, lib
  from pandas._libs.arrays import NDArrayBacked
  from pandas._libs.tslibs import BaseOffset, NaT, NaTType, Timedelta, add_overflowsafe, astype_overflowsafe, dt64arr_to_periodarr, get_unit_from_dtype, iNaT, parsing, period, to_offset
  from pandas._libs.tslibs.dtypes import FreqGroup, PeriodDtypeBase, freq_to_period_freqstr
  from pandas._libs.tslibs.fields import isleapyear_arr
  from pandas._libs.tslibs.offsets import Tick, delta_to_tick
  from pandas._libs.tslibs.period import DIFFERENT_FREQ, IncompatibleFrequency, Period, get_period_field_arr, period_asfreq_arr
  from pandas.util._decorators import cache_readonly, doc
  from pandas.util._exceptions import find_stack_level
  from pandas.core.dtypes.common import ensure_object, pandas_dtype
  from pandas.core.dtypes.dtypes import DatetimeTZDtype, PeriodDtype
  from pandas.core.dtypes.generic import ABCIndex, ABCPeriodIndex, ABCSeries, ABCTimedeltaArray
  from pandas.core.dtypes.missing import isna
  from pandas.core.arrays import datetimelike
  import pandas.core.common
label_desc: Use image node_id 2 for calling a global function with example usage: raise_on_incompatible(left, right) and returns: IncompatibleFrequency