code: def subsample(
      X: Union[np.ndarray, spmatrix],
      y: np.ndarray,
      is_classification: bool,
      sample_size: Union[float, int],
      random_state: Optional[Union[int, np.random.RandomState]] = None,
  ) -> Tuple[Union[np.ndarray, spmatrix], np.ndarray]:
      """Subsamples data returning the same type as it recieved.
  
      If `is_classification`, we split using a stratified shuffle split which
      preserves unique labels in the training set.
  
      NOTE:
      It's highly unadvisable to use lists here. In order to preserver types,
      we convert to a numpy array and then back to a list.
  
      NOTE2:
      Interestingly enough, StratifiedShuffleSplut and descendants don't support
      sparse `y` in `split(): _check_array` call. Hence, neither do we.
  
      Parameters
      ----------
      X: Union[np.ndarray, spmatrix]
          The X's to subsample
  
      y: np.ndarray
          The Y's to subsample
  
      is_classification: bool
          Whether this is classification data or regression data. Required for
          knowing how to split.
  
      sample_size: float | int
          If float, percentage of data to take otherwise if int, an absolute
          count of samples to take.
  
      random_state: int | RandomState = None
          The random state to pass to the splitted
  
      Returns
      -------
      (np.ndarray | spmatrix, np.ndarray)
          The X and y subsampled according to sample_size
      """
      if isinstance(X, List):
          X = np.asarray(X)
  
      if isinstance(y, List):
          y = np.asarray(y)
  
      if is_classification:
          splitter = CustomStratifiedShuffleSplit(
              train_size=sample_size, random_state=random_state
          )
          left_idxs, _ = next(splitter.split(X=X, y=y))
  
          # This function supports pandas objects but they won't get here
          # yet as we do not reduce the size of pandas dataframes.
          if isinstance(X, pd.DataFrame):
              idxs = X.index[left_idxs]
              X = X.loc[idxs]
          else:
              X = X[left_idxs]
  
          if isinstance(y, pd.DataFrame) or isinstance(y, pd.Series):
              idxs = y.index[left_idxs]
              y = y.loc[idxs]
          else:
              y = y[left_idxs]
  
      else:
          X, _, y, _ = train_test_split(  # type: ignore
              X,
              y,
              train_size=sample_size,
              random_state=random_state,
          )
  
      return X, y
  
imports: from typing import Any, Dict, Iterator, List, Mapping, Optional, Sequence, Tuple, Type, Union, cast
  import warnings
  import numpy
  import pandas
  from scipy.sparse import spmatrix
  from sklearn.model_selection import train_test_split
  from autosklearn.evaluation.splitter import CustomStratifiedShuffleSplit
label_desc: Use image node_id 7 for calling a global function with example usage: subsample(X, y, is_classification, sample_size, random_state) and returns: X,  y