Skip to content

Commit 5bc9e73

Browse files
authored
Raise meaningful error when plotting single-sample data (#13980)
1 parent 11ac062 commit 5bc9e73

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

mne/viz/_figure.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ def __init__(self, **kwargs):
7777
f"Expected an instance of Raw, Epochs, or ICA, got {type(inst)}."
7878
)
7979

80+
if len(inst.times) < 2:
81+
raise ValueError(
82+
"Data from at least two time points are required to open the browser."
83+
)
84+
8085
logger.debug(f"Opening {self.mne.instance_type} browser...")
8186

8287
self.mne.ica_type = None

mne/viz/tests/test_figure.py

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

5+
import numpy as np
56
import pytest
67

8+
from mne import create_info
9+
from mne.io import RawArray
710
from mne.viz._figure import _get_browser
811

912

1013
def test_browse_figure_constructor():
1114
"""Test error handling in MNEBrowseFigure constructor."""
1215
with pytest.raises(TypeError, match="an instance of Raw, Epochs, or ICA"):
1316
_get_browser(show=False, block=False, inst="foo")
17+
18+
19+
def test_browse_figure_requires_two_timepoints():
20+
"""Test that the browser raises an error when inst has fewer than 2 time points."""
21+
info = create_info(ch_names=["CH1"], sfreq=100.0, ch_types="eeg")
22+
raw = RawArray(np.zeros((1, 1)), info)
23+
assert len(raw.times) == 1
24+
with pytest.raises(ValueError, match="at least two time points"):
25+
_get_browser(show=False, block=False, inst=raw)

0 commit comments

Comments
 (0)