Skip to content

Match EEGLAB calling conventions and index shapes - #656

Merged
suraj-ranganath merged 2 commits into
developfrom
cursor/xfail-api-numeric-d149
Nov 19, 2026
Merged

suraj-ranganath merged 2 commits into
developfrom
cursor/xfail-api-numeric-d149

Conversation

@suraj-ranganath

Copy link
Copy Markdown
Member

Match EEGLAB argument order, 1-based epoch indices, and row-shaped gauss and eeg_lat2point results, and keep structure-array dataset lists. Sixteen Python-backend expected failures now pass. MATLAB Engine is not installed, so the MATLAB reference suite was not run.

Refs #430

Open in Web Open in Cursor 

epoch, gauss, and eeg_lat2point now follow MATLAB rows and 1-based
indices. pop_loadset, pop_expica, pop_copyset, and pop_delset accept
the EEGLAB argument and dataset-list contracts.

Co-authored-by: Suraj Ranganath <[email protected]>

@claude claude Bot left a comment

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.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@claude

claude Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 1m 48s —— View job


Code review

  • Pre-review gate and head check (7583cdd, open, not a draft, no earlier review)

  • Read the diff and AGENTS.md

  • Review passes: AGENTS.md, conventions, correctness, EEGLAB parity

  • Post review (2 inline comments)

  • Overall assessment: Needs changes. Most of the PR is correct, but one change affects every standalone Python caller of pop_copyset.

  • Highest-risk area: the pop_copyset return type

  • Merge recommendation: Needs changes

Blocking

None.

Important

  1. pop_copyset returns CURRENTSET as np.float64 for plain-list ALLEEG (src/eegprep/functions/popfunc/pop_copyset.py:69)
    • This change was made for the MATLAB backend, but it applies to every caller.
    • Standalone code like ALLEEG, EEG, CURRENTSET = pop_copyset(ALLEEG, 1, 2); ALLEEG[CURRENTSET - 1] now raises TypeError.
    • docs/source/examples/plot_dataset_management.py will print CURRENTSET: 3.0.
    • The GUI path still works only because session.normalize_dataset_indices accepts whole-number floats.
    • Fix: return int for list input. Either return np.float64 only when ALLEEG is a structured array, or convert in tests/eeglab_tests/backend.py. Fix this →
  2. The changelog does not say that eegprep.epoch changed what it does (docs/source/changelog.rst:13)
    • redefine_functions.epoch used to wrap pop_epoch, which epochs a dataset. It now runs the data-matrix epoch.m port.
    • That matches EEGLAB, but existing epoch(EEG, ...) calls break silently. AGENTS.md asks for migration notes in this case.
    • Fix: add a sentence such as "use pop_epoch to epoch a dataset".

Nits

None.

Test gaps

  • The new test test_pop_copyset_keeps_a_struct_array_and_copies_the_selected_dataset only covers struct-array input. Add one assertion that the list-input path still returns an int CURRENTSET, so the regression above stays caught.

EEGLAB parity notes

  • The vendored EEGLAB reference is not in this checkout (src/eegprep/eeglab/ is missing), so I checked parity from what I know of the .m files, not from the source.
  • pop_loadset.m uses the old two-argument form only when nargin == 2. The Python version also accepts an odd tail such as (file, path, 'loadmode', 'info'). That is a harmless extension.
  • These changes match EEGLAB and look correct:
    • pop_expica takes (EEG, whichica, filename), and the GUI caller in menu_actions.py:837 is updated.
    • gauss returns a row.
    • eeg_lat2point flattens timewin.
    • pop_editeventfield appends events for indices past the end; the existing grow loop at line 239 already handles them.
    • pop_delset keeps the shape of a struct array.
  • As the PR description says, this changes core functions, so before merging it needs the MATLAB reference-suite run (eeglab-reference.yml) and human approval, per AGENTS.md.

I could not run tests in this environment: running commands needed approval.

eeg_out = {field: deepcopy(stored[field][position]) for field in stored.dtype.names}
else:
eeg_out = deepcopy(copied)
current = np.float64(set_out)

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.

Important: CURRENTSET is now np.float64 for plain-list ALLEEG too

current = np.float64(set_out) applies to every caller, not only the MATLAB struct-array path. In standalone Python, the documented pattern breaks:

ALLEEG, EEG, CURRENTSET = pop_copyset(ALLEEG, 1, 2)
ALLEEG[CURRENTSET - 1]   # TypeError: list indices must be integers or slices, not numpy.float64

docs/source/examples/plot_dataset_management.py:87 will also print CURRENTSET: 3.0 now. The GUI path is fine only because normalize_dataset_indices in session.py accepts whole-number floats.

MATLAB doubles are a backend-marshalling concern. Keep int here and convert in tests/eeglab_tests/backend.py (or return np.float64 only when ALLEEG is a structured array, like restore_dataset_container does).

Suggested change
current = np.float64(set_out)
current = np.float64(set_out) if isinstance(stored, np.ndarray) else set_out

Comment thread docs/source/changelog.rst Outdated
Comment on lines +13 to +14
- ``epoch`` accepts positional name/value pairs and returns 1-based column
indices, a ``newtime`` row, and event cells. ``gauss`` returns a row.

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.

Important: the changelog does not say that eegprep.epoch changed what it does

Before this PR, eegprep.epoch (redefine_functions.epoch) was a wrapper for pop_epoch, so it epoched an EEG dataset. Now it runs the data-matrix epoch.m port. That matches EEGLAB, but any epoch(EEG, ...) call now fails or returns the wrong result, and this entry only says "accepts positional name/value pairs". AGENTS.md says: "Update … migration notes where relevant."

Suggested fix: add a sentence such as "epoch now extracts epochs from a data matrix, as epoch.m does; use pop_epoch to epoch a dataset." The docs/source/api/epoching_and_selection.rst entry picks up the new docstring automatically.

pop_copyset returns a float current index only for a structure-array
ALLEEG. epoch now says it extracts epochs from a data matrix.

Co-authored-by: Suraj Ranganath <[email protected]>
@suraj-ranganath
suraj-ranganath merged commit 99f7e05 into develop Nov 19, 2026
12 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.

2 participants