Skip to content

FIX: Warn when bridged interpolation uses bad channels - #14287

Open
Deepnar wants to merge 2 commits into
mne-tools:mainfrom
Deepnar:fix/14263-warn-bridged-bads
Open

Deepnar wants to merge 2 commits into
mne-tools:mainfrom
Deepnar:fix/14263-warn-bridged-bads

Conversation

@Deepnar

@Deepnar Deepnar commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Summary

interpolate_bridged_electrodes temporarily clears inst.info["bads"] while building the interpolation. This can allow channels already marked bad to influence the result without notifying the caller.

This patch keeps the existing interpolation behavior and public API unchanged, but emits a warning naming the affected channels and documents the behavior.

Changes

  • Warn when inst.info["bads"] is non-empty.
  • Document the behavior in the public docstring.
  • Extend the existing regression test to check the warning and restoration of the original bad-channel list.
  • Add a bugfix changelog fragment.

Testing

  • .venv/bin/python -m pytest -p no:pytest-qt mne/preprocessing/tests/test_interpolate.py::test_interpolate_bridged_electrodes --verbose — 1 passed
  • .venv/bin/python -m pytest -p no:pytest-qt mne/preprocessing/tests/test_interpolate.py --verbose — 11 passed
  • .venv/bin/python -m pytest -p no:pytest-qt mne/tests/test_docstring_parameters.py --verbose — 17 passed, 2 skipped
  • Ruff check and format check passed
  • Codespell passed
  • git diff --check passed

Closes #14263.

@welcome

welcome Bot commented Sep 9, 2026

Copy link
Copy Markdown

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

@CarinaFo CarinaFo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, some small nitpicks.

We can use _pl from mne.utils to use the singular/plural of channel depending on length of bad channels.

Thank you for your contribution.

Comment thread mne/preprocessing/interpolate.py Outdated
that to aid in interpolation rather than completely discarding the
data from the two channels.

Channels listed in ``inst.info["bads"]`` are ignored for exclusion and

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
Channels listed in ``inst.info["bads"]`` are ignored for exclusion and
Channels listed in ``inst.info["bads"]`` are not excluded and

Comment thread mne/preprocessing/interpolate.py Outdated
from ..io import BaseRaw, RawArray
from ..transforms import _cart_to_sph, _sph_to_cart
from ..utils import _ensure_int, _validate_type
from ..utils import _ensure_int, _validate_type, warn

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
from ..utils import _ensure_int, _validate_type, warn
from ..utils import _ensure_int, _pl, _validate_type, warn

Comment thread mne/preprocessing/interpolate.py Outdated
bads_orig = inst.info["bads"]
if bads_orig:
warn(
f"The channels {', '.join(bads_orig)} are marked as bad but will not "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
f"The channels {', '.join(bads_orig)} are marked as bad but will not "
f"The channel{_pl(bads_orig)} marked as bad will not "

- Import _pl from mne.utils
- Docstring: 'are ignored for exclusion and' -> 'are not excluded and'
- Warning: follow Carina's suggestion literally:
  f"The channel{_pl(bads_orig)} marked as bad will not "
  (removes channel list, uses _pl for singular/plural)
- Update test to match generic warning
@Deepnar
Deepnar force-pushed the fix/14263-warn-bridged-bads branch from e0f5358 to e7f7d7d Compare September 17, 2026 12:57

@CarinaFo CarinaFo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks good, thanks again for your contribution.

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.

Interpolate bridged electrodes silently interpolates using bads

2 participants