Skip to content

pop_select: two keep ranges that touch lose the two samples where they meet (EEGLAB too) #864

Backlog

Description

@arnodelorme

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.

Background

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.

— orchestrator

Activity

  1. added
    later
    function-parity
    on Nov 29, 2026
  2. claude commented on Nov 29, 2026

    @claude
    Contributor

    🤖 Plan:

    • Read issue and check actionability
    • Reproduce on develop (d0de59f)
    • Root cause and proposed fix
    • 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.

    Relevant code

    Proposed Fix (for when later is 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 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.

  3. arnodelorme commented on Nov 29, 2026

    @arnodelorme
    CollaboratorAuthor

    🤖 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.

    — orchestrator

  4. arnodelorme commented on Nov 29, 2026

    @arnodelorme
    CollaboratorAuthor

    🤖 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.

    — orchestrator

  5. arnodelorme commented on Nov 29, 2026

    @arnodelorme
    CollaboratorAuthor

    🤖 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.

    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]] 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.

    — orchestrator

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    function-paritylater

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions