Repository navigation
[arch] Kill duplication, fix ownership & layering (Fable 5 Phase 4) - #204
Conversation
Part of the Fable 5 Findings epic (#193); addresses issue #198. Standalone/runtime hygiene: - Move developer/parity tooling out of the installed wheel into tools/: visual_capture.py -> tools/visual_parity/, stage_comparison.py -> tools/eeg_bids/, iclabel_net_load_py_measures.py -> tools/iclabel/ (refactored to import the canonical ICLabelNet, removing the float64/float32 model drift). pop_reref_helper.py -> scripts/. - Make eeglabcompat import side-effect-free (lazy temp dir), so importing core modules no longer creates a temp directory at import time. - Resolve the packaged montages dir via importlib.resources instead of a __file__ dirname chain in pop_load_frombids. Dependencies & docs: - Drop the redundant eeglabio optional extra that duplicated the mandatory dependency. eeglabio stays required (used transitively via mne.export for .set writing); installation docs updated to match. - Remove conda-forge install instructions for this unpublished pre-release; make the EEGobj example in contributing.rst actually runnable. - Fix the README docs badge and correct CI branch triggers (main -> develop). Dead code: - Remove _currentset_list (menu_actions), _reject_unsupported_options (pop_newcrossf), the unused withindex parameter (pop_chansel), the custom_randperm no-op wrapper (runica; hoist `import time`), an unraisable except in eegrej, and the unread top-level STUDY['preclust'] seed (_study_utils).
Part of the Fable 5 Findings epic (#193); addresses issue #194. - Remove assertion-swallowing try/except->skipTest wrappers across test_clean_artifacts, test_clean_drifts, test_eeg_picard, test_ICL_feature_extractor, and test_eeg_mne2eeg so assertions run instead of converting failures into skips. Genuine optional-dependency skips are kept as explicit @skipUnless guards. - Deduplicate the per-module create_test_eeg fixtures onto the shared tests/fixtures.py fixture. - Tighten the eeg_autocorr_fftw vs eeg_autocorr cross-check from rtol/atol=0.1 to 1e-4/1e-7 (documented: the only divergence is the single-precision FFT cast in eeg_autocorr). - Add a real (unmocked) calc_projector test that runs the actual sphericalSplineInterpolate and validates channel mapping/assembly. - Replace the ASR numpy-error-injection log-string tests with real degenerate-input tests asserting finite, sane cleaned output. - Assert real clustering behavior (shared labels within tight pairs, far point isolated) in the study clustering helper test. test_eeg_picard_different_random_states now xfails honestly: eeg_picard converges identically regardless of random_state (tracked under the epic for Phase 2/3); marked xfail rather than re-hidden.
…iants Part of the Fable 5 Findings epic (#193); addresses issue #195. Make side-effect-free functions actually side-effect-free by copying at entry, and fix the ICA sign-normalization invariant break. - Deep-copy EEG at entry in eeg_runica, eeg_amica, load_amica_model, eeg_picard, pop_select, pop_headplot, pop_clean_rawdata, clean_windows and clean_asr; copy the data array at entry in runica and clean_asr; build pop_saveset's MATLAB structures from copies so the caller keeps 0-based urchan/urevent; deep-copy the clean_artifacts high-pass snapshot. - eeg_rpsd no longer reseeds the global NumPy RNG (uses a local RandomState). - coords_to_mm / coords_RAS_to_ALS no longer mutate the caller's array. - eeg_from_data no longer silently transposes a tall 2-D array on a shape>shape guess; it raises and asks for nbchan when orientation is ambiguous. - posact sign-flips now negate the matching icaweights row and icawinv column directly instead of recomputing icaweights via pinv(icawinv), which had folded the non-identity sphere into the weights; icasphere is left untouched, preserving icawinv == pinv(icaweights @ icasphere) and icaact == icaweights @ icasphere @ data. eeg_amica and eeg_picard now flatten epoched data in Fortran order to match eeg_runica and EEGLAB. - Adds regression tests asserting inputs are unchanged and the ICA invariants hold.
Part of the Fable 5 Findings epic (#193); addresses issue #196. Replace silent fallbacks with real dispatch, make ignored options take effect or fail loudly, and fix index/boundary errors — each with a test that reproduces the bug first. - Loading: pop_loadset dispatches HDF5 vs scipy by the actual file instead of swallowing every error into an HDF5 retry; pop_fileio dispatches .mat by content instead of silently importing a broken .set as a raw array; pop_loadset_h5 drops the hard-coded emoji fixture and decodes by one rule. - Indexing/events: pop_select chantype selection no longer crashes (eeg_decodechan return unpacked) and the console zero-bases pop_select numeric channels so 1-based history replays correctly; eeg_eegrej no longer drops first/last events by latency; pop_editeventvals epoched latency display/edit is symmetric (ms<->points) and no longer raises. - sigproc: epoch() boundary check fixed (no negative-index slice); eegrej() shifts boundary latencies by base region spans; runamica() cleans its temp dir on failure without swallowing the error. - Session: console CURRENTSET reassignment guarded by a regression test; IMPLEMENTED_ACTIONS now has a test enforcing it matches dispatch routing; GUI dataset commit applies history only after the abort check; the headplot menu action commits its spline edit through the session. - CLI: pipeline gains the negative-edge filter guard the subcommand has; --quiet/--verbose/--no-progress are wired; the self-describing schema covers all required params and stops marking --output required under --overwrite; bids dispatches by format and propagates exit codes. - ASR/clean: clean_flatlines walrus precedence fixed; asr_calibrate raises on unsupported sample rates; clean_artifacts/clean_asr/asr_process no longer swallow failures and re-insert ignored channels per EEGLAB. - Other: newtimef _is_on uses correct whitelist semantics and its dead params fail loudly; compute_pac passes through title/vert/newfig; std_precomp recompute and std_makedesign delfiles take effect; EEGobj raises on unknown attributes; gen_derived_fpath honors ${root}; ICLabel validates icawinv before dereferencing it.
The mutation regression test snapshotted icaweights via list(), which breaks when the shared tests/fixtures.py fixture (Phase 1) provides a pre-ICA dataset with icaweights=None. Assert the caller's ICA fields are the exact same objects after the call instead, which is what 'does not mutate' means and works for both a None and an array-valued icaweights.
|
🤖 Specification (PR >500 LOC; full per-finding detail in #197, epic #193) Stacking. This PR is based on Problem. 45 duplication/ownership/layering findings — the loudest maintainability theme in the review. The highest-value, well-isolated ones are fixed here. Approach (behavior-preserving — existing tests pass unchanged). One canonical helper imported downward; parallel branches collapsed; logic moved to the owning module. Key moves: k-means kernel → Honest scope (this is dedup work, so "duplicates" that have diverged cannot be merged without a behavior decision). ~23 findings fully done, ~8 partial (canonical helper added + some call sites converted; remaining call sites live in out-of-allowlist files), ~10 deferred because consolidation would change observable behavior (figure titles/legends, history strings, the cluster partition + Deferred to Phase 4b (high-risk, low-reward; better as focused standalone work): the four large-file decompositions — Tests. All affected suites green (640+ passed, MATLAB-gated skips only, 1 pre-existing xfail); ruff/pre-commit clean. Three independent reviewers confirmed zero allowlist violations and no behavior changes beyond the intended canonical convergences (each test-locked). |
|
Claude finished @suraj-ranganath's task in 7m 47s —— View job Code review — PR #204 (Fable 5 Phase 4)
I read the full diff against BlockingNone. ImportantFDR canonical helper no longer strips non-finite p-values — The removed values = values[np.isfinite(values)] # removed helper
accepted = values <= alpha * ranks / values.sizeThe canonical flat = np.sort(values.reshape(-1)); count = flat.size # _core.py:140-144
accepted = flat <= indices / count * q_value / correctionTwo consequences when
Why it matters: this is the FDR multiple-comparison correction for ERSP/ITC significance, and the removed helper's NaN-stripping matched EEGLAB's Concrete fix: strip non-finite in Nits
Test gapsCoverage is adequate and the new tests are meaningful (not tautological) —
EEGLAB parity notes
|
clean_asr now returns a fresh dataset; reword the three comments that still described it mutating EEG in place (AGENTS.md: delete stale comments in touched code).
# Conflicts: # tests/test_utils_asr.py
…ing) Part of the Fable 5 Findings epic (#193); addresses issue #197. Built on the integration of Phases 1/2/3/5 so the deduped code keeps those fixes. Behavior-preserving consolidations (existing tests pass unchanged): - studyfunc: extract the k-means kernel into _cluster_kmeans.py so pop_clust, optimal_kmeans and robust_kmeans import it downward (layering inversion fixed); share unique_preserving_order, trialinfo_rows, default_measure_target and the MEASURE_DATA_FIELDS map. - timefreq: newtimef/newcrossf use the canonical statistics.fdr and the shared bootstrap/threshold helpers instead of forked copies; _is_on imports the canonical whitelist predicate. - popfunc: remove the duplicated _is_on copies (import _pop_utils.is_on), pop_topoplot reuses the shared python_literal, pop_topochansel delegates to pop_chansel, pop_comperp collapses the repeated lowpass calls, pop_saveset serializes chanlocs through the single _chanlocs_to_struct_array, and the near-identical pop_rejkurt/pop_jointprob share their rejection plumbing. - gui/cli/extensions: menu_actions collapses the per-name dispatch branches; the pop-result interpretation contract is shared; the dead run_main() is removed; extension_catalog splits its manager and curation halves (extension_catalog_validation.py) and reuses the canonical entry-point helpers; plugin_menu derives bundled metadata from the registry. - plugins: firws/firwsord move to the firfilt plugin (correct ownership) with clean_rawdata importing them. Findings that would change observable behavior (figure titles, history strings, cluster partition/provenance, error strings) or need files outside this scope are intentionally left for a follow-up, as are the four large-file decompositions (pop_load_frombids, statistics/_core, pop_prop_extended, QtDialogRenderer) — those are tracked as Phase 4b.
bfb4638 to
df33f83
Compare
Behavior-preserving consolidations across studyfunc, timefreq, popfunc, GUI/CLI/extensions and the clean_rawdata/firfilt plugins: extract the k-means kernel so numerics import downward, route newtimef/newcrossf through canonical FDR and bootstrap helpers, remove duplicated is_on copies, serialize chanlocs through the one canonical helper, share the rejkurt/jointprob plumbing, split extension_catalog's manager and curation halves, and move firws/firwsord to the firfilt plugin. Existing tests pass unchanged. Findings that would change observable behavior, or need out-of-scope files, and the four large-file decompositions are deferred to Phase 4b.
Base is fable5/integration (Phases 1/2/3/5 stacked); merge after #200/#201/#202/#203 and rebase onto fix/fresh-uv-console once they land.
Part of #197