You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pop_select: two keep ranges that touch lose the two samples where they meet (EEGLAB too) #864
When two keep ranges touch, pop_select removes the two samples where they meet, in EEGLAB and, since pull request #856, in EEGPrep too. Arno decided on November 29, 2026 to keep EEGPrep equal to EEGLAB for now and to fix both later.
Where it stands:pop_select(EEG, 'point', [1 3; 4 8]) on 8 samples keeps 6 samples in EEGLAB (MATLAB R2025b) and in EEGPrep, although all 8 were asked for.
Decision (Arno, November 29, 2026): "For this keep EEGLAB range, but keep the issue open and we will fix it in both EEGPrep and EEGLAB later." (his comment on pull request #856)
Next step: one fix in pop_select.m of sccn/eeglab and the same fix in pop_select.py, together, so that parity is kept at every step. Nobody works on it yet (label later).
According to the two reviews of pull request #856, the cause is the shift of one sample that pop_select applies to the inner edges of the rejection regions before it calls eeg_eegrej (pop_select.m lines 587 to 596): between two adjacent keep ranges the region is not empty after that shift. This was read in the reviews and not checked again when this issue was opened. The comparison of 9,243 point ranges between MATLAB and Python, and the review by Codex that raised this case, are in the review comment of pull request #856.
A separate defect, the last sample kept by eeg_lat2point.m at 250, 500 and 1000 Hz, is fixed in EEGLAB itself in its own pull request on sccn/eeglab, and is not part of this issue.
Open PR — not opened: the issue carries later and Arno's decision is to keep EEGLAB's behavior until pop_select.m and pop_select.py are fixed together. [pop_select] Keep one-sample edge rejections for point ranges #856 (still open) touches the same lines, so a parallel PR would also conflict.
Research
Reproduced: pop_select(EEG, point=[[1, 3], [4, 8]]) on 8 samples at 100 Hz returns 6 samples, data[0] == [0, 1, 4, 5, 6, 7], so samples 3 and 4 are gone. The complement between the two keep ranges is [t(3), t(4)]. Shifting its inner edges by one sample turns it into [t(4), t(3)], an inverted region. eeg_lat2point maps that to [4 3]. The != 0 filter keeps the row, and eeg_eegrej removes samples 3 and 4.
Drop complement regions that become empty after the edge shift, and do it the same way in both repos. In Python, after the shift, skip rows where notime[i, 1] < notime[i, 0]. The alternative is to filter pts[:, 1] < pts[:, 0] instead of != 0, but a check on the time range does not depend on rounding. Make the matching change in pop_select.m around L587-596 in sccn/eeglab in the same release window. Add a regression test to tests/test_pop_select.py that requires point=[[1, 3], [4, 8]] to keep all 8 samples. It should also check that point=[[1, 3], [5, 8]] removes only sample 4, and that interaction overlaps with #856's one-sample-edge handling. Because this changes numerical output compared with EEGLAB, it needs a MATLAB reference run and Arno's approval.
🤖 Pull request #856, [pop_select] Keep one-sample edge rejections for point ranges, keeps EEGPrep equal to EEGLAB for two keep ranges that touch, as Arno decided, and holds that result in two tests of tests/test_pop_select.py. The fix of this issue will have to change both on purpose:
test_adjacent_keep_ranges_match_eeglab, added for this issue and naming it: 'point', [1 3; 4 8] on 0:9 keeps 0, 1, 4, 5, 6, 7 (MATLAB R2025b, at 100 Hz and at 2048 Hz).
The case point=[[2, 3], [4, 9]] of test_one_sample_regions_match_eeglab, which keeps 1, 4, 5, 6, 7, 8.
🤖 Pull request [pop_select] Keep one-sample edge rejections for point ranges is merged into develop. It keeps EEGLAB's result for two keep ranges that touch, as Arno decided, and its test test_adjacent_keep_ranges_match_eeglab names this issue. This issue stays open for the later fix in EEGPrep and in EEGLAB.
🤖 A note on this issue from the work on the last sample that pop_select keeps at 300, 1024, 2048 and 30000 Hz, which Arno asked to fix now in both programs.
What this does for the adjacent ranges of this issue: nothing, on purpose.point=[[1, 3], [4, 8]] on 0:9 still returns 0, 1, 4, 5, 6, 7 in EEGLAB and in EEGPrep, and the test test_adjacent_keep_ranges_match_eeglab is unchanged and passes. None of the 135 calls with two keep ranges or one sample regions changes in either program. The cause of this issue is another one: the gap between two keep ranges that touch becomes a region whose start is after its end ([4 3]), and eeg_eegrej removes both samples.
What it makes easier. The regions are now exact whole numbers in both programs, so a later fix for this issue can test "start after end" on points without a tolerance.
Two relatives seen in the same runs, left as they are. With keep ranges that overlap or are not in increasing order, the two programs differ today and after the two pull requests (15 of the 135 calls): point=[[4, 8], [1, 3]] returns 0, 1, 4, 5, 6, 7 in EEGPrep, which sorts the ranges, and an empty dataset in EEGLAB. point=[[2, 4], [4, 9]] returns 1, 2, 3, 4, 5, 6, 7, 8 in EEGPrep, which merges them, and 1, 5, 6, 7, 8 in EEGLAB. They belong with this issue when it is fixed in both programs together.
Activity
claude commentedon Nov 29, 2026
🤖 Plan:
develop(d0de59f)Open PR— not opened: the issue carrieslaterand Arno's decision is to keep EEGLAB's behavior untilpop_select.mandpop_select.pyare fixed together. [pop_select] Keep one-sample edge rejections for point ranges #856 (still open) touches the same lines, so a parallel PR would also conflict.Research
Reproduced:
pop_select(EEG, point=[[1, 3], [4, 8]])on 8 samples at 100 Hz returns 6 samples,data[0] == [0, 1, 4, 5, 6, 7], so samples 3 and 4 are gone. The complement between the two keep ranges is[t(3), t(4)]. Shifting its inner edges by one sample turns it into[t(4), t(3)], an inverted region.eeg_lat2pointmaps that to[4 3]. The!= 0filter keeps the row, andeeg_eegrejremoves samples 3 and 4.Relevant code
src/eegprep/functions/popfunc/pop_select.py#L478-L498- complement build and ±1-sample edge shift (pop_select.mL587-596)src/eegprep/functions/popfunc/pop_select.py#L503-L508-(end - start) != 0keeps inverted rowssrc/eegprep/functions/popfunc/eeg_eegrej.py#L84-L94- accepts the inverted regionProposed Fix (for when
lateris removed)Drop complement regions that become empty after the edge shift, and do it the same way in both repos. In Python, after the shift, skip rows where
notime[i, 1] < notime[i, 0]. The alternative is to filterpts[:, 1] < pts[:, 0]instead of!= 0, but a check on the time range does not depend on rounding. Make the matching change inpop_select.maround L587-596 in sccn/eeglab in the same release window. Add a regression test totests/test_pop_select.pythat requirespoint=[[1, 3], [4, 8]]to keep all 8 samples. It should also check thatpoint=[[1, 3], [5, 8]]removes only sample 4, and that interaction overlaps with #856's one-sample-edge handling. Because this changes numerical output compared with EEGLAB, it needs a MATLAB reference run and Arno's approval.arnodelorme commentedon Nov 29, 2026
🤖 Pull request #856, [pop_select] Keep one-sample edge rejections for point ranges, keeps EEGPrep equal to EEGLAB for two keep ranges that touch, as Arno decided, and holds that result in two tests of
tests/test_pop_select.py. The fix of this issue will have to change both on purpose:test_adjacent_keep_ranges_match_eeglab, added for this issue and naming it:'point', [1 3; 4 8]on 0:9 keeps 0, 1, 4, 5, 6, 7 (MATLAB R2025b, at 100 Hz and at 2048 Hz).point=[[2, 3], [4, 9]]oftest_one_sample_regions_match_eeglab, which keeps 1, 4, 5, 6, 7, 8.— orchestrator
[pop_select] Keep one-sample edge rejections
arnodelorme commentedon Nov 29, 2026
🤖 Pull request [pop_select] Keep one-sample edge rejections for point ranges is merged into develop. It keeps EEGLAB's result for two keep ranges that touch, as Arno decided, and its test
test_adjacent_keep_ranges_match_eeglabnames this issue. This issue stays open for the later fix in EEGPrep and in EEGLAB.— orchestrator
arnodelorme commentedon Nov 29, 2026
🤖 A note on this issue from the work on the last sample that
pop_selectkeeps at 300, 1024, 2048 and 30000 Hz, which Arno asked to fix now in both programs.The two pull requests. EEGLAB: pop_select: keep continuous point ranges in points so the last sample is not kept. EEGPrep: [pop_select] Keep continuous point ranges in points. Both build the regions to reject in points when the range was given in points on continuous data, so that a single range that ends one sample before the end no longer keeps the last sample (156 of 9,243 ranges before, 0 after, in both programs).
What this does for the adjacent ranges of this issue: nothing, on purpose.
point=[[1, 3], [4, 8]]on0:9still returns0, 1, 4, 5, 6, 7in EEGLAB and in EEGPrep, and the testtest_adjacent_keep_ranges_match_eeglabis unchanged and passes. None of the 135 calls with two keep ranges or one sample regions changes in either program. The cause of this issue is another one: the gap between two keep ranges that touch becomes a region whose start is after its end ([4 3]), andeeg_eegrejremoves both samples.What it makes easier. The regions are now exact whole numbers in both programs, so a later fix for this issue can test "start after end" on points without a tolerance.
Two relatives seen in the same runs, left as they are. With keep ranges that overlap or are not in increasing order, the two programs differ today and after the two pull requests (15 of the 135 calls):
point=[[4, 8], [1, 3]]returns0, 1, 4, 5, 6, 7in EEGPrep, which sorts the ranges, and an empty dataset in EEGLAB.point=[[2, 4], [4, 9]]returns1, 2, 3, 4, 5, 6, 7, 8in EEGPrep, which merges them, and1, 5, 6, 7, 8in EEGLAB. They belong with this issue when it is fixed in both programs together.— orchestrator