Skip to content

[pop_importepoch] Accept a one-row table on a single trial dataset - #852

Merged
arnodelorme merged 5 commits into
developfrom
agent/20261129-fix-843
Nov 29, 2026
Merged

arnodelorme merged 5 commits into
developfrom
agent/20261129-fix-843

Conversation

@claude

@claude claude Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

EEGPrep refused a one-row table on a dataset with a single trial ("pop_importepoch requires an epoched dataset"). EEGLAB accepts it: pop_importepoch.m line 266 only compares the number of rows with EEG.trials. Arno approved following EEGLAB on November 28, 2026. This removes the guard (2 lines), replaces the test that required the error, and updates the help and the changelog.

Comparison with EEGLAB (MATLAB R2025b, EEGLAB 4207693), same input on both sides

EEG = pop_importdata('data', zeros(1,3), 'srate', 100) then pop_importepoch(EEG, {'Correct', 0.01}, {'response','rt'}, 'latencyfields', {'rt'}).

Events (type, latency, response) epoch field in events EEG.epoch
EEGLAB TLE at 1, rt at 1.01, both Correct none empty
EEGPrep, this branch TLE at 1, rt at 1.01, both Correct none empty
EEGPrep, develop error

Two rows on the single trial are refused on both sides (the rows must match EEG.trials).

Verification

tests/test_pop_importepoch_current.py and the importer workflow tests: 27 passed. The new test fails with the guard in place. Pre-commit and Ruff pass. tests/test_package_help.py::test_every_public_optional_path_carries_its_marker fails on develop as well and is not touched by this change. EEGLAB reference workflow on this branch: https://github.com/sccn/eegprep/actions/runs/46238670776 (started on the first commit; its result is not known yet). The menu entry stays greyed for continuous data, as in EEGLAB (onepoch).

Fixes #843

🤖 Generated with Claude Code

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor Author

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.

Cover a one-sweep 3-D dataset importing epoch info and 2-D continuous
data still being rejected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@claude
claude Bot force-pushed the agent/20261129-fix-843 branch from 4feb33f to 17493aa Compare November 29, 2026 03:06
@claude claude Bot changed the title [popfunc] Accept a single selected sweep in pop_importepoch [tests] Add pop_importepoch single-sweep regression test Nov 29, 2026
@arnodelorme

Copy link
Copy Markdown
Collaborator

Review (Claude Fable): needs Arno

  • The test is correct and small (11 lines, one file). It passes on the branch and fails when I undo the fix of 1a74fb9.
  • Its second half makes EEGPrep reject a one row table on a two dimensional dataset with one trial. EEGLAB accepts that case: run in MATLAB R2025b, it returns one TLE event at latency 1 with response = Correct. pop_importepoch.m has no "epoched dataset" check, it only compares the rows with EEG.trials (line 266).
  • Its first half repeats a test that develop already has: test_f10_reader_options_apply_selection_and_replay[pop_loadeeg] also fails without the fix.
  • Decision for Arno: keep the rejection that only EEGPrep has (then this can merge as it is), or follow EEGLAB and remove the guard (then a one line fix with its test replaces this pull request). I recommend following EEGLAB.
Details

What I checked

  • Head 17493aa3, base develop at 1a74fb97, mergeable. No other open pull request touches a pop_importepoch file.
  • CI when I posted: Pre-commit checks, Ruff and ty, and EEGLAB Python backend pass. The six test jobs and the base install job were still pending.
  • Local run of tests/test_pop_importepoch_current.py: 4 passed, 1 deselected (the EEGLAB reference test, which needs --eeglab-backend).
  • With the guard put back to if trials <= 1: the new test fails, as it should. tests/test_stream9_gui_importers.py::test_f10_reader_options_apply_selection_and_replay[pop_loadeeg] fails too, so the single sweep path already had a workflow test. AGENTS.md asks to add only "a test that would catch a real bug the EEGLAB-ported tests and workflow tests miss".

EEGLAB on the case the test rejects

EEG = pop_importdata('data', zeros(1,3), 'srate', 100, 'dataformat', 'array');   % trials=1, ndims=2, xmin=0
EEG2 = pop_importepoch(EEG, {'Correct'}, {'response'});
% MATLAB ACCEPTED: nevents=1 type=TLE latency=1 response=Correct, EEG.epoch empty

EEGPrep on the same input raises ValueError: pop_importepoch requires an epoched dataset, and the new test requires that error.

Why the guard is fragile

In MATLAB a single sweep and a continuous recording are the same array, because the trailing dimension of size one is dropped. The Python guard trials <= 1 and np.ndim(EEG.get("data")) != 3 tells them apart by the shape of the array, and EEGPrep does not keep that shape:

  • eeg_from_data(np.zeros((1, 3, 1))) returns two dimensional data. This is why the test has to overwrite single["data"] by hand.
  • The output of the accepted import has data of shape (1, 3), so a second pop_importepoch(output, ...) raises.
  • After eeg_checkset, a one sweep dataset is two dimensional and raises.

So the test locks a rule that depends on an internal array shape, not on anything the user sees, and that differs from EEGLAB.

The two options

  • A, follow EEGLAB (my recommendation). Delete the guard in pop_importepoch.py (lines 84 and 85). The next check, len(records) != trials, is the same as pop_importepoch.m:266. Test: a one row table on a two dimensional dataset with one trial gives the MATLAB result above. Update the sentence "The current dataset must be epoched" in resources/help/pop_importepoch.md. This changes a core function, so it needs the MATLAB reference run. The menu entry stays greyed for continuous data as in EEGLAB (onepoch, eeglab.m:763).
  • B, keep the rejection. Merge this pull request as it is once CI is green, and say in the help file that a single sweep is accepted only as a three dimensional array.

GUI rules

Rule 21 is met (one file, 11 lines). Rule 27: the change is a test only, no window and no number changes, so no capture and no histogram are needed. Rule 33 is met: issue #843 names the earlier issue #738. Rules 23, 26 and 34 are not concerned, no dialog code is touched.

— orchestrator review

@arnodelorme

Copy link
Copy Markdown
Collaborator

Code review

Independent review by Codex (OpenAI GPT-6.1 Terra, high reasoning effort), asked by the orchestrator, which made the change with Claude Fable. Codex read commit 684dd07 in a read-only sandbox. It found nothing blocking. Its three important points are answered below, and its text follows unchanged.

What was done with its findings

  • The help promised metadata in EEG["epoch"]: fixed in commit e2bbef4. The help now says that on a single trial dataset EEG["epoch"] stays empty and the imported values are kept in the events only, which is what MATLAB returns (EEG.epoch empty).
  • A continuous recording can lose its events: documented, not changed. The same commit adds that the events of a continuous recording are replaced. This is EEGLAB's own behaviour: pop_importepoch.m lines 305 to 315 force clearevents to on when the old events have no epoch field. I did not add a MATLAB run on a long recording with events, so this point rests on reading the MATLAB code, not on a measured comparison.
  • The menu stays greyed for a single trial dataset: left as it is. EEGLAB greys File > Import epoch info for continuous data too (onepoch, eeglab.m line 763), so the menu already matches. The change only concerns calls from a script or the console.
Codex's review, unchanged

Blocking

None.

Important

Single trial imports are unavailable through the menu. eeglab_menu.py:61 disables epoch import for continuous data, and session.py:748 classifies every dataset with one trial as continuous, including a single sweep. Decide whether to enable the menu for these datasets and test the GUI flow. Check EEGLAB’s menu behavior before claiming GUI parity.

The help promises metadata that is discarded. pop_importepoch.md:26 and interactive_pop_workflows.rst:100 say the imported row remains in EEG["epoch"]. For one trial, eeg_checkset empties that field. Document where the surviving metadata goes and this single trial exception.

A long continuous recording can lose events. pop_importepoch.py:95 clears old events by default and also clears events without an epoch field when clearevents="off". Removing the guard exposes continuous recordings to this behavior. Warn users explicitly in the help. The supplied MATLAB example supports accepting one row, but does not establish whether EEGLAB handles existing continuous events the same way.

Nits

None. The changelog accurately describes acceptance of a single row, although it does not describe the event replacement risk.

Test gaps

tests/test_pop_importepoch_current.py:204 passes and checks the supplied MATLAB event values and empty epoch structure. The original guard would reject its first call. Add a long continuous recording with existing events and clearevents="off" to establish and document that behavior against MATLAB. Add a single trial menu and GUI workflow test if the menu is enabled.

Removing the guard is consistent with the supplied MATLAB result. I found no further single trial division or indexing failure in the import path. The local MATLAB reference file is absent, so I could not independently inspect it or verify continuous event handling. GitHub access was unavailable, so the live PR head, description, and required premerge MATLAB reference evidence could not be checked.

Merge recommendation: Request changes for the documentation and resolve the single trial GUI behavior before merging.

— orchestrator

@arnodelorme arnodelorme changed the title [tests] Add pop_importepoch single-sweep regression test [pop_importepoch] Accept a one-row table on a single trial dataset Nov 29, 2026
@arnodelorme

Copy link
Copy Markdown
Collaborator

A note for the merge: the two commits I pushed here (684dd07 and e2bbef4) carry a Co-Authored-By line, which AGENTS.md forbids. I saw the rule after pushing and cannot remove the line without a forced push. Please delete it in the squash message.

— orchestrator

# Conflicts:
#	docs/source/changelog.rst
@arnodelorme

Copy link
Copy Markdown
Collaborator

@copilot resolve the merge conflicts in this pull request

…-843

# Conflicts:
#	docs/source/changelog.rst

Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

🤖 Resolved the changelog conflict and merged current develop in 1bc35d8. git diff --check passed; local tests and pre-commit could not run because pytest and uv are unavailable.

Copilot AI requested a review from arnodelorme November 29, 2026 15:15
@arnodelorme
arnodelorme merged commit d0de59f into develop Nov 29, 2026
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.

pop_importepoch: accept event information for a single selected sweep

2 participants