code: def sample(
      obj_len: int,
      size: int,
      replace: bool,
      weights: np.ndarray | None,
      random_state: np.random.RandomState | np.random.Generator,
  ) -> np.ndarray:
      """
      Randomly sample `size` indices in `np.arange(obj_len)`
  
      Parameters
      ----------
      obj_len : int
          The length of the indices being considered
      size : int
          The number of values to choose
      replace : bool
          Allow or disallow sampling of the same row more than once.
      weights : np.ndarray[np.float64] or None
          If None, equal probability weighting, otherwise weights according
          to the vector normalized
      random_state: np.random.RandomState or np.random.Generator
          State used for the random sampling
  
      Returns
      -------
      np.ndarray[np.intp]
      """
      if weights is not None:
          weight_sum = weights.sum()
          if weight_sum != 0:
              weights = weights / weight_sum
          else:
              raise ValueError("Invalid weights: weights sum to zero")
  
      return random_state.choice(
          obj_len, size=size, replace=replace, p=weights
      ).astype(np.intp, copy=False)
  
file_path: catboost/contrib/python/pandas/py3/pandas/core/sample.py
imports: from __future__ import annotations
  from typing import TYPE_CHECKING
  import numpy
  from pandas._libs import lib
  from pandas._typing import AxisInt
  from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries
label_desc: Use image node_id 3 for calling a global function with example usage: sample(obj_len, size, replace, weights, random_state) and returns: random_state