Skip to content

[FIX] ASR: init clean_windows rejection masks before one-sided zthresholds - #113

Merged
nbara merged 1 commit into
nbara:masterfrom
sappelhoff:fix/asr-clean-windows-mask-init
Jul 18, 2026
Merged

nbara merged 1 commit into
nbara:masterfrom
sappelhoff:fix/asr-clean-windows-mask-init

Conversation

@sappelhoff

Copy link
Copy Markdown
Collaborator

In clean_windows, mask1 and mask2 were only assigned inside their respective if np.max(zthresholds) > 0 / if np.min(zthresholds) < 0 branches, but combined unconditionally via np.logical_or.reduce((mask1, mask2, mask3)). Since zthresholds is a documented, user-facing parameter, passing a one-sided value (e.g. [1, 2] or [-5, -1]) skips one branch and raises UnboundLocalError. The default [-3.5, 5] straddles 0 so both branches run, keeping the bug latent.

Initialize both masks to all-False before the conditionals, so a criterion that isn't evaluated simply rejects no windows.

Testing

Added a regression test exercising clean_windows with both one-sided directions of zthresholds. Full tests/test_asr.py passes; ruff clean.

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.11%. Comparing base (6b107c9) to head (c2b9ca1).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #113      +/-   ##
==========================================
+ Coverage   83.10%   83.11%   +0.01%     
==========================================
  Files          25       25              
  Lines        2823     2825       +2     
==========================================
+ Hits         2346     2348       +2     
  Misses        477      477              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sappelhoff

Copy link
Copy Markdown
Collaborator Author

Note: includes the nonlinear_eigenspace reproducibility fix from #118. test_asr_class[*-riemann] compares incremental-vs-bulk output with a loose tolerance and is flaky on CI because that path used an unseeded RNG; this can trip on any PR regardless of what it changes. #118 is the root fix — once it merges first, this commit drops out on rebase.

@sappelhoff sappelhoff mentioned this pull request Jul 14, 2026
@nbara
nbara force-pushed the fix/asr-clean-windows-mask-init branch from 922fbe1 to a37a8c5 Compare July 16, 2026 07:15
…holds

mask1 and mask2 in clean_windows were only assigned inside their
respective `if np.max(zthresholds) > 0` / `if np.min(zthresholds) < 0`
branches, but combined unconditionally via
`np.logical_or.reduce((mask1, mask2, mask3))`. Since zthresholds is a
documented, user-facing parameter, passing a one-sided value (e.g.
[1, 2] or [-5, -1]) skips one branch and raises UnboundLocalError. The
default [-3.5, 5] straddles 0 so both branches run, keeping the bug
latent.

Fix: initialize both masks to all-False (matching the EEGLAB/BCILAB
reference behavior of flagging no windows by default) before the
conditionals, so each criterion that isn't evaluated simply rejects no
windows instead of being undefined.

Added a regression test exercising clean_windows with both one-sided
directions of zthresholds on the eeg_raw.npy fixture.
@nbara
nbara force-pushed the fix/asr-clean-windows-mask-init branch from a37a8c5 to c2b9ca1 Compare July 18, 2026 16:10
@nbara
nbara merged commit a4487f2 into nbara:master Jul 18, 2026
7 checks passed
@sappelhoff
sappelhoff deleted the fix/asr-clean-windows-mask-init branch July 19, 2026 09:06
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.

2 participants