Repository navigation
pop_studydesign: Open legacy designs and place their independent variables in the reference panel - #1027
Conversation
There was a problem hiding this comment.
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 finished @arnodelorme's task in 1m 31s —— View job Code review
BlockingNone. Important
NitsNone. Test gaps
EEGLAB parity notesNone. These look fine:
The vendored EEGLAB tree is missing from this checkout, so I couldn't compare line by line against Also checked: |
| """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"))] |
There was a problem hiding this comment.
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) (
eegprep/src/eegprep/functions/studyfunc/pop_studydesign.py
Lines 679 to 682 in c4fff0c
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.
# Conflicts: # docs/source/api/study_workflows.rst
arnodelorme
left a comment
There was a problem hiding this comment.
This review was written by an AI assistant during a nightly check, not by Arno.
Code review
- Overall assessment: Needs changes. The
superguigeometry, panel sizing, and Python-dict empty-label guard matchpop_studydesign.m, while legacy.studyMAT files loaded viapop_loadstudystill hit NumPy 2.x empty-arrayValueErrorcrashes on open or OK. - Highest-risk area: Legacy MATLAB empty-array handling in
std_getindvar.pyandpop_studydesign.py - Merge recommendation: Needs changes
Blocking
None.
Important
-
std_getindvar.py,_append_design_values(L106-L119): Emptyvartypeorvaluearrays still crash before or after the new_empty_value(label)check.- Why it matters: When an unassigned MATLAB struct slot or a legacy
.studyMAT file loaded bypop_loadstudyhasvartypeorvaluestored as''or[],convert_matlabturns those fields into size-0 NumPy arrays (np.empty((0, 0))). Line 107 evaluatesvariable.get("vartype") or "categorical"before line 109 checks_empty_value(variable.get("label")), and lines 106 and 116 useor []ondesign.get("variable")andvariable.get("value"). Under NumPy 2.x,bool(np.empty((0, 0)))raisesValueError: The truth value of an empty array is ambiguous, sopop_studydesign_dialog_specstill fails to open such designs. - Suggested fix: Check
_empty_value(variable.get("label"))first, derivevartypeas"categorical" if _empty_value(variable.get("vartype")) else str(variable["vartype"])(matchingpop_studydesign.mL176-L178 andstd_checkset.mL378-L383), and guarddesign.get("variable")andvariable.get("value")with_empty_value(...)rather thanor [].
- Why it matters: When an unassigned MATLAB struct slot or a legacy
-
pop_studydesign.py,_without_empty_variablesandcommit_studydesign_editor(L286, L526-L536, L628-L631): Pressing OK on a MAT-loaded legacy STUDY raisesValueErroron remaining size-0 NumPy fields.- Why it matters:
pop_loadstudyconverts empty MATLAB strings and arrays insideSTUDY["design"](such asdesign["filepath"] = ''or a continuous variable'svalue = []) tonp.empty((0, 0))._without_empty_variablesremoves empty-label variables while leaving those other size-0 arrays intact on bothoriginalandstate["designs"]. Pressing OK without edits calls_same_design(L684-L699), where_plain_valueleaves size-0np.ndarrayvalues unconverted (value.item()fails for size != 1) and dict equality raisesValueError: The truth value of an empty array is ambiguous. Editing the design and pressing OK hits the sameValueErrorin_options_from_editor_design(if design.get("filepath"):at L682), and opening a MAT-loaded design with a continuous variable hits it invariable_summary_lines(variable.get("value") or []at L260). - Suggested fix: Normalize MATLAB-empty fields inside
_without_empty_variables(replaceis_matlab_emptyfilepathwith"",includewith[], and kept variablevalue/vartypewith[]/"categorical"), and convertnp.ndarrayvalues via.tolist()in_plain_valueso any extra empty MATLAB fields (such aslimo) compare cleanly.
- Why it matters:
Nits
qt.py,_build_widgetand_apply_eeglab_style(L422-L423, L918-L923):QGroupBoxpanel titles miss the 16 px font size and#000066text color.- Why it matters:
_apply_font_hintscallswidget.setFont(font)while theQGroupBoxhas no parent, locking in the 9 pt (12 px) default font size, and_apply_eeglab_styleomitsQGroupBoxfrom itsfont-size: 16pxandcolor: {EEGLAB_TEXT}selectors. In OS dark mode the unstyledWindowTextpalette can render light text over the#a8c2ffdialog background, and the title is smaller than MATLAB'suipanel(..., 'FontSize', 12, ...)(supergui.mL320, 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
QGroupBoxto thefont-size: 16pxandcolor: {EEGLAB_TEXT}rules in_apply_eeglab_style.
- Why it matters:
Test gaps
tests/test_gui_pop_study.py(L418-L430):test_studydesign_opens_legacy_empty_variable_and_preserves_other_factorsstarts from an in-memorypop_studydict wheredesign["filepath"]is""and the empty variable slot already hasvartype="categorical"andvalue=[]. Add a MAT round-trip viascipy.io.savemat+pop_loadstudy(..., load_datasets=False)(with emptyfilepath,label,value, andvartypeslots) coveringpop_studydesign_dialog_spec, uneditedcommit_studydesign_editor(com == ""), andcommit_studydesign_editorafter renaming a design.
EEGLAB parity notes
- All 16
superguigeomcells, control order,SuperguiControl("panel")zero-extent sizing, andfit_width=Falseonvariable_summarymatchpop_studydesign.m(L103-L154) andsupergui.m(L318-L321, L359-L385). - In
pop_studydesign.m(L66-L70, L171), stripping empty variables fromusrdat.designcauses~isequal(STUDY.design(index), tmpdes)to rebuild the design on OK even when unedited. Filteringoriginalwith_without_empty_variablesincommit_studydesign_editoravoids 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 passedtests/test_study_metadata.pyandtests/test_study_end_to_end.py: 23 passedtests/test_gui_geometry.pyandtests/test_guifunc_primitives.py: 159 passed, 67 skipped (Linux-only MATLAB reference coordinate checks on macOS)ruff checkandruff format --checkon all 4 modified Python files: passed- Reproduction check using
scipy.io.savemat+pop_loadstudy(..., load_datasets=False)on a legacy MAT STUDY with emptyfilepathand empty variable slots: reproduced theValueErrorin bothpop_studydesign_dialog_spec(whenvartypeis empty) andcommit_studydesign_editor(both unedited and renamed).
arnodelorme
left a comment
There was a problem hiding this comment.
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_studydesignandstd_getindvar,superguigeometry,QGroupBoxpanel styling and sizing, and MAT roundtrip coverage all check out cleanly atc895563a20aad35e70e21d3059863953e396eebe. - Highest-risk area: None identified.
- Merge recommendation: Safe to merge.
Blocking
None.
Important
None.
Nits
None.
Test gaps
None.
EEGLAB parity notes
- All 16
superguigeomcells, control ordering,SuperguiControl("panel")zero-extent sizing,QGroupBox16 px font and#000066text styling, andfit_width=Falseonvariable_summarymatchpop_studydesign.m(L103 to L154) andsupergui.m(L318 to L321, L359 to L385). - Normalizing MATLAB empty fields in
_without_empty_variables,_options_from_editor_design,variable_summary_lines,_plain_value, andstd_getindvar._append_design_valuespreserves legacy.studyMAT designs on unedited OK without spuriousstd_makedesignhistory entries.
Tests run
Ran in a detached worktree at c895563a20aad35e70e21d3059863953e396eebe:
tests/test_gui_pop_study.py: 20 passedtests/test_study_metadata.py,tests/test_study_end_to_end.py,tests/test_gui_geometry.py, andtests/test_guifunc_primitives.py: 188 passed, 70 skipped (Linux MATLAB reference coordinates on macOS)ruff check,ruff format --check, andty checkon modified Python files: passed
Checked for correctness bugs, EEGLAB parity, data structure compatibility, changed-behavior tests, and CLAUDE.md/AGENTS.md compliance.
🤖 Part of #968 and #875. Open legacy designs and place their independent variables in the reference panel. Stacked on #974.
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.