8000 Fix get_group(None, ...) producing wrong-shaped/empty event_time_results by SID-6921 · Pull Request #413 · fooof-tools/fooof · GitHub
[go: up one dir, main page]

Skip to content

Fix get_group(None, ...) producing wrong-shaped/empty event_time_results - #413

Open
SID-6921 wants to merge 1 commit into
fooof-tools:mainfrom
SID-6921:fix-event-get-group-none-indices
Open

SID-6921 wants to merge 1 commit into
fooof-tools:mainfrom
SID-6921:fix-event-get-group-none-indices

Conversation

@SID-6921
Copy link
Copy Markdown

What

SpectralTimeEventModel.get_group's docstring promises:

event_inds, window_inds ... If None, selects all available indices.

For output_type='event', the data (spectrograms) and event_group_results were correctly indexed with einds/winds (the checked/converted indices from check_inds, which turns None into a full-range selection). But event_time_results was indexed with the raw event_inds/window_inds parameters instead:

output.results.event_time_results = \
    {key : self.results.event_time_results[key][event_inds][:, window_inds] \
    for key in self.results.event_time_results}

numpy treats None as np.newaxis when used as an index, not "select all". So:

  • Passing None for just one of event_inds/window_inds inserted a spurious extra axis into every event_time_results array (e.g. shape (2, 1, 3) instead of (2, 3)).
  • The whole population step ran only inside if event_inds is not None or window_inds is not None:, so passing None for both skipped it entirely, leaving event_time_results empty and data.spectrograms unset, rather than the documented "select all" result.

Repro

sub = model.get_group(None, None, output_type='event')
sub.results.event_time_results  # {} -- should hold every event's full results
sub.data.spectrograms  # None -- should be the full spectrograms array

sub2 = model.get_group([0, 1], None, output_type='event')
sub2.results.event_time_results['offset'].shape  # (2, 1, 3) -- should be (2, 3)

Fix

Use the already-computed einds/winds for event_time_results, and always run the population step for output_type='event' instead of only when at least one index argument is given, matching the "None selects all" contract.

The output_type in ('time', 'group') branch is intentionally left untouched — test_event_get_group already asserts that None there yields an empty export (a different, deliberate contract for the export path), so I kept that behavior as-is.

Testing

Extended test_event_get_group to check that get_group(None, None) returns the full data/results shapes, and that giving None on only one axis (get_group([0], None)) doesn't insert a spurious axis. Confirmed the new assertions fail on the pre-fix code (AttributeError: 'NoneType' object has no attribute 'shape' for the both-None case) and pass after the fix. Full suite: 375 passed, 9 skipped (same skip count as the unmodified checkout).

SpectralTimeEventModel.get_group's docstring promises that a None for
event_inds or window_inds selects all available indices along that axis.
For output_type='event', the data and event_group_results were already
indexed with the checked/converted einds and winds, but event_time_results
was indexed with the raw event_inds/window_inds parameters instead:

    event_time_results[key][event_inds][:, window_inds]

numpy treats None as np.newaxis when used as an index, not "select all",
so passing None on one axis inserted a spurious extra axis into every
event_time_results array, and the whole population step was additionally
skipped outright when both were None, leaving event_time_results empty
and data.spectrograms unset despite the documented "selects all" contract.

Use the already-computed einds/winds (from check_inds, which does convert
None to a full-range selection) for event_time_results, and always run the
population step for output_type='event' rather than only when at least one
index argument is given. The output_type in ('time', 'group') branch is
unchanged: an existing test asserts that None there intentionally yields
an empty export.
Copilot AI balanced review requested due to automatic review settings November 14, 2026 19:14
Copilot AI left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
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.

2 participants

0