Skip to content

Commit 9ef7eed

Browse files
committed
FIX: top level
1 parent 483abae commit 9ef7eed

1 file changed

Lines changed: 4 additions & 24 deletions

File tree

mne/stats/tests/test_cluster_level_modern.py

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# License: BSD-3-Clause
33
# Copyright the MNE-Python contributors.
44

5+
import matplotlib.pyplot as plt
56
import numpy as np
67
import pytest
78
from numpy.testing import assert_array_almost_equal, assert_array_equal
@@ -19,11 +20,12 @@
1920
from mne.time_frequency import AverageTFRArray, BaseTFR, EpochsTFRArray
2021
from mne.utils import GetEpochsMixin
2122

23+
pd = pytest.importorskip("pandas")
24+
pytest.importorskip("formulaic") # required for cluster_test API
25+
2226

2327
def test_cluster_test_one_sample(stat_conditions):
2428
"""Test cluster_test with a single-group (1-sample) design."""
25-
pd = pytest.importorskip("pandas")
26-
pytest.importorskip("formulaic") # required for cluster_test API
2729
condition1_1d, _, _, _ = stat_conditions
2830
df = pd.DataFrame(dict(data=[condition1_1d], group=["only"]))
2931
kwargs = dict(n_permutations=100, tail=0, rng=1, buffer_size=None)
@@ -42,9 +44,6 @@ def test_cluster_test_one_sample(stat_conditions):
4244

4345
def test_compare_old_and_new_cluster_api(stat_conditions):
4446
"""Test for same results from old and new APIs."""
45-
pd = pytest.importorskip("pandas")
46-
pytest.importorskip("formulaic")
47-
4847
condition1_1d, condition2_1d, condition1_2d, condition2_2d = stat_conditions
4948
df_1d = pd.DataFrame(
5049
dict(
@@ -70,9 +69,6 @@ def test_compare_old_and_new_cluster_api(stat_conditions):
7069
@pytest.mark.filterwarnings('ignore:Ignoring argument "tail":RuntimeWarning')
7170
def test_new_cluster_api(Inst):
7271
"""Test handling different MNE objects in the cluster API."""
73-
pd = pytest.importorskip("pandas")
74-
pytest.importorskip("formulaic")
75-
7672
rng = np.random.default_rng(seed=8675309)
7773
is_epo = GetEpochsMixin in Inst.__mro__
7874
is_tfr = BaseTFR in Inst.__mro__
@@ -150,8 +146,6 @@ def test_new_cluster_api(Inst):
150146
@pytest.mark.filterwarnings('ignore:Ignoring argument "tail":RuntimeWarning')
151147
def test_cluster_test_rm_anova():
152148
"""Test the interaction-formula (repeated-measures ANOVA) branch of cluster_test."""
153-
pd = pytest.importorskip("pandas")
154-
155149
rng = np.random.default_rng(seed=0)
156150
n_subjects, n_channels, n_times = 8, 3, 6
157151
info = create_info(n_channels, sfreq=100.0, ch_types="eeg")
@@ -220,8 +214,6 @@ def stat_fun(*args):
220214

221215
def test_cluster_test_formula_validation(stat_conditions):
222216
"""Test that cluster_test raises clear errors for unsupported formulas."""
223-
pd = pytest.importorskip("pandas")
224-
225217
condition1_1d, condition2_1d, _, _ = stat_conditions
226218
df = pd.DataFrame(dict(data=[condition1_1d, condition2_1d], a=["x", "y"]))
227219
df["b"] = "z"
@@ -253,11 +245,6 @@ def test_cluster_test_formula_validation(stat_conditions):
253245
@pytest.mark.filterwarnings("ignore:FigureCanvasAgg is non-interactive.*:UserWarning")
254246
def test_cluster_test_plot_cluster_time_frequency():
255247
"""Test ClusterResult.plot_cluster_time_frequency."""
256-
import matplotlib.pyplot as plt
257-
258-
pd = pytest.importorskip("pandas")
259-
pytest.importorskip("formulaic")
260-
261248
rng = np.random.default_rng(seed=0)
262249
n_subjects, n_channels, n_freqs, n_times = 6, 4, 3, 5
263250
ch_names = ["Fz", "Cz", "Pz", "Oz"]
@@ -296,10 +283,6 @@ def make_tfr(bump):
296283
@pytest.mark.filterwarnings("ignore:FigureCanvasAgg is non-interactive.*:UserWarning")
297284
def test_cluster_test_plot_cluster_time_frequency_disjoint_clusters():
298285
"""cluster_idx must select between clusters, ranked by mass not p-value."""
299-
import matplotlib.pyplot as plt
300-
301-
pd = pytest.importorskip("pandas")
302-
303286
rng = np.random.default_rng(seed=0)
304287
n_subjects, n_channels, n_freqs, n_times = 10, 4, 3, 6
305288
ch_names = ["Fz", "Cz", "Pz", "Oz"]
@@ -431,9 +414,6 @@ def overlay_values(fig):
431414

432415
def test_cluster_test_plot_cluster_time_frequency_wrong_dim(stat_conditions):
433416
"""Test plot_cluster_time_frequency rejects 2D (time x channel) clusters."""
434-
pd = pytest.importorskip("pandas")
435-
pytest.importorskip("formulaic")
436-
437417
condition1_1d, condition2_1d, _, _ = stat_conditions
438418
df = pd.DataFrame(dict(data=[condition1_1d, condition2_1d], condition=["a", "b"]))
439419
result = cluster_test(

0 commit comments

Comments
 (0)