code: def assert_categorical_equal(
      left,
      right,
      check_dtype: bool = True,
      check_category_order: bool = True,
      obj: str = "Categorical",
  ) -> None:
      """
      Test that Categoricals are equivalent.
  
      Parameters
      ----------
      left : Categorical
      right : Categorical
      check_dtype : bool, default True
          Check that integer dtype of the codes are the same.
      check_category_order : bool, default True
          Whether the order of the categories should be compared, which
          implies identical integer codes.  If False, only the resulting
          values are compared.  The ordered attribute is
          checked regardless.
      obj : str, default 'Categorical'
          Specify object name being compared, internally used to show appropriate
          assertion message.
      """
      _check_isinstance(left, right, Categorical)
  
      exact: bool | str
      if isinstance(left.categories, RangeIndex) or isinstance(
          right.categories, RangeIndex
      ):
          exact = "equiv"
      else:
          # We still want to require exact matches for Index
          exact = True
  
      if check_category_order:
          assert_index_equal(
              left.categories,
              right.categories,
              obj=f"{obj}.categories",
              exact=exact,
          )
          assert_numpy_array_equal(
              left.codes,
              right.codes,
              check_dtype=check_dtype,
              obj=f"{obj}.codes",
          )
      else:
          try:
              lc = left.categories.sort_values()
              rc = right.categories.sort_values()
          except TypeError:
              # e.g. '<' not supported between instances of 'int' and 'str'
              lc, rc = left.categories, right.categories
          assert_index_equal(
              lc, rc, obj=f"{obj}.categories", exact=exact
          )
          assert_index_equal(
              left.categories.take(left.codes),
              right.categories.take(right.codes),
              obj=f"{obj}.values",
              exact=exact,
          )
  
      assert_attr_equal("ordered", left, right, obj=obj)
  
imports: from __future__ import annotations
  import operator
  from typing import TYPE_CHECKING, Literal, NoReturn, cast
  import numpy
  from pandas._libs import lib
  from pandas._libs.missing import is_matching_na
  from pandas._libs.sparse import SparseIndex
  import pandas._libs.testing
  from pandas._libs.tslibs.np_datetime import compare_mismatched_resolutions
  from pandas.core.dtypes.common import is_bool, is_float_dtype, is_integer_dtype, is_number, is_numeric_dtype, needs_i8_conversion
  from pandas.core.dtypes.dtypes import CategoricalDtype, DatetimeTZDtype, ExtensionDtype, NumpyEADtype
  from pandas.core.dtypes.missing import array_equivalent
  import pandas
  from pandas import Categorical, DataFrame, DatetimeIndex, Index, IntervalDtype, IntervalIndex, MultiIndex, PeriodIndex, RangeIndex, Series, TimedeltaIndex
  from pandas.core.arrays import DatetimeArray, ExtensionArray, IntervalArray, PeriodArray, TimedeltaArray
  from pandas.core.arrays.datetimelike import DatetimeLikeArrayMixin
  from pandas.core.arrays.string_ import StringDtype
  from pandas.core.indexes.api import safe_sort_index
  from pandas.io.formats.printing import pprint_thing
label_desc: Use image node_id 9 for calling a global function with example usage: assert_categorical_equal(left, right, check_dtype, check_category_order, obj) without return types