Skip to content

pop_studydesign: Open legacy designs and place their independent variables in the reference panel - #1027

Merged
arnodelorme merged 6 commits into
developfrom
agent/issue-968-studydesign
Dec 1, 2026
Merged

arnodelorme merged 6 commits into
developfrom
agent/issue-968-studydesign

Conversation

@arnodelorme

@arnodelorme arnodelorme commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

🤖 Part of #968 and #875. Open legacy designs and place their independent variables in the reference panel. Stacked on #974.

Live MATLAB, EEGPrep before and after

Function output distances

Vertical control offsets

Native measurements and validation

On the N400 reference STUDY, the old Qt public call failed on an empty MATLAB variable label. The repaired figure is 514 × 421 and MATLAB is 507 × 421, with a maximum row offset of 0.42 px. The earlier width of the variable summary initially stretched the window. The current code populates that list after sizing as in the native reference. Unchanged and newly added designs returned identical design counts, selected indices, names, subjects and factors across the two native dialogs. The regression and geometry suites passed 124 tests. Test submissions turned off resaving the reference STUDY.

Full inventory report for the project team. pop_studydesign (p. 55). PDF · Editable Word.

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

Copy link
Copy Markdown
Contributor

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


Code review

  • Overall assessment: Needs changes. The panel layout and the empty-label guards look correct. The one problem is that pressing OK on a legacy STUDY with no edits now rewrites its design.
  • Highest-risk area: studydesign_editor_state filtering vs. commit_studydesign_editor change detection
  • Merge recommendation: Needs changes

Blocking

None.

Important

  • pop_studydesign.py, studydesign_editor_state (L287–288): OK rewrites legacy designs nobody edited.
    • What happens: the editor state removes variables with empty labels. commit_studydesign_editor then compares each state design with the original design using _same_design, and the original still has the extra entry. The check fails, so pressing OK with no changes re-runs std_makedesign on the legacy design and adds that command to history.
    • Why it matters: this is the exact case the PR adds support for. History gains a command the user never made, and the stored design is rebuilt.
    • Not verified by running: I couldn't run code in the review sandbox. The native comparison in the PR description checks design counts and factors but not the returned command.
    • Fix: apply the same filter to original before comparing, or filter only for display. Details are in the inline comment.

Nits

None.

Test gaps

  • test_studydesign_opens_legacy_empty_variable_and_preserves_other_factors covers building the dialog and the panel geometry. It doesn't cover pressing OK. Add one assertion: commit_studydesign_editor(study, datasets, studydesign_editor_state(study, datasets), resave=False) returns "" for that legacy study.

EEGLAB parity notes

None. These look fine:

  • The supergui geom cells.
  • Skipping the QGroupBox when the window is sized: measured returns a "panel" with zero extent, so it doesn't change the window size.
  • Filling the variable summary after sizing via fit_width=False.

The vendored EEGLAB tree is missing from this checkout, so I couldn't compare line by line against pop_studydesign.m.

Also checked: std_getindvar._append_design_values now skips empty labels with _empty_value instead of str(label or ""), which removes the empty-array crash. _read_widget on the tagged QGroupBox returns None, which is harmless. The Sphinx note in study_workflows.rst matches the change.

"""Return the mutable design-editor state shared by the dialog callbacks."""
designs = [deepcopy(design) for design in study.get("design") or [] if isinstance(design, dict)]
for design in designs:
design["variable"] = [var for var in _ensure_variable_list(design) if not is_matlab_empty(var.get("label"))]

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: OK rewrites a legacy design the user never touched. Removing empty-label variables here means state["designs"] no longer equals STUDY.design. commit_studydesign_editor (L536–544) then runs _same_design(original[index - 1], design) (

def _same_design(left: dict[str, Any], right: dict[str, Any]) -> bool:
return _plain_value(left) == _plain_value(right)
). The original still has the extra variable entry, so the check fails. Opening a legacy STUDY and pressing OK without changes therefore re-runs std_makedesign for that design and adds a std_makedesign(...) command to LASTCOM/history.

I couldn't run this in the review sandbox, so this comes from reading the code. The PR description's native comparison checks design counts and factors but not the returned history command.

Suggested fix: compare the original after applying the same filter, for example a small _without_empty_variables(design) helper used here and on original in commit_studydesign_editor. Alternatively, filter only when building variable_summary_lines/variables. Also add a test asserting that commit_studydesign_editor(study, ds, studydesign_editor_state(study, ds), resave=False) returns an empty command for the legacy study built in test_studydesign_opens_legacy_empty_variable_and_preserves_other_factors.

@arnodelorme
arnodelorme changed the base branch from agent/issue-939-study-geom to develop December 1, 2026 06:54
# Conflicts:
#	docs/source/api/study_workflows.rst

@arnodelorme arnodelorme left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review was written by an AI assistant during a nightly check, not by Arno.

Code review

  • Overall assessment: Needs changes. The supergui geometry, panel sizing, and Python-dict empty-label guard match pop_studydesign.m, while legacy .study MAT files loaded via pop_loadstudy still hit NumPy 2.x empty-array ValueError crashes on open or OK.
  • Highest-risk area: Legacy MATLAB empty-array handling in std_getindvar.py and pop_studydesign.py
  • Merge recommendation: Needs changes

Blocking

None.

Important

  • std_getindvar.py, _append_design_values (L106-L119): Empty vartype or value arrays still crash before or after the new _empty_value(label) check.

    • Why it matters: When an unassigned MATLAB struct slot or a legacy .study MAT file loaded by pop_loadstudy has vartype or value stored as '' or [], convert_matlab turns those fields into size-0 NumPy arrays (np.empty((0, 0))). Line 107 evaluates variable.get("vartype") or "categorical" before line 109 checks _empty_value(variable.get("label")), and lines 106 and 116 use or [] on design.get("variable") and variable.get("value"). Under NumPy 2.x, bool(np.empty((0, 0))) raises ValueError: The truth value of an empty array is ambiguous, so pop_studydesign_dialog_spec still fails to open such designs.
    • Suggested fix: Check _empty_value(variable.get("label")) first, derive vartype as "categorical" if _empty_value(variable.get("vartype")) else str(variable["vartype"]) (matching pop_studydesign.m L176-L178 and std_checkset.m L378-L383), and guard design.get("variable") and variable.get("value") with _empty_value(...) rather than or [].
  • pop_studydesign.py, _without_empty_variables and commit_studydesign_editor (L286, L526-L536, L628-L631): Pressing OK on a MAT-loaded legacy STUDY raises ValueError on remaining size-0 NumPy fields.

    • Why it matters: pop_loadstudy converts empty MATLAB strings and arrays inside STUDY["design"] (such as design["filepath"] = '' or a continuous variable's value = []) to np.empty((0, 0)). _without_empty_variables removes empty-label variables while leaving those other size-0 arrays intact on both original and state["designs"]. Pressing OK without edits calls _same_design (L684-L699), where _plain_value leaves size-0 np.ndarray values unconverted (value.item() fails for size != 1) and dict equality raises ValueError: The truth value of an empty array is ambiguous. Editing the design and pressing OK hits the same ValueError in _options_from_editor_design (if design.get("filepath"): at L682), and opening a MAT-loaded design with a continuous variable hits it in variable_summary_lines (variable.get("value") or [] at L260).
    • Suggested fix: Normalize MATLAB-empty fields inside _without_empty_variables (replace is_matlab_empty filepath with "", include with [], and kept variable value / vartype with [] / "categorical"), and convert np.ndarray values via .tolist() in _plain_value so any extra empty MATLAB fields (such as limo) compare cleanly.

Nits

  • qt.py, _build_widget and _apply_eeglab_style (L422-L423, L918-L923): QGroupBox panel titles miss the 16 px font size and #000066 text color.
    • Why it matters: _apply_font_hints calls widget.setFont(font) while the QGroupBox has no parent, locking in the 9 pt (12 px) default font size, and _apply_eeglab_style omits QGroupBox from its font-size: 16px and color: {EEGLAB_TEXT} selectors. In OS dark mode the unstyled WindowText palette can render light text over the #a8c2ff dialog background, and the title is smaller than MATLAB's uipanel(..., 'FontSize', 12, ...) (supergui.m L320, equivalent to 16 px in Qt). At 16 px bold, "Edit the independent variables for this design" measures ~350 px wide inside the 485 px panel.
    • Suggested fix: Add QGroupBox to the font-size: 16px and color: {EEGLAB_TEXT} rules in _apply_eeglab_style.

Test gaps

  • tests/test_gui_pop_study.py (L418-L430): test_studydesign_opens_legacy_empty_variable_and_preserves_other_factors starts from an in-memory pop_study dict where design["filepath"] is "" and the empty variable slot already has vartype="categorical" and value=[]. Add a MAT round-trip via scipy.io.savemat + pop_loadstudy(..., load_datasets=False) (with empty filepath, label, value, and vartype slots) covering pop_studydesign_dialog_spec, unedited commit_studydesign_editor (com == ""), and commit_studydesign_editor after renaming a design.

EEGLAB parity notes

  • All 16 supergui geom cells, control order, SuperguiControl("panel") zero-extent sizing, and fit_width=False on variable_summary match pop_studydesign.m (L103-L154) and supergui.m (L318-L321, L359-L385).
  • In pop_studydesign.m (L66-L70, L171), stripping empty variables from usrdat.design causes ~isequal(STUDY.design(index), tmpdes) to rebuild the design on OK even when unedited. Filtering original with _without_empty_variables in commit_studydesign_editor avoids spurious history commands and design rebuilds on unedited OK.

Tests run

Ran in a detached worktree at 4fce3ba1306f7f586e971dd538485e66391e283d:

  • tests/test_gui_pop_study.py: 19 passed
  • tests/test_study_metadata.py and tests/test_study_end_to_end.py: 23 passed
  • tests/test_gui_geometry.py and tests/test_guifunc_primitives.py: 159 passed, 67 skipped (Linux-only MATLAB reference coordinate checks on macOS)
  • ruff check and ruff format --check on all 4 modified Python files: passed
  • Reproduction check using scipy.io.savemat + pop_loadstudy(..., load_datasets=False) on a legacy MAT STUDY with empty filepath and empty variable slots: reproduced the ValueError in both pop_studydesign_dialog_spec (when vartype is empty) and commit_studydesign_editor (both unedited and renamed).

@arnodelorme arnodelorme left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review was written by an AI assistant during a nightly check, not by Arno.

Code review

  • Overall assessment: Looks good. Legacy MATLAB empty fields in pop_studydesign and std_getindvar, supergui geometry, QGroupBox panel styling and sizing, and MAT roundtrip coverage all check out cleanly at c895563a20aad35e70e21d3059863953e396eebe.
  • Highest-risk area: None identified.
  • Merge recommendation: Safe to merge.

Blocking

None.

Important

None.

Nits

None.

Test gaps

None.

EEGLAB parity notes

  • All 16 supergui geom cells, control ordering, SuperguiControl("panel") zero-extent sizing, QGroupBox 16 px font and #000066 text styling, and fit_width=False on variable_summary match pop_studydesign.m (L103 to L154) and supergui.m (L318 to L321, L359 to L385).
  • Normalizing MATLAB empty fields in _without_empty_variables, _options_from_editor_design, variable_summary_lines, _plain_value, and std_getindvar._append_design_values preserves legacy .study MAT designs on unedited OK without spurious std_makedesign history entries.

Tests run

Ran in a detached worktree at c895563a20aad35e70e21d3059863953e396eebe:

  • tests/test_gui_pop_study.py: 20 passed
  • tests/test_study_metadata.py, tests/test_study_end_to_end.py, tests/test_gui_geometry.py, and tests/test_guifunc_primitives.py: 188 passed, 70 skipped (Linux MATLAB reference coordinates on macOS)
  • ruff check, ruff format --check, and ty check on modified Python files: passed

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

@arnodelorme
arnodelorme merged commit cc41590 into develop Dec 1, 2026
11 of 15 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.

1 participant