Skip to content

ENH: Validate frequencies and add docstring warning in SpectrumArray (#14596) - #14598

Merged
tsbinns merged 3 commits into
mne-tools:mainfrom
ishaaaan17:enh/spectrum-array-freqs-check
Nov 28, 2026
Merged

tsbinns merged 3 commits into
mne-tools:mainfrom
ishaaaan17:enh/spectrum-array-freqs-check

Conversation

@ishaaaan17

@ishaaaan17 ishaaaan17 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Reference issue (if any)

Fixes #14596.

What does this implement/fix?

As discussed with @tsbinns and @larsoner in #14596, this PR adds minimal sanity checks and documentation warnings for SpectrumArray and EpochsSpectrumArray:

  1. Frequency Sanity Checks: Validates in _check_data_shape that frequencies are one-sided (freqs >= 0) and do not exceed the Nyquist frequency (sfreq / 2), raising a ValueError otherwise.
  2. Docstring Warning: Adds a .. warning:: note to the docstrings of both SpectrumArray and EpochsSpectrumArray indicating that input validation is minimal and inconsistently or incorrectly specifying parameters can lead to unexpected errors downstream.
  3. Tests & Changelog: Adds unit tests covering negative frequencies and Nyquist-exceeding frequencies in test_spectrum_array_errors, along with a Towncrier changelog entry (14598.bugfix.rst).

Additional information

All tests pass locally (pytest mne/time_frequency/tests/test_spectrum.py), and style/changelog checks are 100% clean.

AI Assistance Disclosure: I formulated the plan and implemented the validation logic and docstrings myself, and used Antigravity (Gemini) to draft the unit tests and verify style/changelog consistency.

@tsbinns tsbinns left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ishaaaan17! I only notice two minor things.

Comment thread mne/time_frequency/spectrum.py Resolved
Comment thread mne/time_frequency/spectrum.py Resolved
@ishaaaan17
ishaaaan17 requested a review from tsbinns November 27, 2026 20:58

@tsbinns tsbinns left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ishaaaan17. Just one tiny thing I missed earlier, the it would be good to merge.

Comment thread mne/time_frequency/spectrum.py Resolved
@ishaaaan17
ishaaaan17 requested a review from tsbinns November 28, 2026 11:13
@tsbinns
tsbinns enabled auto-merge (squash) November 28, 2026 11:59

@tsbinns tsbinns left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ishaaaan17! Marking for merge whgen green

@tsbinns
tsbinns merged commit 40cbeb3 into mne-tools:main Nov 28, 2026
27 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Thoughts on input validation for SpectrumArray objects

2 participants