Skip to content

Commit

Permalink
BUG: Fix RecursionError during IntervalTree construction (#25498)
Browse files Browse the repository at this point in the history
  • Loading branch information
jschendel authored and jreback committed Mar 3, 2019
1 parent d708461 commit cc5b73e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Bug Fixes

- Bug in :meth:`Series.is_unique` where single occurrences of ``NaN`` were not considered unique (:issue:`25180`)
- Bug in :func:`merge` when merging an empty ``DataFrame`` with an ``Int64`` column or a non-empty ``DataFrame`` with an ``Int64`` column that is all ``NaN`` (:issue:`25183`)
- Bug in ``IntervalTree`` where a ``RecursionError`` occurs upon construction due to an overflow when adding endpoints, which also causes :class:`IntervalIndex` to crash during indexing operations (:issue:`25485`)
-

.. _whatsnew_0.242.contributors:
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/intervaltree.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ cdef class {{dtype_title}}Closed{{closed_title}}IntervalNode:
else:
# calculate a pivot so we can create child nodes
self.is_leaf_node = False
self.pivot = np.median(left + right) / 2
self.pivot = np.median(left / 2 + right / 2)
left_set, right_set, center_set = self.classify_intervals(
left, right)

Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/indexes/interval/test_interval_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,13 @@ def test_is_overlapping_trivial(self, closed, left, right):
# GH 23309
tree = IntervalTree(left, right, closed=closed)
assert tree.is_overlapping is False

def test_construction_overflow(self):
# GH 25485
left, right = np.arange(101), [np.iinfo(np.int64).max] * 101
tree = IntervalTree(left, right)

# pivot should be average of left/right medians
result = tree.root.pivot
expected = (50 + np.iinfo(np.int64).max) / 2
assert result == expected

0 comments on commit cc5b73e

Please sign in to comment.