code: def _sanitize_confound_dtype(n_signal, confound):
      """Check confound is the correct datatype."""
      if isinstance(confound, pd.DataFrame):
          confound = confound.values
      if isinstance(confound, str):
          filename = confound
          confound = csv_to_array(filename)
          if np.isnan(confound.flat[0]):
              # There may be a header
              confound = csv_to_array(filename, skip_header=1)
          if confound.shape[0] != n_signal:
              raise ValueError(
                  "Confound signal has an incorrect "
                  f"lengthSignal length: {n_signal}; "
                  f"confound length: {confound.shape[0]}"
              )
      elif isinstance(confound, np.ndarray):
          if confound.ndim == 1:
              confound = np.atleast_2d(confound).T
          elif confound.ndim != 2:
              raise ValueError(
                  "confound array has an incorrect number "
                  f"of dimensions: {confound.ndim}"
              )
          if confound.shape[0] != n_signal:
              raise ValueError(
                  "Confound signal has an incorrect "
                  f"lengthSignal length: {n_signal}; "
                  f"confound length: {confound.shape[0]}."
              )
  
      else:
          raise TypeError(
              f"confound has an unhandled type: {confound.__class__}"
          )
      return confound
  
imports: import warnings
  import numpy
  import pandas
  from scipy import linalg, signal
  from scipy.interpolate import CubicSpline
  from sklearn.utils import as_float_array, gen_even_slices
  from nilearn._utils import fill_doc, stringify_path
  from nilearn._utils.numpy_conversions import as_ndarray, csv_to_array
  from nilearn._utils.param_validation import check_run_sample_masks
label_desc: Use image node_id 21 for calling a global function with example usage: _sanitize_confound_dtype(n_signal, confound) and returns: confound