From 754baafbac1acd77a24958327b64b96d831020c7 Mon Sep 17 00:00:00 2001 From: Cedric Conday Date: Tue, 30 Jun 2026 03:46:20 +0000 Subject: [PATCH 1/4] Fix transition-bandwidth in FIR 'filter too short' error message (#11406) The error reported transition * sfreq / 2.0, but transition is already half the Nyquist-normalized width, so it displayed half the actual transition band (e.g. 0.50 Hz for a requested 1.0 Hz). Report transition * sfreq. Adds a regression test. --- doc/changes/dev/11406.bugfix.rst | 1 + mne/filter.py | 2 +- mne/tests/test_filter.py | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 doc/changes/dev/11406.bugfix.rst diff --git a/doc/changes/dev/11406.bugfix.rst b/doc/changes/dev/11406.bugfix.rst new file mode 100644 index 00000000000..fa862c5f3fb --- /dev/null +++ b/doc/changes/dev/11406.bugfix.rst @@ -0,0 +1 @@ +Fix the error message raised when a requested FIR ``filter_length`` is too short, which reported half the actual transition bandwidth, by `Cedric Conday`_. diff --git a/mne/filter.py b/mne/filter.py index f8f4abf6499..2ea091c2c87 100644 --- a/mne/filter.py +++ b/mne/filter.py @@ -440,7 +440,7 @@ def _firwin_design(N, freq, gain, window, sfreq): if this_N > N: raise ValueError( f"The requested filter length {N} is too short for the requested " - f"{transition * sfreq / 2.0:0.2f} Hz transition band, which " + f"{transition * sfreq:0.2f} Hz transition band, which " f"requires {this_N} samples" ) # Construct a lowpass diff --git a/mne/tests/test_filter.py b/mne/tests/test_filter.py index 02239c8545d..bafe76fefae 100644 --- a/mne/tests/test_filter.py +++ b/mne/tests/test_filter.py @@ -1134,3 +1134,20 @@ def test_smart_pad(dc, sfreq): x_want = np.r_[np.zeros_like(x), x_want, np.zeros_like(x)] x_pad = _smart_pad(x, (len(x) * 2,) * 2, "reflect_limited") assert_allclose(x_pad, x_want, atol=0.1, err_msg="reflect_limited with zeros") + + +def test_filter_too_short_error_reports_correct_transition(): + """The 'too short' filter error must report the true transition band (gh-11406).""" + import mne + + sfreq = 1000.0 + raw = mne.io.RawArray( + np.random.default_rng(0).standard_normal((1, 4000)), + mne.create_info(1, sfreq, "eeg"), + ) + # filter_length far too short for a 1 Hz transition band; the error must + # report 1.00 Hz (the requested l_trans_bandwidth), not half that. + with pytest.raises(ValueError, match="1.00 Hz transition band"): + raw.filter( + l_freq=10, h_freq=None, l_trans_bandwidth=1.0, filter_length="11ms" + ) From 4e3f331887ae3dab6b5ba35212c0e4ebcfdf6b96 Mon Sep 17 00:00:00 2001 From: Cedric Conday Date: Tue, 30 Jun 2026 03:46:42 +0000 Subject: [PATCH 2/4] rename changelog fragment to PR number --- doc/changes/dev/{11406.bugfix.rst => 14005.bugfix.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename doc/changes/dev/{11406.bugfix.rst => 14005.bugfix.rst} (100%) diff --git a/doc/changes/dev/11406.bugfix.rst b/doc/changes/dev/14005.bugfix.rst similarity index 100% rename from doc/changes/dev/11406.bugfix.rst rename to doc/changes/dev/14005.bugfix.rst From eac241c66581db0ded4e583f779f9656a6765db3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 30 Jun 2026 03:46:55 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mne/tests/test_filter.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mne/tests/test_filter.py b/mne/tests/test_filter.py index bafe76fefae..9c97e583995 100644 --- a/mne/tests/test_filter.py +++ b/mne/tests/test_filter.py @@ -1148,6 +1148,4 @@ def test_filter_too_short_error_reports_correct_transition(): # filter_length far too short for a 1 Hz transition band; the error must # report 1.00 Hz (the requested l_trans_bandwidth), not half that. with pytest.raises(ValueError, match="1.00 Hz transition band"): - raw.filter( - l_freq=10, h_freq=None, l_trans_bandwidth=1.0, filter_length="11ms" - ) + raw.filter(l_freq=10, h_freq=None, l_trans_bandwidth=1.0, filter_length="11ms") From f156838c02baa42a77ceb7ebc45cf1239a932109 Mon Sep 17 00:00:00 2001 From: CedricConday Date: Wed, 1 Jul 2026 05:31:24 +0000 Subject: [PATCH 4/4] test: hoist numpy/mne imports to module level per review --- mne/tests/test_filter.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mne/tests/test_filter.py b/mne/tests/test_filter.py index 9c97e583995..76b3634ba75 100644 --- a/mne/tests/test_filter.py +++ b/mne/tests/test_filter.py @@ -15,6 +15,7 @@ from scipy.signal import butter, freqz, sosfreqz from scipy.signal import resample as sp_resample +import mne from mne import Epochs, create_info from mne._fiff.pick import _DATA_CH_TYPES_SPLIT from mne.filter import ( @@ -1138,8 +1139,6 @@ def test_smart_pad(dc, sfreq): def test_filter_too_short_error_reports_correct_transition(): """The 'too short' filter error must report the true transition band (gh-11406).""" - import mne - sfreq = 1000.0 raw = mne.io.RawArray( np.random.default_rng(0).standard_normal((1, 4000)),