diff --git a/CHANGELOG.md b/CHANGELOG.md index 1eb3229..a71113f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/intervaltree/intervaltree.py b/intervaltree/intervaltree.py index 4dae20b..e273127 100644 --- a/intervaltree/intervaltree.py +++ b/intervaltree/intervaltree.py @@ -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? @@ -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: