code: def test_spectrum_to_data_frame(inst, request, evoked):
      """Test the to_data_frame method for Spectrum."""
      pytest.importorskip("pandas")
      from pandas.testing import assert_frame_equal
  
      # setup
      is_already_psd = inst in ("raw_spectrum", "epochs_spectrum")
      is_epochs = inst == "epochs_spectrum"
      inst = _get_inst(inst, request, evoked)
      extra_dim = () if is_epochs else (1,)
      extra_cols = (
          ["freq", "condition", "epoch"] if is_epochs else ["freq"]
      )
      # compute PSD
      spectrum = (
          inst if is_already_psd else inst.compute_psd(exclude="bads")
      )
      n_epo, n_chan, n_freq = extra_dim + spectrum.get_data().shape
      # test wide format
      df_wide = spectrum.to_data_frame()
      n_row, n_col = df_wide.shape
      assert n_row == n_freq
      assert n_col == n_chan + len(extra_cols)
      assert set(spectrum.ch_names + extra_cols) == set(df_wide.columns)
      # test long format
      df_long = spectrum.to_data_frame(long_format=True)
      n_row, n_col = df_long.shape
      assert n_row == n_epo * n_freq * n_chan
      base_cols = ["channel", "ch_type", "value"]
      assert n_col == len(base_cols + extra_cols)
      assert set(base_cols + extra_cols) == set(df_long.columns)
      # test index
      index = extra_cols[-2:]  # ['freq'] or ['condition', 'epoch']
      df = spectrum.to_data_frame(index=index)
      if is_epochs:
          index_tuple = (
              list(spectrum.event_id)[0],  # condition
              spectrum.selection[0],
          )  # epoch number
          subset = df.loc[index_tuple]
          assert subset.shape == (
              n_freq,
              n_chan + 1,
          )  # + 1 is the freq column
      with pytest.raises(
          ValueError, match='"time" is not a valid option'
      ):
          spectrum.to_data_frame(index="time")
      # test picks
      picks = [0, 1]
      _pick_first = spectrum.pick(picks).to_data_frame()
      _pick_last = spectrum.to_data_frame(picks=picks)
      assert_frame_equal(_pick_first, _pick_last)
  
imports: from functools import partial
  import numpy
  import pytest
  from matplotlib.colors import same_color
  from numpy.testing import assert_array_equal
  from mne import Annotations
  from mne.time_frequency import read_spectrum
  from mne.time_frequency.spectrum import EpochsSpectrumArray, SpectrumArray
label_desc: Use image node_id 12 for calling a global function with example usage: test_spectrum_to_data_frame(inst, request, evoked) without return types