code: def test_to_data_frame():
      """Test EpochsTFR Pandas exporter."""
      # Create fake EpochsTFR data:
      pytest.importorskip("pandas")
      n_epos = 3
      ch_names = ["EEG 001", "EEG 002", "EEG 003", "EEG 004"]
      n_picks = len(ch_names)
      ch_types = ["eeg"] * n_picks
      n_freqs = 5
      n_times = 6
      data = np.random.rand(n_epos, n_picks, n_freqs, n_times)
      times = np.arange(6)
      srate = 1000.0
      freqs = np.arange(5)
      events = np.zeros((n_epos, 3), dtype=int)
      events[:, 0] = np.arange(n_epos)
      events[:, 2] = np.arange(5, 5 + n_epos)
      event_id = {
          k: v for v, k in zip(events[:, 2], ["ha", "he", "hu"])
      }
      info = mne.create_info(ch_names, srate, ch_types)
      tfr = mne.time_frequency.EpochsTFR(
          info, data, times, freqs, events=events, event_id=event_id
      )
      # test index checking
      with pytest.raises(
          ValueError, match="options. Valid index options are"
      ):
          tfr.to_data_frame(index=["foo", "bar"])
      with pytest.raises(
          ValueError, match='"qux" is not a valid option'
      ):
          tfr.to_data_frame(index="qux")
      with pytest.raises(
          TypeError, match="index must be `None` or a string "
      ):
          tfr.to_data_frame(index=np.arange(400))
      # test wide format
      df_wide = tfr.to_data_frame()
      assert all(np.isin(tfr.ch_names, df_wide.columns))
      assert all(
          np.isin(
              ["time", "condition", "freq", "epoch"], df_wide.columns
          )
      )
      # test long format
      df_long = tfr.to_data_frame(long_format=True)
      expected = (
          "condition",
          "epoch",
          "freq",
          "time",
          "channel",
          "ch_type",
          "value",
      )
      assert set(expected) == set(df_long.columns)
      assert set(tfr.ch_names) == set(df_long["channel"])
      assert len(df_long) == tfr.data.size
      # test long format w/ index
      df_long = tfr.to_data_frame(long_format=True, index=["freq"])
      del df_wide, df_long
      # test whether data is in correct shape
      df = tfr.to_data_frame(
          index=["condition", "epoch", "freq", "time"]
      )
      data = tfr.data
      assert_array_equal(
          df.values[:, 0], data[:, 0, :, :].reshape(1, -1).squeeze()
      )
      # compare arbitrary observation:
      assert (
          df.loc[
              ("he", slice(None), freqs[1], times[2]), ch_names[3]
          ].iat[0]
          == data[1, 3, 1, 2]
      )
  
      # Check also for AverageTFR:
      tfr = tfr.average()
      with pytest.raises(
          ValueError, match="options. Valid index options are"
      ):
          tfr.to_data_frame(index=["epoch", "condition"])
      with pytest.raises(
          ValueError, match='"epoch" is not a valid option'
      ):
          tfr.to_data_frame(index="epoch")
      with pytest.raises(
          TypeError, match="index must be `None` or a string "
      ):
          tfr.to_data_frame(index=np.arange(400))
      # test wide format
      df_wide = tfr.to_data_frame()
      assert all(np.isin(tfr.ch_names, df_wide.columns))
      assert all(np.isin(["time", "freq"], df_wide.columns))
      # test long format
      df_long = tfr.to_data_frame(long_format=True)
      expected = ("freq", "time", "channel", "ch_type", "value")
      assert set(expected) == set(df_long.columns)
      assert set(tfr.ch_names) == set(df_long["channel"])
      assert len(df_long) == tfr.data.size
      # test long format w/ index
      df_long = tfr.to_data_frame(long_format=True, index=["freq"])
      del df_wide, df_long
      # test whether data is in correct shape
      df = tfr.to_data_frame(index=["freq", "time"])
      data = tfr.data
      assert_array_equal(
          df.values[:, 0], data[0, :, :].reshape(1, -1).squeeze()
      )
      # compare arbitrary observation:
      assert df.loc[(freqs[1], times[2]), ch_names[3]] == data[3, 1, 2]
  
imports: import datetime
  import re
  from itertools import product
  from pathlib import Path
  import matplotlib.pyplot
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal, assert_equal
  from scipy.signal import morlet2
  import mne
  from mne import Epochs, EpochsArray, Info, Transform, create_info, pick_types, read_events
  from mne.io import read_raw_fif
  from mne.tests.test_epochs import assert_metadata_equal
  from mne.time_frequency import tfr_array_morlet, tfr_array_multitaper
  from mne.time_frequency.tfr import AverageTFR, EpochsTFR, _compute_tfr, _make_dpss, combine_tfr, cwt, fwhm, morlet, read_tfrs, tfr_morlet, tfr_multitaper, write_tfrs
  from mne.utils import catch_logging, grand_average
  from mne.viz.utils import _fake_click, _fake_keypress, _fake_scroll
label_desc: Use image node_id 19 for calling a global function with example usage: test_to_data_frame() without return types