code: def test_scaler(info, method):
      """Test methods of Scaler."""
      raw = io.read_raw_fif(raw_fname)
      events = read_events(event_name)
      picks = pick_types(
          raw.info,
          meg=True,
          stim=False,
          ecg=False,
          eog=False,
          exclude="bads",
      )
      picks = picks[1:13:3]
  
      epochs = Epochs(
          raw,
          events,
          event_id,
          tmin,
          tmax,
          picks=picks,
          baseline=(None, 0),
          preload=True,
      )
      epochs_data = epochs.get_data(copy=False)
      y = epochs.events[:, -1]
  
      epochs_data_t = epochs_data.transpose([1, 0, 2])
      if method in ("mean", "median"):
          if not check_version("sklearn"):
              with pytest.raises(
                  (ImportError, RuntimeError), match=" module "
              ):
                  Scaler(info, method)
              return
  
      if info:
          info = epochs.info
      scaler = Scaler(info, method)
      X = scaler.fit_transform(epochs_data, y)
      assert_equal(X.shape, epochs_data.shape)
      if method is None or isinstance(method, dict):
          sd = DEFAULTS["scalings"] if method is None else method
          stds = np.zeros(len(picks))
          for key in ("mag", "grad"):
              stds[pick_types(epochs.info, meg=key)] = 1.0 / sd[key]
          stds[pick_types(epochs.info, meg=False, eeg=True)] = (
              1.0 / sd["eeg"]
          )
          means = np.zeros(len(epochs.ch_names))
      elif method == "mean":
          stds = np.array(
              [np.std(ch_data) for ch_data in epochs_data_t]
          )
          means = np.array(
              [np.mean(ch_data) for ch_data in epochs_data_t]
          )
      else:  # median
          percs = np.array(
              [
                  np.percentile(ch_data, [25, 50, 75])
                  for ch_data in epochs_data_t
              ]
          )
          stds = percs[:, 2] - percs[:, 0]
          means = percs[:, 1]
      assert_allclose(
          X * stds[:, np.newaxis] + means[:, np.newaxis],
          epochs_data,
          rtol=1e-12,
          atol=1e-20,
          err_msg=method,
      )
  
      X2 = scaler.fit(epochs_data, y).transform(epochs_data)
      assert_array_equal(X, X2)
  
      # inverse_transform
      Xi = scaler.inverse_transform(X)
      assert_array_almost_equal(epochs_data, Xi)
  
      # Test init exception
      pytest.raises(ValueError, Scaler, None, None)
      pytest.raises(TypeError, scaler.fit, epochs, y)
      pytest.raises(TypeError, scaler.transform, epochs)
      epochs_bad = Epochs(
          raw,
          events,
          event_id,
          0,
          0.01,
          baseline=None,
          picks=np.arange(len(raw.ch_names)),
      )  # non-data chs
      scaler = Scaler(epochs_bad.info, None)
      pytest.raises(
          ValueError, scaler.fit, epochs_bad.get_data(copy=False), y
      )
  
file_path: mne-python/mne/decoding/tests/test_transformer.py
imports: from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_equal
  from mne import Epochs, io, pick_types, read_events
  from mne.decoding import FilterEstimator, PSDEstimator, Scaler, TemporalFilter, UnsupervisedSpatialFilter, Vectorizer
  from mne.defaults import DEFAULTS
  from mne.utils import check_version, use_log_level
label_desc: Use image node_id 1 for calling a global function with example usage: test_scaler(info, method) without return types