code: def _safe_indexing(X, indices, *, axis=0):
      """Return rows, items or columns of X using indices.
  
      Parameters
      ----------
      X : array-like, sparse-matrix, list, dataframes, series data
          from which to sample rows, items or columns. `list` are only
          supported when `axis=0`.
      indices : bool, int, str, slice, array-like
          - If `axis=0`, boolean and integer array-like, integer slice,
            and scalar integer are supported.
          - If `axis=1`:
              - to select a single column, `indices` can be of `int` type for
                all `X` types and `str` only for dataframe. The selected subset
                will be 1D, unless `X` is a sparse matrix in which case it will
                be 2D.
              - to select multiples columns, `indices` can be one of the
                following: `list`, `array`, `slice`. The type used in
                these containers can be one of the following: `int`, 'bool' and
                `str`. However, `str` is only supported when `X` is a dataframe.
                The selected subset will be 2D.
      axis : int, default=0
          The axis along which `X` will be subsampled. `axis=0` will select
          rows while `axis=1` will select columns.
  
      Returns
      -------
      subset
          Subset of X on axis 0 or 1.
  
      Notes
      -----
      CSR, CSC, and LIL sparse matrices are supported. COO sparse matrices are
      not supported.
      """
      if indices is None:
          return X
  
      if axis not in (0, 1):
          raise ValueError(
              "'axis' should be either 0 (to index rows) or 1 (to index "
              " column). Got {} instead.".format(axis)
          )
  
      if isinstance(indices, (pd.Index, cudf.Index)):
          indices = list(indices)
  
      indices_dtype = _determine_key_type(indices)
  
      if axis == 0 and indices_dtype == "str":
          raise ValueError(
              "String indexing is not supported with 'axis=0'"
          )
  
      if axis == 1 and X.ndim != 2:
          raise ValueError(
              "'X' should be a 2D NumPy array, 2D sparse matrix or pandas "
              "dataframe when indexing the columns (i.e. 'axis=1'). "
              "Got {} instead with {} dimension(s).".format(
                  type(X), X.ndim
              )
          )
  
      if axis == 1 and indices_dtype == "str" and not hasattr(X, "loc"):
          raise ValueError(
              "Specifying the columns using strings is only supported for "
              "pandas DataFrames"
          )
  
      if hasattr(X, "iloc"):
          return _pandas_indexing(X, indices, indices_dtype, axis=axis)
      elif hasattr(X, "shape"):
          return _array_indexing(X, indices, indices_dtype, axis=axis)
      else:
          return _list_indexing(X, indices, indices_dtype)
  
imports: from ..preprocessing import FunctionTransformer
  from ....thirdparty_adapters import check_array
  from ..utils.validation import check_is_fitted
  from ..utils.skl_dependencies import TransformerMixin, BaseComposition, BaseEstimator
  from cuml.internals import _deprecate_pos_args
  from cuml.internals.array_sparse import SparseCumlArray
  from cuml.internals.global_settings import _global_settings_data
  import cuml
  from itertools import chain
  from itertools import compress
  from joblib import Parallel
  import functools
  import timeit
  import numbers
  from cuml.internals.import_utils import has_sklearn
  from contextlib import contextmanager
  from collections import defaultdict
  import warnings
  from cuml.internals.safe_imports import cpu_only_import_from
  from cuml.internals.safe_imports import gpu_only_import_from
  from cuml.internals.safe_imports import cpu_only_import
  from cuml.internals.safe_imports import gpu_only_import
label_desc: Use image node_id 4 for calling a global function with example usage: _safe_indexing(X, indices) and returns: X, _pandas_indexing, _array_indexing, _list_indexing