Skip to content

Stream 10: Export and BIDS - #562

Merged
suraj-ranganath merged 9 commits into
developfrom
cursor/stream-10-export-bids-44c5
Nov 6, 2026
Merged

suraj-ranganath merged 9 commits into
developfrom
cursor/stream-10-export-bids-44c5

Conversation

@suraj-ranganath

@suraj-ranganath suraj-ranganath commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Match File > Export and the BIDS tools to pinned EEGLAB 8ac485f654d6bbb1a6acb8dc9ef3f2eaf3d409ba. The MATLAB reference suite in this repo is pinned to EEGLAB d0963be9d81acc5b66e84f8d3d7c89e3ce127cc4 and eeglab_tests fec88f9ffe7c225eb1de8924db8b6a3e0d53a4d9. Those pins were not changed.

Two files outside this stream were edited, and only for the dialogs this stream opens. menu_actions._import_dataset is owned by stream 9: the BIDS branch now calls pop_importbids(..., gui=True, return_study=True) and stores the in-memory study. qt._select_file is owned by stream 2: mode="directory" uses QFileDialog.getExistingDirectory so the import and export browse buttons can pick a folder. tests/test_tutorial_eeglab_tests.py now selects subjects S01 and S02 because those datasets already set EEG.subject, and that field wins over the subject= argument.

pop_exportbids(EEG, folder) still writes one dataset from memory. A study export takes each subject from EEG.subject, then STUDY.datasetinfo, and raises when both are empty. createids numbers the unique subjects sub-001, sub-002, and participants.tsv has one row per subject. The export dialog records a replayable command with the dataset list, task, license, changes, and createids. EEGLAB leaves that command empty (pop_exportbids.m lines 247-252). The import field "Import only the following participant indices" takes 1-based indices and records 'subjects', [1 2]. Both that replayed command and pop_importbids(..., subjects=[1, 2]) resolve those indices to participant labels before listing files. A folder import records [STUDY, ALLEEG] = pop_importbids(...) with return_study on, plus the selected recordings, task, sessions, and runs. Replaying that command rebuilds the same study. A direct call still returns the datasets unless return_study=True. validate_bids does not write eegprep_bids_validation.json.

MATLAB was not run here. These five checks stay deselected unless --eeglab-backend=matlab is passed:

uv run --no-sync pytest tests/test_stream10_export_bids.py -k test_reference_ --eeglab-backend=matlab

  • test_reference_pop_export_decimal_places — %.7f text equals pop_export.m:179.
  • test_reference_pop_expica_save_ascii — f"{v:16.7e}" equals save -ascii (pop_expica.m:79). MATLAB argument order is whichica, then filename (pop_expica.m:81). Confirm the field width is 16, not the audit's 15.
  • test_reference_pop_expevents_table — Python urevent 0 and MATLAB urevent 1 both write 1.000000 (eeg_eventtable.m:123-159). Events are a NumPy structured array, because a list of dicts arrives as a cell and fieldnames fails (eeg_eventtable.m:95).
  • test_reference_bids_importeventfile_uses_value — skips if bids_importeventfile is missing. Expects stimulus/response from the value column (bids_importeventfile.m:14). The EEG includes setname and the other fields eeg_checkset reads at d0963be9 (eeg_checkset.m:687, :769, :1090, :1155, :1297), with chaninfo and etc as structs.
  • test_reference_pop_writeeeg_edf_length — skips if Biosig sopen is missing (pop_writeeeg.m:49). EEGPrep keeps 2112 samples. The EEGLAB file length is pnts rounded up to samples_in_datarecord from the header (writeeeg.m:139). The shared prefix matches within the EDF quantum, and the padded tail is the physical minimum.

test_pop_writeeeg_edf_record_duration_at_256_hz is a Python unit test, not a MATLAB reference test. It writes 1000 samples at 256 Hz through pop_writeeeg and checks the record duration and sample count on read-back.

The core .github/workflows/eeglab-reference.yml run was not started. Hands-on side-by-side GUI screenshots are still a pre-merge step.

Finding Root cause Fix Test
F11 Export menu opened a save picker and forced transpose on. pop_export, pop_writeeeg, and pop_exportbids open their EEGLAB dialogs. pop_expica and pop_expevents stay file pickers. Dialog specs, renderer exports, menu monkeypatch, Qt offscreen build.
F13 Task, participant, and event editors were free-text boxes. A list or ndarray subject rendered as sub-['001']. DialogSpecs use the MATLAB field tags. Subject code unwraps a one-element list or array before adding sub-. Renderer tests and sub-001 / sub-002 for a list and an ndarray.
F16 plotrad/shrink were None, so save failed, and import never built a study. None becomes an empty array. The import dialog returns an in-memory study and does not copy derivatives/eeglab. Save/reload, Oddball study command, cancel.
F17 One-second EDF records padded 2112 samples to 2200 and kept 11 of 17 events. Record length divides the sample count, with enough annotation signals for every event. History has no LASTCOM. EEGPrep keeps every sample. EEGLAB writeeeg.m:139 still uses a one-second record and Biosig fills the tail with the digital minimum. 2112 samples, 17 events, file quantum bound. The MATLAB file is pnts rounded up to its header record length; the shared prefix matches within that quantum and the tail is the physical minimum. Skips without Biosig. test_pop_writeeeg_edf_record_duration_at_256_hz checks 1000 samples at 256 Hz.
F24 Text used %.7g, ICA weights were tab-separated, events had no number column. %.Nf, concatenated %16.7e, and eeg_eventtable columns. File tests plus the three MATLAB text comparisons.
F25 Export omitted required sidecars, wrote event type 1.0, and validation reported 0 errors. A study export wrote every dataset as sub-01 and one participants row. The dialog history could not be replayed. Writes README, *_eeg.json, *_electrodes.tsv, and *_coordsystem.json. Each dataset uses EEG.subject, then STUDY.datasetinfo subject. createids assigns one sub-001-style id per subject, and participants.tsv has one row per subject. The dialog command includes the dataset list, task, license, changes, and createids. Sidecar names, sub-S01/sub-S02, one anonymized id for two sessions, empty-subject error, and a console replay that matches the output tree.
F123 Import took the type from trial_type and had no options dialog. The participant field treated 2 as a subject label. A folder history omitted return_study and the recordings filter, so a replay unpacked the datasets instead of the study and imported every recording. Probe list starts with value. Participant indices are 1-based into participants.tsv order, or sorted sub-* folders when that file is missing, and are mapped to labels before filtering. History records 'subjects', [1 2], 'recordings', and 'return_study', 'on' on [STUDY, ALLEEG] = pop_importbids(...). stimulus/response import, subjects 001 and 002 with bidssubjectsstr='2', history replay of [2] and [1 2], a 2-subject study replay, a recordings-filtered replay, and non-numeric / out-of-range errors.
F125 precision=7 wrote 7 significant digits, and an empty edit field fell through to 7 instead of the dialog default 4. %.Nf decimal places. The default 4 and 1E-3 are the edit value, so Ok with untouched fields writes 4 decimal places. Qt test presses Ok and checks 1.2346 is written and 1.2345679 is not.

Refs #555

Open in Web Open in Cursor 

File export and BIDS tools now follow the pinned EEGLAB dialogs and file
layouts: decimal-place text export, save -ascii ICA weights, event tables,
EDF/BDF length and annotations, value-column BIDS import, and the required
BIDS sidecars.

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

claude Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 0s —— View job


I'll analyze this and get back to you.

cursoragent and others added 4 commits November 6, 2026 01:11
Windows history was storing backslashes, so the command no longer matched
the derivatives/eeglab path checked on every platform.

Co-authored-by: Suraj Ranganath <[email protected]>
Electrodes and coordsystem files drop task- and desc-. Export and import
edit fields keep their dialog defaults. Subject codes unwrap a one-element
list, and validate_bids runs bids-validator when it is installed.

Co-authored-by: Suraj Ranganath <[email protected]>
The expevents, event-import, and EDF checks were sending list-of-dict
events and chanlocs, which MATLAB reads as cells, and an EEG missing
setname. The fixtures now use structured arrays and the fields
eeg_checkset reads, including setname and struct chaninfo and etc.

Co-authored-by: Suraj Ranganath <[email protected]>
EEGPrep keeps every sample. The MATLAB file is checked against the
header record length, the shared prefix uses the file quantum, and the
padded tail is the physical minimum.

Co-authored-by: Suraj Ranganath <[email protected]>
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 6, 2026 03:59

@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 6, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 37s —— View job


Reviewing PR #562

  • Gather context (diff, AGENTS.md)
  • Independent review passes (correctness, EEGLAB parity, conventions), running now
  • Validate findings
  • Post review

@suraj-ranganath
suraj-ranganath marked this pull request as draft November 6, 2026 04:22
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 6, 2026 04:31
@claude

claude Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 26s —— View job


Reviewing PR #562

  • Gather context (diff, AGENTS.md, review skill)
  • Independent review passes (correctness, EEGLAB parity, conventions)
  • Validate findings
  • Post review

@suraj-ranganath
suraj-ranganath marked this pull request as draft November 6, 2026 05:59
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 6, 2026 05:59
Keep both changelog entries after #558 and #563.

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

# Conflicts:
#	docs/source/changelog.rst
@suraj-ranganath
suraj-ranganath marked this pull request as draft November 6, 2026 07:38
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 6, 2026 07:38
@claude

claude Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 2m 7s —— View job


Code review

  • Overall assessment: Needs changes. The text, ICA and event exporters, the EDF record plan, the sidecars and the dialogs look right. The study export path to BIDS loses subject identity.
  • Highest-risk area: pop_exportbids called from File > Export > BIDS with a multi-subject STUDY.
  • Merge recommendation: Needs changes.

Blocking

  • Study export writes every dataset as sub-01 (pop_exportbids.py:235, _write_recordings). The menu path never passes subject, so the default "01" applies to every dataset. Ten subjects become sub-01 with runs 01 to 10. participants.tsv also gets only one row, because zip(datasets, subjects) at L255 pairs datasets with the unique labels. EEGLAB pop_exportbids.m groups files by EEG.subject, falls back to STUDY.datasetinfo.subject, and errors if both are empty. It also takes session and run from the dataset. createids=True has the opposite problem: each dataset gets its own new ID, so one subject's sessions are split across several fake subjects. Fix: take the label for each dataset from eeg["subject"] or the STUDY datasetinfo, apply createids per unique subject, and write one participants row per subject. Test: export two datasets with subjects S01 and S02, then assert both folders exist and participants.tsv has two rows. Fix this →

Important

  • The import dialog treats "participant indices" as subject labels (pop_importbids.py:210). EEGLAB parses the entry as numeric indices into participants.tsv (pop_importbids.m:163, :281). Here the strings go to bids_list_eeg_files as labels, so on a dataset with sub-001 …, typing 1 2 matches no files and the import fails. Fix: map the 1-based indices to labels in sorted participant order before filtering.
  • The GUI export's history command cannot be replayed (pop_exportbids.py:68). It always records LASTCOM = pop_exportbids(EEG, '<folder>');. The task, licence, CHANGES, createids and the dataset list are left out, so running it from the console exports a different thing. EEGLAB returns an empty comOut for the GUI path. Fix: record the full call with all the options, or return "" from the GUI path.

Nits

None.

Test gaps

  • No test exports more than one subject. The tests at L297, L350, L363 and L534 export single datasets, which is why the blocking bug above is not caught.

EEGLAB parity notes

  • I fetched pop_exportbids.m and pop_importbids.m from sccn/EEG-BIDS to check the two findings above, because src/eegprep/eeglab/ is not in this checkout. I could not inspect pyedflib here, so I did not check how setDatarecordDuration rounds a non-integer record length such as n/256 s. A MATLAB reference run with test_reference_pop_writeeeg_edf_length at a 256 Hz rate would cover it.
  • The PR description says the eeglab-reference.yml run and the side-by-side GUI screenshots are still outstanding. Both are needed before merge under AGENTS.md.

Inline comments are posted on the three findings.

run_counts: dict[str, int] = {}
subjects: list[str] = []
for index, eeg in enumerate(datasets, start=1):
subject_label = f"{index:02d}" if createids else str(subject).removeprefix("sub-")

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.

Blocking: study export puts every dataset under one subject.

File > Export > BIDS calls pop_exportbids(datasets, gui=True, require_study=True, study=...) without subject, so subject_label is "01" for every dataset. A study with subjects S01–S10 is written as sub-01/eeg/sub-01_task-X_run-01..10_eeg.set. participants.tsv gets only one row, because subjects holds unique labels while zip(datasets, subjects) at L255 pairs them by position.

EEGLAB groups files by EEG.subject, falling back to STUDY.datasetinfo.subject, and errors when both are empty (pop_exportbids.m, "get subjects and sessions" block). It also takes session and run from EEG.session and EEG.run. With createids=True this code goes the other way and gives each dataset its own new ID, which splits one subject's sessions across several fake subjects.

Fix: when exporting a study (or whenever eeg["subject"] is set), derive the label per dataset from eeg["subject"] or study["datasetinfo"][i]["subject"]. Unwrap it with _subject_text, as bids_tools does. Map createids over the unique subjects, and build participants.tsv from one row per unique subject. Add a test that exports two datasets with subject "S01" and "S02" and asserts sub-S01/ and sub-S02/ exist, with two participants rows.

if chosen:
options["recordings"] = chosen
if result.get("bidssubjects"):
subjects = _split_list(result.get("bidssubjectsstr"))

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: "participant indices" are used as subject labels.

The checkbox says Import only the following participant indices, and EEGLAB treats the entry as numeric indices into participants.tsv. It runs str2double(res.bidssubjectsstr) (pop_importbids.m:163), then opt.subjects = opt.subjects+1 (:281). Here the raw strings go to bids_list_eeg_files(subjects=...) as BIDS labels. On a dataset with sub-001 … sub-010, typing 1 2 matches no files, and the import fails with "no supported EEG files found".

Fix: parse the entries as 1-based integers and map them through the sorted subject list (participants.tsv order, or sub-* folder order when that file is missing) to labels before filtering. Also emit numeric 'subjects', [1 2] in the history command. Add a test using the existing scanned-selector fixture with subjects 001/002 and bidssubjectsstr="2".

(root / "CHANGES").write_text(str(changes).rstrip() + "\n", encoding="utf-8")
subjects = _write_recordings(root, datasets, subject=subject, task=task, createids=createids, task_info=task_info)
_write_participants(root / "participants.tsv", datasets, subjects)
command = f"LASTCOM = pop_exportbids(EEG, {format_history_value(root)});"

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 GUI export's history command does not reproduce the export.

After the study wizard, the command recorded is always LASTCOM = pop_exportbids(EEG, '<folder>');. It leaves out the task name, licence, CHANGES and createids, and it names EEG rather than the study datasets. Replaying it from eegprep-console exports only the current dataset, with task='eeg'. EEGLAB returns an empty comOut for the GUI path because of this same problem (the history block at the end of pop_exportbids.m is commented out).

Fix: either pass the dialog-chosen task, license, changes and createids into the command, with the dataset list (ALLEEG), or return "" from the GUI path, as EEGLAB does. The second option means menu_actions skips history (it already returns early on an empty command).

Study export reads EEG.subject, then STUDY.datasetinfo, and writes one
participants row per subject. Import participant indices are 1-based.
The export dialog history includes task, license, changes, and createids.

Co-authored-by: Suraj Ranganath <[email protected]>
@suraj-ranganath
suraj-ranganath marked this pull request as draft November 6, 2026 08:26
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 6, 2026 08:26
@claude

claude Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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


Code review (re-review of 7ff0dc0)

  • Overall assessment: Needs changes, one small fix. The three earlier findings are fixed:
    • Each dataset now gets its subject from EEG.subject and falls back to STUDY.datasetinfo. The export raises when both are empty. createids numbers each unique subject once, and participants.tsv has one row per subject.
    • The import dialog maps 1-based participant indices to labels.
    • The export dialog records a full command that a test replays.
  • Highest-risk area: replaying the pop_importbids history command after a participant-index selection.
  • Merge recommendation: Needs changes.

Blocking

None.

Important

  • A replayed 'subjects', [1 2] imports different subjects (pop_importbids.py:215, _history_command L440, _list_filters L354). The dialog filters on subject_labels, but the history records only the 1-based indices. When the command is replayed, subjects=[1, 2] goes to bids_list_eeg_files, which reads integer subject queries as 0-based indices into the sorted labels (bids_list_eeg_files.py:95-101). With sub-001/sub-002, replaying 'subjects', [2] filters to nothing and raises "no supported EEG files found". Replaying [1 2] loads only 002. Fix: in _list_filters, when the subjects kwarg is a list of ints, resolve it with _indexed_participants and _check_participant_indices, as the dialog does. Then extend test_import_dialog_participant_indices_are_one_based to replay the command. Details are in the inline comment. Fix this →

Nits

None.

Test gaps

  • test_import_dialog_participant_indices_are_one_based checks only the command text ('subjects', [2]) and never runs the command. A replay check like the one in test_export_dialog_history_replays_the_same_tree would catch the finding above.

EEGLAB parity notes

  • I checked the new subject, session and run resolution against the pop_exportbids.m subject block, as cited at L308, and the createids numbering against bids_export.m:605-608. Both match.
  • I could not run Python in this session, so the replay finding comes from reading _list_filters and bids_list_eeg_files. It has not been executed.
  • Still needed before merge under AGENTS.md: the eeglab-reference.yml run (this PR changes pop_writeeeg, pop_export and the BIDS I/O) and the side-by-side GUI screenshots.

indices = _participant_indices(text)
labels = _indexed_participants(source)
_check_participant_indices(indices, labels)
options["subjects"] = indices

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 recorded 'subjects', [1 2] imports different subjects when replayed.

indices = _participant_indices(text)
labels = _indexed_participants(source)
_check_participant_indices(indices, labels)
options["subjects"] = indices
# pop_importbids.m:281 adds 1 because participants.tsv row 1 is the header.
options["subject_labels"] = [labels[index - 1] for index in indices]
folder = str(result.get("folder") or "").strip()

In the dialog, these numbers are 1-based indices into participants.tsv. The filter actually uses subject_labels. The history command at L440-L442 records only the numeric subjects. When that command is replayed, subjects=[1, 2] falls through _list_filters (L354) to bids_list_eeg_files. That function treats integer subject queries as 0-based indices into the sorted subject labels:

else:
# index the applicable values (eg subjects) with integers, alphabetically
# strip any missing candidates
data_values = [dv for dv in data_values if dv is not None and dv != '']
data_values = [str(dv) for dv in data_values]
uq_values = sorted(set(data_values))
# rewrite the query values into the first k sorted unique strings

With sub-001/sub-002:

  • The dialog with 2 loads 002 and records 'subjects', [2]. Replaying it drops the out-of-range index 2, filters to nothing, and raises "no supported EEG files found".
  • The dialog with 1 2 loads both subjects. Replaying it loads only 002.

The order can differ too. The dialog uses participants.tsv order, while the replay sorts the labels.

Fix: make the command-line subjects= option resolve integers the same way the dialog does. In _list_filters, when kwargs["subjects"] holds ints, map them through _indexed_participants(source) with _check_participant_indices, as _import_dialog does. Then the recorded [1 2] replays the same import and matches EEGLAB's 'subjects' (pop_importbids.m:281). Extend test_import_dialog_participant_indices_are_one_based to replay command and check that it loads the same subjects.

Dialog history and pop_importbids(subjects=[1, 2]) both use 1-based
participant positions, so replaying the command imports the same subjects.

Co-authored-by: Suraj Ranganath <[email protected]>
@suraj-ranganath
suraj-ranganath marked this pull request as draft November 6, 2026 08:51
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 6, 2026 08:51
@claude

claude Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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


Code review (re-review of d9c1eb4)

  • Overall assessment: Needs changes, two small fixes. The finding from the last review is fixed. pop_importbids(subjects=[1, 2]) and a replayed dialog command now both map 1-based participant indices to labels before listing files. Index 0 and indices past the end raise clear errors. The new test replays both [2] and [1 2]. Both remaining problems are in how the import's history command replays in eegprep-console.
  • Highest-risk area: replaying the [STUDY, ALLEEG] = pop_importbids(...) command that File > Import > BIDS writes to history.
  • Merge recommendation: Needs changes.

Blocking

None.

Important

  • The study import command does not give back a STUDY when replayed (pop_importbids.py:473-475, _history_command). The menu path records [STUDY, ALLEEG] = pop_importbids(...). The console turns that into STUDY, ALLEEG = pop_importbids(...), and that call has no return_study=True, so it returns the plain EEG list:

    • With 2 datasets, STUDY silently becomes the first EEG dict.
    • With 3 or more datasets, the unpack raises.

    Fix: record something that brings back the study return on replay, or make the two-output form the default for folder imports, which is what EEGLAB returns. Add a replay test. Fix this →

  • The recordings choice is not recorded (pop_importbids.py:470). The dialog filters on recordings, but the history loop leaves it out, so a replay imports every device. There is a one-line suggestion inline.

Nits

None.

Test gaps

  • tests/test_stream10_export_bids.py:384 checks only the prefix of the [STUDY, ALLEEG] command. Replaying it the way test_export_dialog_history_replays_the_same_tree does would catch the first finding.

EEGLAB parity notes

  • EEGLAB pop_importbids always returns [STUDY, ALLEEG], so the recorded two-output command is the right shape. Only the Python replay is wrong.
  • I could not run Python in this session, so both findings come from reading _history_command, menu_actions._import_dataset and console._console_python_command. Neither has been executed.
  • Still needed before merge under AGENTS.md: the eeglab-reference.yml run (this PR changes pop_writeeeg, pop_export and the BIDS I/O) and the side-by-side GUI screenshots.

Comment on lines +473 to +475
call = f"pop_importbids({', '.join(parts)})"
if return_study:
return f"[STUDY, ALLEEG] = {call};"

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 File > Import > BIDS history command does not give back a STUDY when replayed.

parts.extend([format_history_value(key), format_history_value(dialog[key])])
call = f"pop_importbids({', '.join(parts)})"
if return_study:
return f"[STUDY, ALLEEG] = {call};"
return f"EEG = {call};"

menu_actions._import_dataset calls this with return_study=True and echoes [STUDY, ALLEEG] = pop_importbids('<bids>', ...) to eegprep-console. _console_python_command turns that into STUDY, ALLEEG = pop_importbids(...), and that call has no return_study. So the function returns the plain EEG list (or a single dict) instead of (study, datasets):

  • With 2 datasets, STUDY becomes the first EEG dict and ALLEEG the second. Nothing raises.
  • With 3 or more datasets, the unpack raises ValueError.
  • With 1 dataset, Python unpacks the dict's keys.

This is the GUI-to-console replay path that AGENTS.md asks to keep seamless.

Fix: put something in the recorded command that brings back the study return when the console replays it. One way is to emit a 'return_study' pair that the keywordizer turns into return_study=True. Another is to make the two-output form the default for folder imports, which is what EEGLAB pop_importbids always returns. Then add a replay check next to the return_study=True test at tests/test_stream10_export_bids.py:384. That test checks only the command prefix today.

parts.extend([format_history_value("studyName"), format_history_value(dialog["studyName"])])
if dialog.get("outputdir"):
parts.extend([format_history_value("outputdir"), format_history_value(Path(dialog["outputdir"]))])
for key in ("bidstask", "sessions", "runs", "subjects"):

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 recordings choice from the dialog is not in the history command.

_import_dialog sets options["recordings"], and _list_filters uses it to filter, but this loop leaves out recordings. On a multi-device dataset, replaying the command imports every recording, not just the ones chosen in the dialog. That is the same replay mismatch as the subject-index fix in d9c1eb4.

Suggested change
for key in ("bidstask", "sessions", "runs", "subjects"):
for key in ("bidstask", "sessions", "runs", "recordings", "subjects"):

The dialog history now records return_study on and the selected recordings, so running that command again rebuilds the same STUDY and ALLEEG.

Co-authored-by: Suraj Ranganath <[email protected]>
@suraj-ranganath
suraj-ranganath marked this pull request as draft November 6, 2026 09:19
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 6, 2026 09:19
@claude

claude Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 37s —— View job


Code review (re-review of e2ba7b6)

  • Overall assessment: Looks good. Both findings from the last review are fixed:
    • Study replay. A study import's history command now includes 'return_study', 'on'. _on_off turns that 'on'/'off' text into a boolean, so replaying [STUDY, ALLEEG] = pop_importbids(...) in the console gives back (study, datasets) and not the plain EEG list. Any other text raises an error that names pop_importbids.
    • Recordings in history. The dialog's recordings choice is now saved in the history command. _list_filters passes it to bids_list_eeg_files(recordings=...).
  • Highest-risk area: None identified in this commit.
  • Merge recommendation: Safe to merge once the two pre-merge steps below are done.

Blocking

None.

Important

None.

Nits

None.

Test gaps

None. test_import_dialog_study_history_replays_two_subjects and test_import_dialog_recordings_history_replays_the_same_datasets replay the command through _console_python_command in an EEGPrepConsoleWorkspace. They check that the replay gives the same study name, dataset count, subjects and recordings as the dialog import. That covers the replay gap from the last review. Dropping the startswith("[STUDY, ALLEEG] = ...") prefix check at L384 is fine, because the replay tests check more than the prefix did.

EEGLAB parity notes

  • Recording 'return_study', 'on' matches the [STUDY, ALLEEG] return that pop_importbids.m always gives. A direct Python call still returns datasets by default, as the docstring, the help page and bids_workflow.rst say.
  • _folded makes the studyName, bidstask, subjects, sessions, runs and recordings lookups ignore case, the same way _DIALOG_KEYS already matches keys in lowercase. This matches how MATLAB finputcheck reads option names.
  • I couldn't run the tests in this session, because running pytest needed an approval I didn't have. These findings come from reading pop_importbids.py, console._console_python_command and bids_list_eeg_files.py. CI is the evidence that the tests pass.
  • Still needed before merge, per AGENTS.md:
    • Run eeglab-reference.yml on this branch, because the PR changes pop_writeeeg, pop_export, pop_expica, pop_expevents and the BIDS I/O.
    • Attach the side-by-side GUI screenshots.

Checked for correctness bugs, EEGLAB parity, data structure compatibility, changed-behavior tests, and CLAUDE.md/AGENTS.md compliance.

Copy link
Copy Markdown
Member Author

Review follow-up at e2ba7b6.

Fixed (all review rounds):

  • r2: pop_exportbids now uses each dataset's own subject; pop_importbids participant indices are 1-based; the GUI export history now replays (an intentional improvement over EEGLAB's empty command, documented); EDF record length at 256 Hz is tested.
  • r3: integer subjects now go through a single 1-based path (_resolve_subject_query, matching pop_importbids.m L163/L281), and a replay test failed before the fix.
  • r4: the study-import history now records 'return_study','on' and includes 'recordings'. Two replay tests (two subjects, recordings filter) failed before the fix.
  • r5: no code findings.

Process points:

  • MATLAB reference: eeglab-reference.yml only runs on workflow_dispatch, and the hosted runner hasn't passed since October. The reference suite ran on our MATLAB R2025b bench instead, pinned to EEGLAB d0963be9 and eeglab_tests fec88f9f. Results at d9c1eb4: 6/6 Stream 10 references passed, including the 256 Hz EDF length oracle. Subject selection matches EEGLAB pop_importbids for subjects=2 and [1 2]. e2ba7b6 only changes the recorded history command, so the numbers are unaffected.
  • GUI: side-by-side and replay screenshots were captured for each round:
    • two-subject export to sub-S01/sub-S02;
    • createids;
    • import of 2 and 1 2;
    • helpful errors for bad input;
    • console replay of the study and recordings-filtered imports, which rebuild the same STUDY/ALLEEG.

CI is green on Ubuntu 3.12/3.13, macOS and Windows.

@suraj-ranganath
suraj-ranganath merged commit 9364de6 into develop Nov 6, 2026
11 checks passed
@cursor cursor Bot mentioned this pull request Nov 6, 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.

2 participants