Repository navigation
Make chop() a no-op for degenerate ranges - #165
Open
36taransingh5-dotcom wants to merge 2 commits into
Open
36taransingh5-dotcom wants to merge 2 commits into
36taransingh5-dotcom wants to merge 2 commits into
Conversation
… >= end used to split intervals containing the range endpoints (chop(x, x) acted like slice(x)) or, for begin > end, produce overlapping duplicate pieces. Nothing overlaps an empty range, so nothing should be trimmed: return early instead. Add a guard clause to prevent processing invalid intervals.
Add test for chopping degenerate ranges in IntervalTree.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
chop(begin, end)withbegin >= endused to mutate the tree instead of doing nothing:chop(x, x)split every interval containingxin two (acting likeslice(x)), so the original intervals silently disappeared and could no longer be removed.chop(9, 5)turned(0, 10)into the overlapping pieces(0, 9)and(5, 10), double-covering the middle and inflatinglen().Nothing overlaps an empty range, so there is nothing to trim and nothing enveloped to remove. This PR returns early when
begin >= end, matching the docstring ("Like remove_envelop(), but trims back Intervals hanging into the chopped area so that nothing overlaps") and Python slice semantics for empty ranges.Reproducer
Tests
test_chop_degenerate_rangecoverschop(5, 5),chop(9, 5), and the empty tree.Developed with AI assistance.