Skip to content

[BIDS] Match the EEGLAB layout of the BIDS import window - #720

Merged
arnodelorme merged 2 commits into
developfrom
agent/issue-707
Nov 27, 2026
Merged

arnodelorme merged 2 commits into
developfrom
agent/issue-707

Conversation

@arnodelorme

@arnodelorme arnodelorme commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

The pop_importbids dialog sizes its columns and rows by EEGLAB's geometry, so the task, run and participant controls line up, the run list is short and greyed while unchecked, and the window has EEGLAB's width. The event type popup lists every events.tsv column, value first, as EEGLAB does. The import code is unchanged.

Captures (EEGLAB, before, after) and tests: https://github.com/adelorme-assistant/project_eegprep/blob/main/reports/pr-707/issue-707_before_after.pdf (Word: https://github.com/adelorme-assistant/project_eegprep/blob/main/reports/pr-707/issue-707_before_after.docx)

Fixes #707
Part of #742

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

Copy link
Copy Markdown
Contributor

Claude finished @arnodelorme's task in 1m 17s —— View job


Code review

  • Overall assessment: Needs one small fix. The layout changes use DialogSpec fields that already exist (size, extra_stylesheet, geomvert, weighted_columns): geomvert row heights, weighted columns, fixed width and the greyed disabled listbox. The import path (_import_dialog, _loader_options, history) is unchanged.
  • Highest-risk area: _event_columns now reads events.tsv headers with its own decoder instead of the shared BIDS one.
  • Merge recommendation: Needs changes.

Blocking

None.

Important

  • _event_columns skips decode_bids_text (src/eegprep/plugins/EEG_BIDS/pop_importbids.py:373-378). The old code read headers with read_bids_table, which calls decode_bids_text (sidecar.py:14). That helper strips a UTF-8 BOM and falls back to Latin-1 for TSV files. The new events.open(encoding="utf-8") does neither:

    • BOM files: a UTF-8 BOM events.tsv (common from Excel) yields a "onset" column. It isn't in _TIMING_COLUMNS, so it appears in the event type popup.
    • Latin-1 files: a Latin-1 events.tsv raises UnicodeDecodeError and is silently skipped. Its columns disappear from the popup, even though pop_load_frombids reads that file fine through read_bids_table.

    Fix: open the file with "rb", decode the first line with decode_bids_text(..., suffix=".tsv") and drop the UnicodeError catch. The inline comment has a committable suggestion. Add a header written with encoding="utf-8-sig" to the new test.

Nits

  • The width in size=(1078, ...) is a bare number, while _DIALOG_BASE_HEIGHT and _DIALOG_ROW_HEIGHT are named constants. AGENTS.md asks for named constants for semantically important numbers. Add a _DIALOG_WIDTH next to them that says where 1078 comes from in EEGLAB.

Test gaps

None beyond the BOM/Latin-1 header case above. The new test covers the behavior that changed: columns are combined across files and ordered with value first, the task, run and participant controls line up, the run list is disabled and shorter.

EEGLAB parity notes

  • I couldn't check the EEGLAB source line by line: the EEG-BIDS plugin isn't vendored under src/eegprep/eeglab/plugins/, so pop_importbids.m lines 86-92 and 127 and bids_geteventfieldsfromfolder weren't available. The described behavior matches my reading of upstream EEG-BIDS: every *events.tsv column, timing columns removed, sorted, value first.
  • Not confirmed, because the source wasn't available:
    • whether upstream also scans derivatives/. rglob now reads every events file, where the old code stopped after the first.
    • whether its excluded-column list is exactly onset/duration/sample/stim_file/response_time.
  • I didn't run the tests: running pytest wasn't permitted in this job.

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

Comment on lines +373 to 378
for events in source.rglob("*events.tsv"):
try:
table = read_bids_table(events)
except (OSError, UnicodeError, ValueError):
with events.open(encoding="utf-8") as stream:
found.update(stream.readline().rstrip("\r\n").split("\t"))
except (OSError, UnicodeError):
continue

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: this header read skips decode_bids_text (

def decode_bids_text(payload: bytes, *, suffix: str) -> str:
"""Decode one BIDS sidecar.
UTF-8 is tried first and a leading UTF-8 BOM is removed. A ``.tsv`` file
that is not valid UTF-8 is decoded as Latin-1, so each byte keeps its
Unicode code point. The micro-sign byte ``0xB5`` stays µ, and ``0x80``
stays U+0080. JSON that is not UTF-8 raises ``UnicodeDecodeError``.
"""
try:
return payload.decode("utf-8-sig")
except UnicodeDecodeError:
if not _is_tsv(suffix):
raise
return payload.decode("latin-1")
), which the old read_bids_table path used.

  • A UTF-8 BOM file produces a "onset" column. That name isn't in _TIMING_COLUMNS, so it shows up in the event type popup.
  • A Latin-1 events.tsv raises UnicodeDecodeError and is silently skipped. pop_load_frombids reads the same file through read_bids_table, so the import can use those columns but the user can't pick them.

Decode the header with the shared helper instead (and import decode_bids_text from sidecar):

Suggested change
for events in source.rglob("*events.tsv"):
try:
table = read_bids_table(events)
except (OSError, UnicodeError, ValueError):
with events.open(encoding="utf-8") as stream:
found.update(stream.readline().rstrip("\r\n").split("\t"))
except (OSError, UnicodeError):
continue
for events in source.rglob("*events.tsv"):
try:
with events.open("rb") as stream:
header = decode_bids_text(stream.readline(), suffix=".tsv")
except OSError:
continue
found.update(header.rstrip("\r\n").split("\t"))

The import line also has to change: from eegprep.plugins.EEG_BIDS.sidecar import decode_bids_text, read_bids_table. A header written with encoding="utf-8-sig" in the new test would cover this.

@arnodelorme

Copy link
Copy Markdown
Collaborator Author

🤖 Captures: EEGLAB, EEGPrep before and EEGPrep after, taken on jamming under a virtual screen.

BIDS import window

BIDS import window

@arnodelorme

Copy link
Copy Markdown
Collaborator Author

The review bot found that the event type popup read the events.tsv headers without the shared BIDS decoder, so a file saved with a UTF-8 BOM showed a column named "onset" with an invisible BOM character in front and a Latin-1 file was skipped. Commit 945d3b9 now decodes the header with decode_bids_text, adds a BOM file to the dialog test, and names the 1078 pixel width (_DIALOG_WIDTH, the width of EEGLAB's captured window).

The test file tests/test_file_menu_audit_673.py passes (68 tests); the one failure, test_real_testmff_matches_eeglab_epochs, is unrelated and comes from defusedxml missing in this local environment. The new BOM case fails on the previous commit and passes now.

— orchestrator

@arnodelorme
arnodelorme merged commit 40416e3 into develop Nov 27, 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.

pop_importbids window: look the same as EEGLAB's (bids_import); BIDS export ignored for now

1 participant