Skip to content

Commit 2014510

Browse files
FIX: Warn on rank estimate with too few samples
Signed-off-by: Emmanuel Ferdman <[email protected]>
1 parent a8084cb commit 2014510

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

mne/decoding/tests/test_csp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def test_spoc():
431431
# check y
432432
pytest.raises(ValueError, spoc.fit, X, y * 0)
433433

434-
# Check that doesn't take CSP-spcific input
434+
# Check that doesn't take CSP-specific input
435435
pytest.raises(TypeError, SPoC, cov_est="epoch")
436436

437437
# Check mixing matrix on simulated data
@@ -492,6 +492,7 @@ def test_csp_component_ordering():
492492

493493

494494
@pytest.mark.filterwarnings("ignore:.*Only one sample available.*")
495+
@pytest.mark.filterwarnings("ignore:.*You've got fewer samples than channels.*")
495496
@parametrize_with_checks([CSP(), SPoC()])
496497
def test_sklearn_compliance(estimator, check):
497498
"""Test compliance with sklearn."""

mne/rank.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def _estimate_rank_meeg_signals(
184184
"""
185185
picks_list = _picks_by_type(info)
186186
if data.shape[1] < data.shape[0]:
187-
raise ValueError(
187+
warn(
188188
"You've got fewer samples than channels, your "
189189
"rank estimate might be inaccurate."
190190
)
@@ -249,7 +249,7 @@ def _estimate_rank_meeg_cov(
249249
scalings = _handle_default("scalings_cov_rank", scalings)
250250
_apply_scaling_cov(data, picks_list, scalings)
251251
if data.shape[1] < data.shape[0]:
252-
raise ValueError(
252+
warn(
253253
"You've got fewer samples than channels, your "
254254
"rank estimate might be inaccurate."
255255
)

mne/simulation/tests/test_evoked.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def test_simulate_evoked():
100100
@pytest.mark.filterwarnings("ignore:No average EEG reference present")
101101
@pytest.mark.filterwarnings("ignore:Too few samples")
102102
@pytest.mark.filterwarnings("ignore:Epochs are not baseline corrected")
103+
@pytest.mark.filterwarnings("ignore:.*You've got fewer samples than channels.*")
103104
def test_add_noise():
104105
"""Test noise addition."""
105106
rng = np.random.default_rng(0)

mne/tests/test_cov.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ def _assert_cov(cov, cov_desired, tol=0.005, nfree=True):
412412

413413
@pytest.mark.slowtest
414414
@pytest.mark.parametrize("rank", ("full", None))
415+
@pytest.mark.filterwarnings("ignore:.*You've got fewer samples than channels.*")
415416
def test_cov_estimation_with_triggers(rank, tmp_path):
416417
"""Test estimation from raw with triggers."""
417418
raw = read_raw_fif(raw_fname)
@@ -781,6 +782,7 @@ def raw_epochs_events():
781782

782783

783784
@pytest.mark.parametrize("rank", (None, "full", "info"))
785+
@pytest.mark.filterwarnings("ignore:.*You've got fewer samples than channels.*")
784786
def test_low_rank_methods(rank, raw_epochs_events):
785787
"""Test low-rank covariance matrix estimation."""
786788
pytest.importorskip("sklearn")
@@ -814,6 +816,7 @@ def test_low_rank_methods(rank, raw_epochs_events):
814816
assert these_bounds[0] < cov["loglik"] < these_bounds[1], (rank, method)
815817

816818

819+
@pytest.mark.filterwarnings("ignore:.*You've got fewer samples than channels.*")
817820
def test_low_rank_cov(raw_epochs_events):
818821
"""Test additional properties of low rank computations."""
819822
pytest.importorskip("sklearn")
@@ -890,6 +893,7 @@ def test_low_rank_cov(raw_epochs_events):
890893

891894

892895
@testing.requires_testing_data
896+
@pytest.mark.filterwarnings("ignore:.*You've got fewer samples than channels.*")
893897
def test_cov_ctf():
894898
"""Test basic cov computation on ctf data with/without compensation."""
895899
pytest.importorskip("sklearn")

0 commit comments

Comments
 (0)