Skip to content

DOC: clarify index mismatch in Epochs.drop when epochs are auto-dropped#13688

Merged
drammock merged 14 commits intomne-tools:mainfrom
Famous077:fix/epochs-drop-index-mismatch
Mar 5, 2026
Merged

DOC: clarify index mismatch in Epochs.drop when epochs are auto-dropped#13688
drammock merged 14 commits intomne-tools:mainfrom
Famous077:fix/epochs-drop-index-mismatch

Conversation

@Famous077
Copy link
Contributor

@Famous077 Famous077 commented Feb 25, 2026

Fixed issue #11373

-->

What does this implement/fix?

--> The indices shown in epochs.plot() reflect epochs.selection
(original event indices), while epochs.drop() uses 0-based
indices into the remaining epochs. This PR clarifies this
behavior in the docstring and adds an example showing how to
correctly convert plot indices using epochs.selection.

Additional information

--> only documentation, No additional changes to code logic.

@Famous077
Copy link
Contributor Author

Hello @larsoner @drammock , Would appreciate your review when you get a chance. Happy to update based on your feedback. Thank you

mne/epochs.py Outdated
Comment on lines +1543 to +1557
If some epochs were automatically dropped (e.g., due to
insufficient data or rejection), the indices shown in
:meth:`mne.Epochs.plot` may not match the indices expected
by this method. The plot shows indices from
:attr:`mne.Epochs.selection` (original event indices),
while this method uses 0-based indices into the current
set of remaining epochs. To convert plot indices to drop
indices, use::

# epochs.selection contains the original indices
# of the remaining epochs
plot_idx = 1 # index shown in epochs.plot()
drop_idx = np.where(epochs.selection == plot_idx)[0]
epochs.drop(drop_idx)

Copy link
Member

Choose a reason for hiding this comment

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

This is pretty good. I think:

  1. it should be in a separate Notes section of the docstring
  2. it should emphasize less "automatic dropping" and "what is shown in epochs.plot" and instead focus on the fact that this method expects zero-based indices into the currently remaining epochs (not the epochs' original indices, as found in epochs.selection).

@Famous077
Copy link
Contributor Author

Hi @drammock , Thanks for the feedback. I've moved the content into a separate Notes section, refocused it to emphasize zero-based indices into the currently remaining epochs, and reverted the whitespace-only changes in doc/changes/dev/11373.other.rst. Waiting for your review whenever you get a chance.

@Famous077 Famous077 requested a review from drammock February 27, 2026 20:52
@Famous077 Famous077 requested a review from tsbinns March 1, 2026 14:23
@tsbinns
Copy link
Contributor

tsbinns commented Mar 3, 2026

Not sure why the docs aren't building here, but if I run locally, it complains about :attr:`~mne.Epochs.selection` being an invalid target. selection is listed as an attribute in the docs for Epochs, but I believe it needs to be a property of the class to be referenced like this.

@drammock, is it worth making selection a property so that it can be referenced, or should it just be referred to in the docstrings/changelog as, e.g., the `selection` attribute?

@drammock
Copy link
Member

drammock commented Mar 4, 2026

it complains about :attr:`~mne.Epochs.selection` being an invalid target.
[...] is it worth making selection a property so that it can be referenced, or should it just be referred to in the docstrings/changelog as, e.g., the `selection` attribute?

IMO: not worth it just for xref

Copy link
Contributor

@tsbinns tsbinns left a comment

Choose a reason for hiding this comment

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

@Famous077 Some suggestions to get the docs rendering properly. Apart from that, I think this is looking good!

@@ -0,0 +1 @@
Add a note to :meth:`~mne.Epochs.drop` describing a potential mismatch between indices expected by :meth:`~mne.Epochs.drop` and those found in :attr:`~mne.Epochs.selection` when epochs have been automatically dropped, by :newcontrib:`Famous Raj Bhat`. No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Add a note to :meth:`~mne.Epochs.drop` describing a potential mismatch between indices expected by :meth:`~mne.Epochs.drop` and those found in :attr:`~mne.Epochs.selection` when epochs have been automatically dropped, by :newcontrib:`Famous Raj Bhat`.
Add a note to :meth:`mne.Epochs.drop` describing a potential mismatch between the indices expected by :meth:`~mne.Epochs.drop` and those found in the ``selection`` attribute when epochs have been automatically dropped, by :newcontrib:`Famous Raj Bhat`.

mne/epochs.py Outdated
-----
This method expects zero-based indices into the currently remaining
epochs, not the original event indices (as found in
:attr:`mne.Epochs.selection`). If some epochs were automatically
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
:attr:`mne.Epochs.selection`). If some epochs were automatically
the ``selection`` attribute). If some epochs were automatically

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tsbinns Update done. Waiting for you review .

@Famous077 Famous077 requested a review from tsbinns March 4, 2026 19:16
Copy link
Contributor

@tsbinns tsbinns left a comment

Choose a reason for hiding this comment

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

Thanks @Famous077! I'm happy with this, and it seems to me that @drammock's earlier points have been addressed, so I'll approve, though they will also need to do so before this gets merged.

Copy link
Member

@drammock drammock left a comment

Choose a reason for hiding this comment

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

LGTM. I've suggested some fine-tuning of the wording, which I'll commit, and then mark for auto-merge.

@drammock drammock enabled auto-merge (squash) March 4, 2026 21:57
@Famous077
Copy link
Contributor Author

Hi @tsbinns , The CI failures are unrelated to this PR's changes. They're caused by a network connectivity issue in the Azure Pipelines runner — codeberg.org (a nibabel submodule host) is unreachable during dependency installation. Could you please re-run the failed checks or override them and let me know everything is working fine or not.

@Famous077 Famous077 requested review from drammock and tsbinns March 5, 2026 02:53
@drammock drammock merged commit 219e8a1 into mne-tools:main Mar 5, 2026
40 of 41 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.

3 participants