code: def test_groupby_sample(setup):
      rs = np.random.RandomState(0)
      sample_count = 10
      src_data_list = []
      for b in range(5):
          data_count = int(rs.randint(20, 100))
          src_data_list.append(
              pd.DataFrame(
                  {
                      "a": rs.randint(0, 100, size=data_count),
                      "b": np.array([b] * data_count),
                      "c": rs.randint(0, 100, size=data_count),
                      "d": rs.randint(0, 100, size=data_count),
                  }
              )
          )
      df1 = pd.concat(src_data_list)
      shuffle_idx = np.arange(len(df1))
      rs.shuffle(shuffle_idx)
      df1 = df1.iloc[shuffle_idx].reset_index(drop=True)
  
      # test single chunk
      mdf = md.DataFrame(df1)
  
      r1 = mdf.groupby("b").sample(sample_count, random_state=rs)
      result1 = r1.execute().fetch()
      r2 = mdf.groupby("b").sample(sample_count, random_state=rs)
      result2 = r2.execute().fetch()
      pd.testing.assert_frame_equal(result1, result2)
      assert not (result1.groupby("b").count() - sample_count).any()[0]
  
      r1 = mdf.groupby("b").sample(
          sample_count,
          weights=df1["c"] / df1["c"].sum(),
          random_state=rs,
      )
      result1 = r1.execute().fetch()
      r2 = mdf.groupby("b").sample(
          sample_count,
          weights=df1["c"] / df1["c"].sum(),
          random_state=rs,
      )
      result2 = r2.execute().fetch()
      pd.testing.assert_frame_equal(result1, result2)
      assert not (result1.groupby("b").count() - sample_count).any()[0]
  
      r1 = mdf.groupby("b")[["b", "c"]].sample(
          sample_count, random_state=rs
      )
      result1 = r1.execute().fetch()
      r2 = mdf.groupby("b")[["b", "c"]].sample(
          sample_count, random_state=rs
      )
      result2 = r2.execute().fetch()
      pd.testing.assert_frame_equal(result1, result2)
      assert len(result1.columns) == 2
      assert not (result1.groupby("b").count() - sample_count).any()[0]
  
      r1 = mdf.groupby("b").c.sample(sample_count, random_state=rs)
      result1 = r1.execute().fetch()
      r2 = mdf.groupby("b").c.sample(sample_count, random_state=rs)
      result2 = r2.execute().fetch()
      pd.testing.assert_series_equal(result1, result2)
  
      r1 = mdf.groupby("b").c.sample(len(df1), random_state=rs)
      result1 = r1.execute().fetch()
      assert len(result1) == len(df1)
  
      with pytest.raises(ValueError):
          r1 = mdf.groupby("b").c.sample(
              len(df1), random_state=rs, errors="raises"
          )
          r1.execute().fetch()
  
      # test multiple chunks
      mdf = md.DataFrame(df1, chunk_size=47)
  
      r1 = mdf.groupby("b").sample(sample_count, random_state=rs)
      result1 = r1.execute().fetch()
      r2 = mdf.groupby("b").sample(sample_count, random_state=rs)
      result2 = r2.execute().fetch()
      pd.testing.assert_frame_equal(result1, result2)
      assert not (result1.groupby("b").count() - sample_count).any()[0]
  
      r1 = mdf.groupby("b").sample(
          sample_count,
          weights=df1["c"] / df1["c"].sum(),
          random_state=rs,
      )
      result1 = r1.execute().fetch()
      r2 = mdf.groupby("b").sample(
          sample_count,
          weights=df1["c"] / df1["c"].sum(),
          random_state=rs,
      )
      result2 = r2.execute().fetch()
      pd.testing.assert_frame_equal(result1, result2)
      assert not (result1.groupby("b").count() - sample_count).any()[0]
  
      r1 = mdf.groupby("b")[["b", "c"]].sample(
          sample_count, random_state=rs
      )
      result1 = r1.execute().fetch()
      r2 = mdf.groupby("b")[["b", "c"]].sample(
          sample_count, random_state=rs
      )
      result2 = r2.execute().fetch()
      pd.testing.assert_frame_equal(result1, result2)
      assert len(result1.columns) == 2
      assert not (result1.groupby("b").count() - sample_count).any()[0]
  
      r1 = mdf.groupby("b").c.sample(sample_count, random_state=rs)
      result1 = r1.execute().fetch()
      r2 = mdf.groupby("b").c.sample(sample_count, random_state=rs)
      result2 = r2.execute().fetch()
      pd.testing.assert_series_equal(result1, result2)
  
      r1 = mdf.groupby("b").c.sample(len(df1), random_state=rs)
      result1 = r1.execute().fetch()
      assert len(result1) == len(df1)
  
      with pytest.raises(ValueError):
          r1 = mdf.groupby("b").c.sample(
              len(df1), random_state=rs, errors="raises"
          )
          r1.execute().fetch()
  
imports: from collections import OrderedDict
  import numpy
  import pandas
  import pytest
  from ....None import dataframe
  from ....config import option_context
  from ....core.operand import OperandStage
  from ....tests.core import assert_groupby_equal, require_cudf
  from ....utils import arrow_array_to_objects, pd_release_version
  from ...core import DATAFRAME_OR_SERIES_TYPE
  from ..aggregation import DataFrameGroupByAgg
label_desc: Use image node_id 17 for calling a global function with example usage: test_groupby_sample(setup) without return types