Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Fixed:
- Better subclassing support: Determine classes dynamically,
so that methods like str() are aware when our types are subclassed.
- Removed no-op check and extra list allocation during chop()
- Maintainers:
- Load issue4 test data via JSON to save on compilation and collection time.

Expand Down
10 changes: 8 additions & 2 deletions intervaltree/intervaltree.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from numbers import Number
from sortedcontainers import SortedDict
from copy import copy
from warnings import warn

try:
from collections.abc import MutableSet # Python 3?
Expand Down Expand Up @@ -497,10 +496,17 @@ def chop(self, begin, end, datafunc=None):
"""
Like remove_envelop(), but trims back Intervals hanging into
the chopped area so that nothing overlaps.
If specified, uses datafunc(interval, islower=True/False) to
set the data field of the new Intervals.
:param begin: where to chop
:param end: where to chop
:param datafunc(interval, isupper): callable returning a new
value for the interval's data field, whenever overhangers are
replaced.
"""
insertions = set()
begin_hits = [iv for iv in self.at(begin) if iv.begin < begin]
end_hits = [iv for iv in self.at(end) if iv.end > end]
end_hits = self.at(end)

if datafunc:
for iv in begin_hits:
Expand Down