Skip to content

[pop_select] Keep continuous point ranges in points - #881

Open
arnodelorme wants to merge 3 commits into
developfrom
agent/issue-880
Open

arnodelorme wants to merge 3 commits into
developfrom
agent/issue-880

Conversation

@arnodelorme

@arnodelorme arnodelorme commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #880. Part of #729.

Arno's approval (email of November 29, 2026, subject "Re: EEGLAB: pull request for eeg_lat2point, compared with EEGPrep"): "Yes, fix it now in two pull requests. 2b"

Merge only after the EEGLAB pull request sccn/eeglab#1008 is merged: before that, this pull request moves EEGPrep away from EEGLAB develop in 156 of 9,243 ranges.

On continuous data, pop_select.py converted point, nopoint and rmpoint to seconds with eeg_point2lat, which rounds to 1e-9 s, and back to points with eeg_lat2point, as pop_select.m did. At 300, 1024, 2048 and 30000 Hz a limit came back 1e-7 sample after the end of the data, and the last sample was kept although it was not requested. This pull request makes the same change as sccn/eeglab pull request 1008: a range given in points stays in points on continuous data, and the regions to reject are built in points (58 added lines and 1 changed line in pop_select.py).

Example (10 samples holding 0 to 9, compared with EEGLAB in MATLAB R2025b)

Call EEGPrep develop (e435f436) this pull request (18306161) EEGLAB branch agent/issue-1007 (b887b4c35)
pop_select(EEG, point=[3, 9]) at 300 Hz 8 samples (2..9), last sample kept 7 samples (2..8), as requested 7 samples (2..8)
pop_select(EEG, nopoint=[10, 10]) at 1024 Hz ValueError ("does not overlap") 9 samples (0..8), sample 10 removed 9 samples (0..8)
pop_select(EEG, point=[3, 10]) at 300 Hz 8 samples (2..9) 8 samples (2..9) 8 samples (2..9)

EEGLAB reference run made on my EEGLAB branch agent/issue-1007 (commit b887b4c35, MATLAB R2025b), not on EEGLAB develop

Every point range [a, b] with a < b on 10 and on 37 samples at 100, 128, 250, 256, 300, 500, 512, 600, 1000, 1024, 2048, 4900 and 30000 Hz (9,243 ranges), then the other sets.

Samples kept by EEGLAB minus samples kept by EEGPrep, 9,243 ranges EEGLAB develop and EEGPrep develop EEGLAB develop and this pull request EEGLAB b887b4c35 and this pull request
0 9,243 9,087 9,243
+1 0 156 0
Samples kept minus samples requested, EEGPrep, 9,243 ranges develop (e435f436) this pull request
0 9,087 9,243
+1 156 0
Set Calls that differ between EEGLAB and EEGPrep, before after (both pull requests) Changed in EEGPrep
9,243 short point ranges 0 0 156 (43 at 300 Hz, 35 at 1024 Hz, 35 at 2048 Hz, 43 at 30000 Hz, all ending one sample before the end)
280 point ranges on 30,504 to 122,882 samples 9 0, with and without the tolerance of #867 (commit 5edd0e1a, applied in memory) 30 wrong before, 0 after
182 ranges in seconds (time, notime, rmtime) 0 0 0
224 nopoint and rmpoint regions that touch the start or the end 6 0 6 (the ValueError at 1024 Hz on 10 samples)
140 calls compared in depth (values, xmax, boundary events, latencies, com) 1 0 (largest relative difference of xmax 2.0e-16)
135 calls with two keep ranges or one sample regions 15 15 0
25 calls on epoched data 12 12 0

The last two lines are old differences that neither pull request touches. The 15 are keep ranges that overlap or are not in increasing order: EEGPrep sorts and merges them, EEGLAB does not (point=[[4, 8], [1, 3]] returns 0, 1, 4, 5, 6, 7 here and an empty dataset in EEGLAB). The 12 are point ranges on epoched data, where EEGPrep keeps one more sample than EEGLAB (point=[2, 9] keeps 8 samples here and 7 in EEGLAB), and rmpoint=[9, 10], which EEGLAB refuses on epochs at 1024 and 2048 Hz. They are reported to Arno for a separate decision.

The workflow "EEGLAB reference" runs on this branch at commit 18306161: https://github.com/sccn/eegprep/actions/runs/46294127395 . It compares with the EEGLAB of the submodule, which does not have the EEGLAB fix yet.

The change, and what it does not touch

The conversion of the points to times stays where it was, and epoched data still uses it. Right after it, on continuous data, the point ranges are checked and clipped in points (_reject_disjoint_point, _clip_time_matrix with 1 and pnts) and the time matrices are emptied. A new elif branch of the removal then builds the regions to reject in points, with the lines of the time code below it, sample 1, sample pnts and a step of one sample. This follows the new branch of pop_select.m. The Python file keeps its own two habits there, which are older than this pull request: a range completely out of the data raises ValueError where EEGLAB clips it, and keep ranges are sorted and merged.

eeg_lat2point.py and eeg_point2lat.py are not touched (#867 changes eeg_lat2point.py on agent/issue-867). Adjacent keep ranges (#864, point=[[1, 3], [4, 8]]) still return 0, 1, 4, 5, 6, 7, as EEGLAB does, and test_adjacent_keep_ranges_match_eeglab is unchanged.

300 calls with odd or wrong input (10 and 37 samples at 100, 300 and 1024 Hz, three events): 10 change in EEGPrep. 7 are the last sample at 300 Hz and nopoint=[10, 11] at 1024 Hz, 2 are half sample limits point=[2.5, 7.5] at 1024 Hz (6 samples as at the other rates, not 5), and 1 is point=[[1, 5], [3, 9]] at 300 Hz. Between EEGLAB and EEGPrep, 53 of these 300 calls differed before and 37 differ after. The 37 are the two habits above (25 ranges out of the data, 12 unsorted or overlapping keep ranges). The 16 that no longer differ were wrong in EEGLAB: int32 points (12), an event kept on a removed sample at 1024 Hz (3), and nopoint=[10, 11] at 1024 Hz (1).

Tests

tests/test_pop_select.py, tests/test_gui_pop_select.py, tests/test_eeg_eegrej.py, tests/test_rejection_workflows.py, tests/test_gui_rejection_dialogs.py and tests/test_sigproc_eegrej.py with EEGPREP_SKIP_MATLAB=1: 127 passed, 2 skipped, 72 subtests passed. The 2 skipped tests need the MATLAB Engine for Python, which this Mac does not have. There is no test file for pop_rejcont.

The new test test_point_ranges_do_not_keep_last_sample_from_1e9_time_rounding runs on 10 and 37 samples at 300, 1024, 2048 and 30000 Hz. Its expected values (kept values, pnts, xmax, boundary events, the event on a removed sample) come from the EEGLAB run on b887b4c35. 14 of its subtests fail on develop. ruff check, ruff format --check and ./pre-commit.py pass, and docs/source/changelog.rst has the entry.

The branch has three commits because a pushed branch is never rewritten: the first version (99724109), the smaller version that leaves the checks in seconds for epoched data untouched and adds the branch only (28db6959), and the changelog (18306161).

Related: #729, #853, #864, #867, sccn/eeglab issue 1007, sccn/eeglab_tests pull request 20.

— orchestrator

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@claude

claude Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @arnodelorme's task in 1m 16s —— View job


Code review

  • Overall assessment: The code is correct. I compared it line by line with the pop_select.m change in sccn/eeglab#1008 (2ca1ff7) and found no bugs. The only gap is the missing changelog entry described below.
  • Highest-risk area: the new continuous point complement builder, pop_select.py:506-528.
  • Merge recommendation: Wait. pop_select: keep continuous point ranges in points so the last sample is not kept eeglab#1008 is still OPEN. As the PR body says, merging this first would move EEGPrep away from EEGLAB develop in 156 of 9,243 ranges. Merging also needs Arno's sign-off on the MATLAB evidence already in the PR body.

Blocking

None. The merge order above is a sequencing requirement, not a code defect.

Important

None.

Nits

Test gaps

None. test_point_ranges_do_not_keep_last_sample_from_1e9_time_rounding fails on develop and covers the cases from the issue:

  • point with the last sample kept, point that is open at the end, and point that starts at the first sample
  • nopoint and rmpoint on [n, n]
  • refusal of a disjoint range

It covers all four affected sampling rates and both lengths. The existing test_adjacent_keep_ranges_match_eeglab still pins the #864 behaviour.

EEGLAB parity notes

I traced the new code against the EEG.trials == 1 branch of #1008 by hand:

  • Edge shifting is equivalent. EEGLAB adds 1 to odd-indexed points and subtracts 1 from even-indexed ones, except at 1 and EEG.pnts. The Python code adds 1 to each region start unless it is 1, and subtracts 1 from each region end unless it is pnts. A region start can only equal pnts when cur < pnts is false, and then no region is appended. A region end can only be 1 if p0 > cur >= 1, which cannot happen. So the outputs are identical.
  • Single-sample keeps at the edges remove the whole dataset in both. point=[1, 1] and point=[n, n] give a rejection of [1, n] in both EEGLAB [GUI] Match the pop_clean_rawdata dialog to EEGLAB #1008 and this PR, and the old time path did the same. This is shared behaviour, not a regression from this PR. It may deserve its own issue if a one-sample keep should be allowed.
  • Two existing EEGPrep differences are kept as they were. These are not regressions; the PR body already mentions the disjoint refusal.
    • Python sorts and merges overlapping keep ranges. EEGLAB passes g.point to eeg_eegrej in the order given.
    • A disjoint point range raises ValueError. EEGLAB clamps it to [pnts, pnts] and then rejects all data.
  • nopoint clipping differs slightly from MATLAB. _clip_time_matrix clips every entry. pop_select.m clamps only g.nopoint(1) and g.nopoint(end), so in a multi-row nopoint an out-of-range interior bound raises an error in EEGLAB but is clipped silently here. This only matters for unusual input; I mention it for completeness.
  • The epoched paths and the time/notime paths are unchanged.

What I could not run: uv run pytest and ad-hoc probe scripts were not allowed in this job, so this review is based on reading the code. I did not reproduce the PR's "100 passed" result myself.

@arnodelorme

Copy link
Copy Markdown
Collaborator Author

Code review

Independent review by Codex (OpenAI GPT-6.1 Terra), asked by the orchestrator. The first version of this change was written by Gemini 4 Carbon and the present version (commits 28db695 and 1830616) by Claude Fable 5.2, so the reviewer is from a third vendor. Codex read the diff against develop in a read-only sandbox and found nothing blocking. It could not run the tests there. The runs are in the description of the pull request.

What Codex checked. The new branch gives what the time code gave in exact arithmetic, also for unsorted and overlapping rows and for ranges that touch either end. nopoint still wins over point, and the point options still win over the time options. Epoched data and ranges in seconds are unchanged. The values refreshed after eeg_eegrej are used correctly afterwards. The tests target the rounding failure and their expected values are plausible.

One remark, nothing to fix here. Adjacent keep ranges such as point=[[1, 3], [4, 8]] still lose samples 3 and 4. This is #864, which this pull request leaves as it is, as EEGLAB does.

What I fixed before this review. The automatic review above asked for a changelog entry, which is now in docs/source/changelog.rst. My own comparison caught a fault in my first rewrite, which emptied the point ranges on epoched data and removed one sample too many there (12 of 25 epoched calls changed). It was corrected before the commit, and the 25 epoched calls are the same as on develop.

The text of Codex, unchanged

No blocking correctness findings. I found no new correctness bug in the diff.

In exact arithmetic, the new point branch follows the previous time path, including for unsorted and overlapping rows and for ranges touching either edge. nopoint takes precedence over point, as before. Point options also continue to override time options. The epoched and seconds paths remain unchanged, and the fields refreshed after eeg_eegrej are used consistently later.

One preexisting limitation remains: adjacent keep ranges such as point=[[1, 3], [4, 8]] remove samples 3 and 4. The existing test documents that behavior, and this change preserves it.

The new tests target the reported rounding failure and the expected data and boundary values are plausible. I could not run them in the read-only environment because the project virtual environment was absent and the available Python lacked NumPy.

— orchestrator

This branch has not been deployed

No deployments
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.

pop_select: keep point ranges in points on continuous data so the last sample is not kept at 300, 1024, 2048 and 30000 Hz

1 participant