Skip to content

BUG: Evoked.get_data() should exclude bad channels when explicit picks are given#14013

Open
evasafi wants to merge 7 commits into
mne-tools:mainfrom
evasafi:fix/evoked-get-data-bads
Open

BUG: Evoked.get_data() should exclude bad channels when explicit picks are given#14013
evasafi wants to merge 7 commits into
mne-tools:mainfrom
evasafi:fix/evoked-get-data-bads

Conversation

@evasafi

@evasafi evasafi commented Jul 1, 2026

Copy link
Copy Markdown

Fixes #12577

Epochs.get_data(picks="eeg") excludes channels marked as bad by default,
but Evoked.get_data(picks="eeg") does not. Same method name, same
library, inconsistent behavior.

Root cause: Evoked.get_data() always calls
_picks_to_idx(self.info, picks, "all", exclude=()), unconditionally
passing exclude=(). Epochs._get_data() only does this when picks
is None; when explicit picks are given, it lets _picks_to_idx fall
back to its default of exclude="bads".

This PR mirrors that branching logic in Evoked.get_data():

  • picks=None : unchanged, bads still included (preserves existing behavior)
  • explicit picks (e.g. picks="eeg"): bads now excluded by default,
    matching Epochs.get_data()

Added a regression test in test_evoked.py::test_get_data that fails
on current main and passes with this fix. Also added a changelog
entry and added myself to the contributor list.

@CarinaFo

CarinaFo commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Hi Eva, thank you for your contribution.
Fully agree with you that the inconsistent behaviour between epochs and evokeds should be fixed.
I am not sure if changing the behaviour of evokeds is the way to go, it might break people's code if we don't properly deprecate that.
Additionally, it seems that this is a broader and more complex issue as mentioned here.

Let me discuss that with the other maintainers and get back to you.

@evasafi evasafi closed this Jul 3, 2026
@evasafi

evasafi commented Jul 3, 2026

Copy link
Copy Markdown
Author

Thanks for the context, Carina. That forum thread and the broader consistency question make sense. Happy to keep this PR scoped to the Evoked.get_data() fix + docstring for now, and adjust the approach (deprecation path, etc.) once you've discussed with the other maintainers. If it'd be useful, I'd also be glad to help think through the broader .pick() standardization once there's a direction. That's a discussion I'd been meaning to follow more closely anyway.

@evasafi evasafi reopened this Jul 3, 2026
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.

Inconsistent behavior between Epochs and Evoked in get_data() method when picking EEG channels and bads are present

2 participants