code: def test_bagging_sample_execution(
      setup,
      use_dataframe,
      max_samples,
      max_features,
      with_labels,
      with_weights,
  ):
      rs = np.random.RandomState(0)
  
      raw_data = rs.randint(100, size=(100, 50))
      if not use_dataframe:
          t = mt.tensor(raw_data, chunk_size=20)
      else:
          raw_data = pd.DataFrame(raw_data)
          t = md.DataFrame(raw_data, chunk_size=20)
  
      raw_labels = rs.choice([0, 1, 2], size=100)
      raw_weights = rs.random(100)
      labels = (
          mt.tensor(raw_labels, chunk_size=20) if with_labels else None
      )
      weights = (
          mt.tensor(raw_weights, chunk_size=20)
          if with_weights
          else None
      )
  
      sample_op = BaggingSample(
          n_estimators=10,
          max_samples=max_samples,
          max_features=max_features,
          random_state=rs,
      )
      result_tuple = execute(*sample_op(t, labels, weights))
      (
          t_sampled,
          t_labels,
          t_weights,
          t_feature_indices,
      ) = _extract_bagging_io(result_tuple, sample_op, output=True)
  
      label_chunks, weights_chunks, feature_idx_chunks = (
          dict(),
          dict(),
          dict(),
      )
  
      for t, chunks_dict in zip(
          (t_labels, t_weights), (label_chunks, weights_chunks)
      ):
          if t is None:
              continue
          for tiled, chunk, chunk_data in _get_tileable_chunk_data(
              setup, t
          ):
              assert len(tiled.chunks) == 5
              chunks_dict[chunk.index] = chunk_data
              for d in chunk_data:
                  assert d.shape == (10,)
  
      if t_feature_indices is not None:
          for tiled, chunk, chunk_data in _get_tileable_chunk_data(
              setup, t_feature_indices
          ):
              assert len(tiled.chunks) == 5
              feature_idx_chunks[chunk.index] = chunk_data
              assert chunk_data.shape == (
                  2,
                  int(max_features * raw_data.shape[1]),
              )
  
      for tiled, chunk, chunk_data in _get_tileable_chunk_data(
          setup, t_sampled
      ):
          assert len(tiled.chunks) == 5
          assert len(chunk_data) == 2
          for est_id, d in enumerate(chunk_data):
              assert d.shape == (
                  10,
                  int(max_features * raw_data.shape[1]),
              )
  
              if use_dataframe:
                  raw_sliced = raw_data.loc[d.index]
                  if label_chunks:
                      label_chunk = label_chunks[(chunk.index[0],)][
                          est_id
                      ]
                      np.testing.assert_array_equal(
                          raw_labels[d.index], label_chunk
                      )
                  if weights_chunks:
                      weights_chunk = weights_chunks[(chunk.index[0],)][
                          est_id
                      ]
                      np.testing.assert_array_equal(
                          raw_weights[d.index], weights_chunk
                      )
  
                  if feature_idx_chunks:
                      feature_indices_chunk = feature_idx_chunks[
                          chunk.index
                      ][est_id]
                      raw_sliced = raw_sliced.iloc[
                          :, feature_indices_chunk
                      ]
                  pd.testing.assert_frame_equal(raw_sliced, d)
  
file_path: mars/mars/learn/ensemble/tests/test_bagging.py
imports: import asyncio
  import os
  import numpy
  import pandas
  import pytest
  from sklearn.datasets import make_classification, make_regression
  from sklearn.linear_model import LinearRegression, LogisticRegression
  from sklearn.svm import SVC
  from ....None import tensor, dataframe, execute
  from ....conftest import MARS_CI_BACKEND
  from ....core import enter_mode
  from ....services.task.execution.api import Fetcher
  from .._bagging import _extract_bagging_io, BaggingSample, BaggingSampleReindex, BaggingClassifier, BaggingRegressor
label_desc: Use image node_id 2 for calling a global function with example usage: test_bagging_sample_execution(setup, use_dataframe, max_samples, max_features, with_labels, with_weights) without return types