code: def compress_group_index(
      group_index: npt.NDArray[np.int64], sort: bool = True
  ) -> tuple[npt.NDArray[np.int64], npt.NDArray[np.int64]]:
      """
      Group_index is offsets into cartesian product of all possible labels. This
      space can be huge, so this function compresses it, by computing offsets
      (comp_ids) into the list of unique labels (obs_group_ids).
      """
      size_hint = len(group_index)
      table = hashtable.Int64HashTable(size_hint)
  
      group_index = ensure_int64(group_index)
  
      # note, group labels come out ascending (ie, 1,2,3 etc)
      comp_ids, obs_group_ids = table.get_labels_groupby(group_index)
  
      if sort and len(obs_group_ids) > 0:
          obs_group_ids, comp_ids = _reorder_by_uniques(
              obs_group_ids, comp_ids
          )
  
      return ensure_int64(comp_ids), ensure_int64(obs_group_ids)
  
imports: from __future__ import annotations
  from collections import defaultdict
  from typing import TYPE_CHECKING, Callable, DefaultDict, Hashable, Iterable, Sequence, cast
  import numpy
  from pandas._libs import algos, hashtable, lib
  from pandas._libs.hashtable import unique_label_indices
  from pandas._typing import AxisInt, IndexKeyFunc, Level, NaPosition, Shape, SortKind, npt
  from pandas.core.dtypes.common import ensure_int64, ensure_platform_int, is_extension_array_dtype
  from pandas.core.dtypes.generic import ABCMultiIndex, ABCRangeIndex
  from pandas.core.dtypes.missing import isna
  from pandas.core.construction import extract_array
label_desc: Use image node_id 17 for calling a global function with example usage: compress_group_index(group_index, sort) and returns: ensure_int64,  ensure_int64