code: def _safe_indexing(X, indices, axis=0):
      """Return rows, items or columns of X using indices"""
      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)
          )
  
      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: import numbers
  import numpy
  from itertools import compress
  from scipy.sparse import issparse
  from sklearn.model_selection import ParameterGrid
  from sklearn.utils.validation import check_is_fitted
label_desc: Use image node_id 11 for calling a global function with example usage: _safe_indexing(X, indices, axis) and returns: X, _pandas_indexing, _array_indexing, _list_indexing