Skip to content

DOC: Fix apply_function shape description for Epochs (#13118)#13891

Open
bkowshik wants to merge 4 commits into
mne-tools:mainfrom
bkowshik:fix/issue-13118-epochs-applyfun-docstring
Open

DOC: Fix apply_function shape description for Epochs (#13118)#13891
bkowshik wants to merge 4 commits into
mne-tools:mainfrom
bkowshik:fix/issue-13118-epochs-applyfun-docstring

Conversation

@bkowshik
Copy link
Copy Markdown

@bkowshik bkowshik commented May 8, 2026

Reference issue (if any)

What does this implement/fix?

The fun parameter docstring for mne.Epochs.apply_function incorrectly stated that the array passed to the user's function when channel_wise=False has shape (len(picks), n_times). The actual shape is (n_epochs, n_channels, n_times). Adds a new fun_applyfun_epochs docdict entry alongside fun_applyfun_evoked and fun_applyfun_stc, leaving the Raw docstring (where (len(picks), n_times) is correct) untouched.

Related (out of scope): https://mne.discourse.group/t/epochs-apply-function-channel-wise-false-picks-silently-ignores-picks/11828 — separate question about whether picks should be honored when channel_wise=False on Epochs.

Documentation post the fix looks like below:

cd doc
make html-noplot
make show
image

Additional information

Have used Claude Code to understand the issue, identify the location of fix, commands to build locally for testing.

Copy link
Copy Markdown
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 for opening this PR @bkowshik! I have only a very minor comment.

Please have a look at the instructions for documenting these changes in our contributing guide, so that you can be credited.
For a small documentation change like this, the other change type fits best.

Comment thread mne/utils/docs.py Outdated
" if ``channel_wise=True`` and ``(len(picks), n_times)`` otherwise"
)
docdict["fun_applyfun_epochs"] = applyfun_fun_base.format(
" if ``channel_wise=True`` and ``(n_epochs, n_channels, n_times)`` otherwise"
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
" if ``channel_wise=True`` and ``(n_epochs, n_channels, n_times)`` otherwise"
" if ``channel_wise=True`` (because it will apply to 1-D slices along the times axis) and ``(n_epochs, len(picks), n_times)`` otherwise"
  • Suggest changing n_channels to len(picks) for consistency with the docstring of Raw.apply_function().
  • Suggest explaining why n_epochs isn't included as a dimension when channel_wise=True (np.apply_along_axis is used to apply the function to 1-D slices along the times axis).

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.

You would need to fix the line length of this suggestion afterwards if applying directly.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Made the change here: 01c233a

Documentation post this change is looking like this.

image

The fun parameter docstring for mne.Epochs.apply_function incorrectly stated
that the array passed to the user's function when channel_wise=False has
shape (len(picks), n_times). The actual shape is (n_epochs, n_channels, n_times).

Adds a new fun_applyfun_epochs docdict entry alongside fun_applyfun_evoked
and fun_applyfun_stc, leaving the Raw docstring (where (len(picks), n_times)
is correct) untouched. Per scott-huberty's review suggestion on mne-tools#13136.

Fixes mne-tools#13118
@bkowshik bkowshik force-pushed the fix/issue-13118-epochs-applyfun-docstring branch from 93fc229 to 5abd7b1 Compare May 12, 2026 11:10
bkowshik added 2 commits May 12, 2026 17:06
Apply @tsbinns review suggestion (n_channels -> len(picks); explain channel_wise=True shape).
Add 13891.other.rst (other type) and Bhargav Kowshik to names.inc as new contributor.
@bkowshik bkowshik requested a review from larsoner as a code owner May 12, 2026 11:37
@bkowshik
Copy link
Copy Markdown
Author

Thank you so much for the review, feedback and the PR fixing the issue! 👏

Please have a look at the instructions for documenting these changes in our contributing guide, so that you can be credited. For a small documentation change like this, the other change type fits best.

Made the change in this commit: 3f3793c

@bkowshik bkowshik requested a review from tsbinns May 12, 2026 11:39
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.

apply_function docstring wrong for epochs?

3 participants