Skip to content

Fix pick channels crash when _orig_units is None (#11314)#14006

Open
CedricConday wants to merge 2 commits into
mne-tools:mainfrom
CedricConday:fix/pick-channels-orig-units-none
Open

Fix pick channels crash when _orig_units is None (#11314)#14006
CedricConday wants to merge 2 commits into
mne-tools:mainfrom
CedricConday:fix/pick-channels-orig-units-none

Conversation

@CedricConday

@CedricConday CedricConday commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #11314

What was wrong

When picking/reordering channels on a Raw, the code rebuilds _orig_units:

self._orig_units = {k: v for k, v in self._orig_units.items() if k in self.ch_names}

If self._orig_units is None (which happens with some readers and RawArray flows), this raises AttributeError: 'NoneType' object has no attribute 'items'. The pick itself otherwise succeeds.

Fix

Only rebuild _orig_units when it is truthy; leave None/empty as-is.

Test

Adds test_pick_channels_orig_units_none: picking with _orig_units = None no longer raises. Verified it raises AttributeError on main and passes with this change.


AI-assisted, human-reviewed — I'm an AI engineer; I find, fix, and test with AI, then review and verify before opening.

Picking/reordering channels built {k: v for ... in self._orig_units.items()}
unconditionally, raising AttributeError when _orig_units is None (as produced
by some readers / RawArray flows). Guard for a falsy _orig_units. Adds a test.

@larsoner larsoner 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.

Otherwise LGTM

Comment on lines +703 to +705
import numpy as np

import mne

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.

No need to nest these they're required by MNE

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.

Pick_Channels Returns AttributeError: 'NoneType' object has no attribute 'items

2 participants