code: def _csd_wrapper(
      x,
      y,
      fs=1.0,
      window="hann",
      nperseg=None,
      noverlap=None,
      nfft=None,
      detrend="constant",
      return_onesided=True,
      scaling="density",
      axis=-1,
      average="mean",
  ):
      """Wrapper for the `csd()` function based on `ShortTimeFFT` for
      unit testing.
      """
      freqs, _, Pxy = _csd_test_shim(
          x,
          y,
          fs,
          window,
          nperseg,
          noverlap,
          nfft,
          detrend,
          return_onesided,
          scaling,
          axis,
      )
  
      # The following code is taken from csd():
      if len(Pxy.shape) >= 2 and Pxy.size > 0:
          if Pxy.shape[-1] > 1:
              if average == "median":
                  # np.median must be passed real arrays for the desired result
                  bias = _median_bias(Pxy.shape[-1])
                  if np.iscomplexobj(Pxy):
                      Pxy = np.median(
                          np.real(Pxy), axis=-1
                      ) + 1j * np.median(np.imag(Pxy), axis=-1)
                  else:
                      Pxy = np.median(Pxy, axis=-1)
                  Pxy /= bias
              elif average == "mean":
                  Pxy = Pxy.mean(axis=-1)
              else:
                  raise ValueError(
                      f'average must be "median" or "mean", got {average}'
                  )
          else:
              Pxy = np.reshape(Pxy, Pxy.shape[:-1])
  
      return freqs, Pxy
  
file_path: scipy/scipy/signal/tests/_scipy_spectral_test_shim.py
imports: import platform
  from typing import cast, Literal
  import numpy
  from numpy.testing import assert_allclose
  from scipy.signal import ShortTimeFFT
  from scipy.signal import csd, get_window, stft, istft
  from scipy.signal._arraytools import const_ext, even_ext, odd_ext, zero_ext
  from scipy.signal._short_time_fft import FFT_MODE_TYPE
  from scipy.signal._spectral_py import _spectral_helper, _triage_segments, _median_bias
label_desc: Use image node_id 3 for calling a global function with example usage: _csd_wrapper(x, y, fs, window, nperseg, noverlap, nfft, detrend, return_onesided, scaling, axis, average) and returns: freqs,  Pxy