Repository navigation
[Phase 1b] Add dataset metadata dialogs - #71
Conversation
|
Claude finished @suraj-ranganath's task in 4m 10s —— View job Claude Code PR Review
SummaryThis is a solid first slice of Phase 1b. Both Main review points (inline)
Smaller observations (not posted inline)
Tests / docs
Nothing here is a blocker; the inline points (especially #1 and #4) are worth resolving before this lands on |
|
🤖 Phase 1b PR 1 implementation note Problem Approach Key code if gui:
result = inputgui(pop_editset_dialog_spec(EEG), renderer=renderer)
if result is None:
return (EEG, "") if return_com else EEG
options = _changed_options_from_gui(EEG, result)
if not options:
return (EEG, "") if return_com else EEG
output = copy.deepcopy(EEG)
old_xmin = float(output.get("xmin", 0.0) or 0.0)
old_srate = float(output.get("srate", 1.0) or 1.0)
for key, value in options.items():
if key == "dataformat":
continue
_assign_option(output, key, value, dataformat=str(options.get("dataformat", "ascii")))
if "xmin" in options:
_adjust_event_latencies_for_xmin_change(output, old_xmin, old_srate)Tests Visual parity
|
| def _history_value(value: Any) -> str: | ||
| if _is_empty_value(value): | ||
| return "[]" | ||
| if isinstance(value, Mapping): | ||
| return repr(dict(value)) | ||
| if isinstance(value, np.ndarray) and value.dtype == object: | ||
| value = value.tolist() | ||
| if isinstance(value, (list, tuple)) and any(isinstance(item, Mapping) for item in value): | ||
| return repr(value) | ||
| return format_history_value(value) |
There was a problem hiding this comment.
🤖 _history_value falls back to Python repr() for Mapping and lists/tuples that contain mappings. That produces a Python-style literal (e.g. [{'labels': 'Cz'}]), not the MATLAB struct/cell array syntax EEGLAB history expects. If a caller does pop_editset(EEG, 'chanlocs', [{'labels': 'Cz'}]) the recorded history command can't be replayed in EEGLAB and arguably not even in this codebase's own console without further translation.
Given the dialog never exercises chanlocs/icaweights/icasphere from the GUI in this PR and the command-line chanlocs path is the only Mapping-bearing branch, consider one of:
- restricting history coverage to scalar/text/numeric options for now (drop the Mapping/list-of-dict branch and raise/skip), or
- emitting a MATLAB-style placeholder like
'<struct>'so the history at least documents that something happened without misleading by-value contents.
This is also a parity claim worth a unit test once a representation is chosen.
| def _truthy_concat(value: bool | int | str) -> bool: | ||
| if isinstance(value, str): | ||
| return value.strip().lower() in {"1", "true", "yes", "on"} | ||
| return bool(value) |
There was a problem hiding this comment.
🤖 _truthy_concat accepting "true"/"yes"/"on" strings doesn't match EEGLAB (which only takes the numeric 1 flag) and the signature concat: bool | int | str advertises it as a public knob. Per AGENTS.md "No speculative configurability… No backward compatibility by default," this looks like dead surface. Suggest reducing to bool(value) (with the existing tests narrowed to ints/bools) and trimming the type hint to bool | int.
| if result is None: | ||
| return (EEG, "") if return_com else EEG | ||
| options = _changed_options_from_gui(EEG, result) | ||
| if not options: | ||
| return (EEG, "") if return_com else EEG |
There was a problem hiding this comment.
🤖 The GUI cancel / no-change paths return EEG itself (not a copy.deepcopy). Downstream callers can therefore mutate the session dataset through the returned reference, which is asymmetric with the success path (which returns a deepcopy). test_pop_editset_gui_cancel_or_no_changes_returns_original_without_history even pins this behavior with assert cancelled is eeg.
pop_comments on line 39 returns a deepcopy on cancel (its test asserts cancelled is not eeg). The two pop functions added in this PR disagree on the contract — worth aligning. I'd lean toward pop_comments's deepcopy, since "cancel" is a no-op in the user's mental model and the immutability invariant in the rest of the suite assumes pop_* returns a fresh dict.
| for key, value in options.items(): | ||
| if key == "dataformat": | ||
| continue | ||
| _assign_option(output, key, value, dataformat=str(options.get("dataformat", "ascii"))) |
There was a problem hiding this comment.
🤖 dataformat is parsed into options and threaded into _assign_option, but the only place it's actually consumed is _assign_data's file-string branch, which always raises NotImplementedError. The history loop also special-cases dataformat only when it is the sole option:
if key == "dataformat" and len(options) == 1:
continueSo today dataformat is effectively dead: never applied, sometimes recorded into history, and _SUPPORTED_FIELDS advertises it. Per AGENTS.md "no speculative configurability," I'd drop the field entirely until file-format data assignments are actually supported (Phase 1b channels), and remove dataformat= from _assign_option/_assign_data.
| elif name == "pop_comments": | ||
| from eegprep.functions.popfunc.pop_comments import pop_comments | ||
|
|
||
| out = pop_comments(selection, "About this dataset", return_com=True) |
There was a problem hiding this comment.
🤖 The menu hard-codes "About this dataset" as the dialog title regardless of dataset. EEGLAB's pop_comments in the GUI builds its title from EEG.setname-style context (e.g. "Comments of dataset: <setname>") rather than a constant — see the MATLAB pop_comments.m header logic. For the eventual EEGLAB-parity capture this means the screenshot will diverge from MATLAB once a real dataset is loaded.
Two options: (1) pass f"About \"{eeg.get('setname', 'this dataset')}\"" (closer to MATLAB), or (2) pass "" and let pop_comments_dialog_spec's title or "Read/Enter text -- pop_comments()" fallback handle it. Either makes the visual parity test more robust than a constant string.
| def _normalize_ica_index_field(output: dict[str, Any]) -> None: | ||
| value = output.get("icachansind") | ||
| if value is None: | ||
| return | ||
| array = np.asarray(value) | ||
| if array.size == 0: | ||
| output["icachansind"] = np.array([], dtype=int) |
There was a problem hiding this comment.
🤖 _normalize_ica_index_field only acts when the assigned array is empty — it leaves a non-empty icachansind whatever shape/dtype it landed in from the user. But _as_int_array (which the icachansind branch of _assign_option already calls) returns a 1-D int array, so this function is a no-op for assignments that go through pop_editset and only matters for pre-existing data on EEG. If that's the actual purpose (normalizing legacy session state), please add a brief comment; otherwise this helper duplicates _as_int_array and can be removed.
a9a0f0d to
7101a26
Compare
|
@claude review this |
|
Claude finished @suraj-ranganath's task in 3m 37s —— View job Claude Code PR Review
Status of previous review findingsThe follow-up commit
Tests, console-workspace coverage, package exports, and Open findings (worth resolving)1. Menu still passes a hard-coded title to out = pop_comments(selection, "About this dataset", return_com=True)This was flagged in the previous round and remains unchanged. EEGLAB builds the dialog title from the loaded dataset (e.g. 2. 3. if data.ndim == 2 and pnts > 1:
frames = int(data.shape[1])
if frames % pnts:
if trials > 1 and frames // pnts > 0:
...
else:
pnts = frames
trials = 1
4. Smaller observations (not blocking)
Tests / docs
Nothing here is a hard blocker for landing on |
e4c6966 to
0c8747b
Compare


Add pop_comments and pop_editset dataset-metadata workflows with GUI menu dispatch, EEGPrep console-compatible history, and packaged help. Adds focused unit, GUI, menu, console, sample-data, and visual parity coverage for this first Phase 1b slice.
Part of #67