Skip to content

FIX: Handle NaN values in FFT resampling (#14421) - #14580

Open
ADITYASINGH1206 wants to merge 1 commit into
mne-tools:mainfrom
ADITYASINGH1206:fix/resample-nan-handling
Open

ADITYASINGH1206 wants to merge 1 commit into
mne-tools:mainfrom
ADITYASINGH1206:fix/resample-nan-handling

Conversation

@ADITYASINGH1206

@ADITYASINGH1206 ADITYASINGH1206 commented Nov 21, 2026 •

Copy link
Copy Markdown

Reference issue (if any)

Fixes #14421

What does this implement/fix?

When using FFT-based resampling (method="fft" in mne.filter.resample or Raw.resample), having even a single NaN sample in a channel contaminates the entire channel into NaN because Fourier-domain operations spread the NaN across all frequencies.

This pull request implements the solution discussed with @larsoner in #14421:

  1. Detect NaN values in _resample_fft.
  2. Temporarily fill NaN segments via linear interpolation (np.interp), holding boundary values for edge gaps, so the FFT resamples smoothly without spreading NaN.
  3. Map output sample indices back to the nearest original samples and restore NaN at those positions.
  4. Leave polyphase resampling unchanged.

Additional information

Added tests in mne/tests/test_filter.py covering:

  • Leading, trailing, and interior NaN gaps
  • Single valid sample preservation
  • 2D/3D multi-channel arrays and non-default axes
  • Parallel execution with n_jobs=2
  • End-to-end RawArray.resample verification from Raw.resample doesn't handle NaNs #14421
  • Added release changelog entry in doc/changes/dev/14421.bugfix.rst

@welcome

welcome Bot commented Nov 21, 2026

Copy link
Copy Markdown

Hello! 👋 Thanks for opening your first pull request here! ❤️ We will try to get back to you soon. 🚴

This branch has not been deployed

No deployments
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.

Raw.resample doesn't handle NaNs

1 participant