Skip to content

Fix overlapping interval union#1520

Open
samuelbray32 wants to merge 7 commits intomasterfrom
interval_union
Open

Fix overlapping interval union#1520
samuelbray32 wants to merge 7 commits intomasterfrom
interval_union

Conversation

@samuelbray32
Copy link
Collaborator

@samuelbray32 samuelbray32 commented Feb 6, 2026

Description

Checklist:

  • NA If this PR should be accompanied by a release, I have updated the CITATION.cff
  • NA If this PR edits table definitions, I have included an alter snippet for release notes.
  • NA If this PR makes changes to position, I ran the relevant tests locally.
  • NA If this PR makes user-facing changes, I have added/edited docs/notebooks to reflect the changes
  • I have updated the CHANGELOG.md with PR number and description.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses incorrect behavior in Interval.union when interval lists contain overlapping intervals (fixing #1519) and introduces stricter validation intended to ensure interval lists are well-formed.

Changes:

  • Fix Interval.union start/stop detection logic for overlapping intervals and add internal consistency checks.
  • Add _extract_only + _validate_intervals to validate extracted interval-like inputs.
  • Update interval helper tests to cover the overlapping-union case and adjust existing expected values.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/spyglass/common/common_interval.py Updates union algorithm and introduces interval extraction + validation helpers.
tests/common/test_interval_helpers.py Updates/extends test cases for Interval.union behavior.
Comments suppressed due to low confidence (1)

tests/common/test_interval_helpers.py:379

  • New interval validation behavior is introduced via _validate_intervals, but there are no tests asserting that invalid intervals (e.g. [start > stop], including the single-interval case) raise a ValueError, or that unsorted-but-valid inputs are handled as intended. Adding a focused test (or two) here would lock in the new contract and prevent regressions.
@pytest.mark.parametrize(
    "one, two, expected_result",
    [
        (
            np.array([[0, 3]]),
            np.array([[2, 4]]),
            np.array([[0, 4]]),
        ),
        (
            np.array([[0, 1]]),
            np.array([[2, 4]]),
            np.array([[0, 1], [2, 4]]),
        ),
        (
            np.array([[1, 3], [9, 10]]),
            np.array([[0, 2]]),
            np.array([[0, 3], [9, 10]]),
        ),
        (
            np.array([[0, 1]]),
            np.array([[2, 1e11]]),
            np.array([[0, 1], [2, 1e11]]),
        ),
    ],
)
def test_interval_list_union(interval_obj, one, two, expected_result):
    ret = interval_obj(one).union(two).times
    assert np.array_equal(ret, expected_result), "Problem with Interval.union"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@samuelbray32 samuelbray32 marked this pull request as ready for review February 25, 2026 19:46
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.

Incorrect interval union for overlapping intervals

2 participants