Skip to content

[Fable 5 Findings] Phase 4b β€” large-file decomposition & behavior-changing consolidationsΒ #205

Closed

Description

@suraj-ranganath

πŸ€– Follow-up to Fable 5 Findings Phase 4 (#197, PR #204). Phase 4 delivered the behavior-preserving duplication/ownership/layering fixes that could be made safely. This issue tracks the remainder, in two groups.

Group A β€” Large-file decompositions (high-risk, low-reward; do as focused standalone PRs)

Each is a 1000+ line module flagged for sprawl. Splitting them is a large diff with real breakage risk, so they were intentionally not bundled into the Phase 4 dedup pass.

  • functions/popfunc/pop_load_frombids.py (~1200L): extract the NEO raw-reader and the montage-inference/coord-assignment engine into a shared reader module; leave the popfunc as BIDS-sidecar orchestration + history.
  • functions/statistics/_core.py (~1036L): split the mega-module behind its 14 re-export shims into focused modules by stable ownership.
  • plugins/ICLabel/pop_prop_extended.py (~1376L): separate history glue, dipfit/classifier numerics, and the matplotlib property browser.
  • functions/guifunc/qt.py: QtDialogRenderer is a ~1200L stateless class-as-namespace (46 staticmethods); convert to module-level functions or split by widget family.

Group B β€” Consolidations deferred from Phase 4 (need a behavior decision or broader file scope)

These were left out of the behavior-preserving Phase 4 pass because consolidating the diverged copies would change observable behavior (figure titles/legends, history strings, the cluster partition + STUDY.cluster.algorithm provenance, error-message strings, or the mask-vs-None return protocol), or because the remaining copies live in files outside the cluster's allowlist. See PR #204's per-cluster notes for the exact reasoning.

  • 2: pop_clust should dispatch to robust_kmeans when outliers finite and record algorit (K1_study) β€” Finding 1 makes the kernel shareable so a future BEHAVIOR phase can implement this cleanly. Left _mark_outliers untouched.
  • 3: pop_chanplot reimplements cached-channel reading/plotting that std_readdata + std_ (K1_study) β€” The duplicated measure-data field map portion is addressed canonically in finding 9 (std_readdata.MEASURE_DATA_FIELDS), but pop_chanplot keeps its own field map
  • 4: cached measure-axis resolution + _axis_position + _unique_preserving_order duplica (K1_study) β€” BLOCKED for the rest: std_preclust.py (_measure_axis, _axis_position, _unique_preserving_order) and std_precomp.py (_unique_preserving_order) are outside my fil
  • 5: identical _trial_rows trialinfo normalizer copy-pasted across std_combtrialinfo, s (K1_study) β€” BLOCKED for the rest: std_getindvar.py, std_selectdataset.py, and std_gettrialsind.py are outside my allowlist. std_gettrialsind also has a leading 'trialinfo'-
  • 6: design-matrix factor-matching logic duplicated between std_limodesign and std_buil (K1_study) β€” Extracting a limodesign-only helper would relocate, not remove, duplication.
  • 8: three near-identical range-mask helpers across std_readdata, std_pac, _std_measure (K1_study) β€” No test asserts these strings, but the mandate requires identical observable behavior.
  • 10: std_clustplot builds its history command with an ad-hoc f-string instead of build (K1_study) β€” Confirmed build_python_call output matches the current f-string exactly for non-empty clusters but diverges for the empty case.
  • Finding RefactorΒ #2 + Fix mutable default argument and incorrect file loading orderΒ #3: _numeric_vector/_colon_sequence duplicated and drifted across timefr (K2_timefreq) β€” newtimef.py and newcrossf.py consolidated. The timefreq.py and tf_cycle_calc.py copies are OUTSIDE my allowlist, so they remain forked; reported in blocked. Equ
  • Finding Resolve conflict between lincuan:patch-1 and sccn:develop in OctaveWrapperΒ #4: three empirical-p-value conventions coexist in _pac_support / bootstat / (K2_timefreq) β€” Numeric consolidation is behavior-changing for the pac_cont statlim='surrogate' user-facing path; left intact and documented instead. Existing PAC test exercise
  • is_on() reimplemented ~9 times with divergent semantics (K3_popdedup) β€” The out-of-scope copies named in the finding (timefreqfunc/newcrossf.py, timefreqfunc/newtimef.py with inverted/str-only semantics; sigprocfunc/headplot.py; and
  • 4: parallel winrej/rejection-family plumbing in _eegplot_rejection vs pop_eegplot (K4_rejica) β€” Left _displayed_families/_has_family_marks (and the color helpers _kind_color/_family_color) as local copies in _eegplot_rejection. Reason: pop_eegplot._has_rej
  • 5: boundary-event detection forked across helpers; route through eeg_findboundaries (K4_rejica) β€” Routing through eeg_findboundaries is a behavior CHANGE, not a behavior-preserving refactor, and is locked by an EXISTING test. test_phase1b_file_edit_pop_funct
  • Pop-result interpretation contract duplicated in console.py and menu_actions.py; GUI (K6_gui) β€” DELIBERATELY did NOT add the STUDY branch to the GUI path that the finding's fix suggested. Adding it would be a behavior CHANGE (GUI extension pop_* returning
  • FIR band-edge / desired-amplitude math duplicated between qt.py _firpm_order_shape an (K6_gui) β€” qt.py left completely unchanged. The dedup cannot be completed without editing plugins/firfilt/_filtering.py. The two copies genuinely differ (Hz vs Nyquist-nor
  • ConsoleEegh re-implements session.add_history and mutates ALLCOM/LASTCOM without noti (K6_gui) β€” Only the string/append path was routed through the canonical mutator. The numeric destructive ops (eegh(0)/eegh(-n)) still mutate ALLCOM in place without notify
  • refactor for packaging and test distributionΒ #1 pipeline apply duplicate transforms _resample/_rereference/_clean/_epoch/_ica l* (K7_cli) β€” BLOCKED by the behavior-preservation gate + allowlist. The two code paths intentionally have DIVERGENT, independently-tested parameter surfaces, so a single can
  • Fix mutable default argument and incorrect file loading orderΒ #3 Stale 'temporary harness until shared CLI dispatcher' docstrings; per-module main( (K7_cli) β€” Docstring/ownership fix done. Did NOT converge the per-module main() output path onto cli/main.py: the two paths INTENTIONALLY emit different error JSON envelop
  • Three divergent copies of the channel-removal + mask-update block in clean_flatlines. (K9_plugins) β€” Existing tests pass for all three copies only because they do not exercise the divergent paths with a non-trivial pre-existing mask AND channels actually remove

Each item should be taken as a deliberate change with its own test update (not a behavior-preserving refactor). Several pair naturally β€” e.g. routing all boundary-event detection through eeg_findboundaries (Group B) is the behavior-correcting version of the _event_utils dedup.

Activity

  1. added
    phase
    on Jun 12, 2026
  2. claude commented on Jun 12, 2026

    @claude
    Contributor

    πŸ€– Plan:

    • Read issue and confirm scope
    • Duplicate-work preflight (no open PRs target this issue)
    • Decide actionability and respond

    Analysis

    Tracker / epic, not a single bug. 4 Group A decompositions (4906 LOC across pop_load_frombids.py 1202L, statistics/_core.py 1036L, pop_prop_extended.py 1376L, guifunc/qt.py 1292L) plus ~15 Group B behavior-changing consolidations. Each item is itself a focused PR with its own test updates. Out of scope for a single agent PR per the >100-line rule.

    No competing open PR targets this issue. PR #204 (fable5/phase4-architecture) is the behavior-preserving predecessor and is still open.

    Relevant code (Group A targets)

    • src/eegprep/functions/popfunc/pop_load_frombids.py (1202L) β€” NEO reader + montage/coord engine + BIDS orchestration
    • src/eegprep/functions/statistics/_core.py (1036L) β€” mega-module behind 14 re-export shims (anova*_cell.py, ttest*_cell.py, statcond.py, fdr.py, etc.)
    • src/eegprep/plugins/ICLabel/pop_prop_extended.py (1376L) β€” history glue + dipfit/classifier numerics + matplotlib browser
    • src/eegprep/functions/guifunc/qt.py (1292L) β€” QtDialogRenderer class-as-namespace with 46 @staticmethod widgets

    Proposed Approach

    Do not bundle. Split into one PR per checkbox, sequenced by risk and unblocking value. Recommended ordering:

    1. statistics/_core.py split first. Lowest GUI/parity risk β€” pure numerics behind stable shim files. Already has the shim layout (anova1_cell.py, ttest_cell.py, statcond.py, …) acting as the public surface. Move each function group into its named module and reduce _core.py to either deleted or a thin compatibility re-export. Mechanical, well-bounded, ~1000L net move.

    2. qt.py: staticmethods β†’ module functions. Each QtDialogRenderer.<verb> is stateless; convert call sites and either keep QtDialogRenderer as a thin shim or remove. Split by widget family (qt_listpick.py, qt_layout.py, qt_firpm.py, etc.). Visual parity is unchanged β€” covered by existing tools/visual_parity cases. Run the visual parity loop on every dialog touched.

    3. pop_load_frombids.py extract. Pull the NEO raw-reader and montage/coord engine into functions/popfunc/_bids_reader.py (or sigprocfunc/ if reused). Leave pop_load_frombids as orchestration + history. Highest data-correctness risk β€” needs the BIDS fixture coverage exercised end-to-end before merge.

    4. pop_prop_extended.py three-way split. History/com glue stays in the pop_ module; numerics into _iclabel_prop_numerics.py; matplotlib browser into _iclabel_prop_browser.py. Requires gui + visual markers and screenshot diff.

    5. Group B behavior changes β€” one PR per finding, with an issue-linked test that fails before the change. Each one (kmeans dispatch + algorithm provenance, eeg_findboundaries routing, is_on() consolidation, _apply_* pipeline unification, channel-removal + mask-update unification in clean_flatlines, …) is a deliberate behavior change with its own acceptance criteria. They cannot be done as one PR because the failure modes are independent and the test deltas are per-finding.

    What I won't do here

    Open a multi-thousand-line PR that touches all four Group A modules at once. The diff would be unreviewable, would conflict with #204, and would mix mechanical moves with behavior-changing dedups from Group B.

    Next step for a human reviewer

    Confirm the sequencing above (especially: start with statistics/_core.py?), and either spin one of these out as its own issue or tell me to start the first PR scoped to a single item. I can take statistics/_core.py as the first focused PR if you want β€” it's the lowest-risk wedge.

  3. suraj-ranganath commented on Jun 12, 2026

    @suraj-ranganath
    MemberAuthor

    πŸ€– Closing as superseded by the replacement architecture closeout epic #207. The large-file decompositions and behavior-changing consolidations from this issue are now grouped into phase issues #208, #209, #210, #211, #212, and #213.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

phase

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions