code: def _sample_groupby_iter(
      groupby,
      obj_index,
      n,
      frac,
      replace,
      weights,
      random_state=None,
      errors="ignore",
  ):
      if weights is None:
          ws = [None] * groupby.ngroups
      elif not isinstance(weights, Iterable) or isinstance(
          weights, str
      ):
          ws = [weights] * groupby.ngroups
      else:
          weights = pd.Series(weights, index=obj_index)
          ws = [weights.iloc[idx] for idx in groupby.indices.values()]
  
      group_iterator = groupby.grouper.get_iterator(
          groupby._selected_obj
      )
      if not replace and errors == "ignore":
          for (_, obj), w in zip(group_iterator, ws):
              yield obj.sample(
                  n=n,
                  frac=frac,
                  replace=replace,
                  weights=w,
                  random_state=random_state,
              ) if len(obj) > n else obj
      else:
          for (_, obj), w in zip(group_iterator, ws):
              yield obj.sample(
                  n=n,
                  frac=frac,
                  replace=replace,
                  weights=w,
                  random_state=random_state,
              )
  
imports: import copy
  import itertools
  import random
  from collections.abc import Iterable
  from typing import Optional, Sequence, Union
  import numpy
  import pandas
  from ...None import opcodes
  from ...core import ENTITY_TYPE, OutputType, get_output_types, recursive_tile
  from ...core.operand import OperandStage, MapReduceOperand
  from ...serialization.serializables import BoolField, DictField, Float32Field, KeyField, Int32Field, Int64Field, NDArrayField, StringField
  from ...tensor.operands import TensorShuffleProxy
  from ...tensor.random import RandomStateField
  from ...tensor.utils import gen_random_seeds
  from ...utils import has_unknown_shape
  from ..initializer import Series
  from ..operands import DataFrameOperandMixin, DataFrameOperand
  from ..utils import parse_index
label_desc: Use image node_id 1 for calling a global function with example usage: _sample_groupby_iter(groupby, obj_index, n, frac, replace, weights, random_state, errors) without return types