Skip to content

Commit cde73af

Browse files
WillAydjschendel
authored andcommitted
Removed dead intervaltree code (#30459)
1 parent fca241a commit cde73af

File tree

2 files changed

+0
-64
lines changed

2 files changed

+0
-64
lines changed

pandas/_libs/intervaltree.pxi.in

-37
Original file line numberDiff line numberDiff line change
@@ -114,43 +114,6 @@ cdef class IntervalTree(IntervalMixin):
114114
sort_order = np.lexsort(values)
115115
return is_monotonic(sort_order, False)[0]
116116

117-
def get_loc(self, scalar_t key):
118-
"""Return all positions corresponding to intervals that overlap with
119-
the given scalar key
120-
"""
121-
result = Int64Vector()
122-
self.root.query(result, key)
123-
if not result.data.n:
124-
raise KeyError(key)
125-
return result.to_array().astype('intp')
126-
127-
def _get_partial_overlap(self, key_left, key_right, side):
128-
"""Return all positions corresponding to intervals with the given side
129-
falling between the left and right bounds of an interval query
130-
"""
131-
if side == 'left':
132-
values = self.left
133-
sorter = self.left_sorter
134-
else:
135-
values = self.right
136-
sorter = self.right_sorter
137-
key = [key_left, key_right]
138-
i, j = values.searchsorted(key, sorter=sorter)
139-
return sorter[i:j]
140-
141-
def get_loc_interval(self, key_left, key_right):
142-
"""Lookup the intervals enclosed in the given interval bounds
143-
144-
The given interval is presumed to have closed bounds.
145-
"""
146-
import pandas as pd
147-
left_overlap = self._get_partial_overlap(key_left, key_right, 'left')
148-
right_overlap = self._get_partial_overlap(key_left, key_right, 'right')
149-
enclosing = self.get_loc(0.5 * (key_left + key_right))
150-
combined = np.concatenate([left_overlap, right_overlap, enclosing])
151-
uniques = pd.unique(combined)
152-
return uniques.astype('intp')
153-
154117
def get_indexer(self, scalar_t[:] target):
155118
"""Return the positions corresponding to unique intervals that overlap
156119
with the given array of scalar targets.

pandas/tests/indexes/interval/test_interval_tree.py

-27
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,6 @@ def tree(request, leaf_size):
5353

5454

5555
class TestIntervalTree:
56-
def test_get_loc(self, tree):
57-
result = tree.get_loc(1)
58-
expected = np.array([0], dtype="intp")
59-
tm.assert_numpy_array_equal(result, expected)
60-
61-
result = np.sort(tree.get_loc(2))
62-
expected = np.array([0, 1], dtype="intp")
63-
tm.assert_numpy_array_equal(result, expected)
64-
65-
with pytest.raises(KeyError, match="-1"):
66-
tree.get_loc(-1)
67-
6856
def test_get_indexer(self, tree):
6957
result = tree.get_indexer(np.array([1.0, 5.5, 6.5]))
7058
expected = np.array([0, 4, -1], dtype="intp")
@@ -98,10 +86,6 @@ def test_duplicates(self, dtype):
9886
left = np.array([0, 0, 0], dtype=dtype)
9987
tree = IntervalTree(left, left + 1)
10088

101-
result = np.sort(tree.get_loc(0.5))
102-
expected = np.array([0, 1, 2], dtype="intp")
103-
tm.assert_numpy_array_equal(result, expected)
104-
10589
with pytest.raises(
10690
KeyError, match="'indexer does not intersect a unique set of intervals'"
10791
):
@@ -116,17 +100,6 @@ def test_duplicates(self, dtype):
116100
expected = np.array([], dtype="intp")
117101
tm.assert_numpy_array_equal(result, expected)
118102

119-
def test_get_loc_closed(self, closed):
120-
tree = IntervalTree([0], [1], closed=closed)
121-
for p, errors in [(0, tree.open_left), (1, tree.open_right)]:
122-
if errors:
123-
with pytest.raises(KeyError, match=str(p)):
124-
tree.get_loc(p)
125-
else:
126-
result = tree.get_loc(p)
127-
expected = np.array([0], dtype="intp")
128-
tm.assert_numpy_array_equal(result, expected)
129-
130103
@pytest.mark.parametrize(
131104
"leaf_size", [skipif_32bit(1), skipif_32bit(10), skipif_32bit(100), 10000]
132105
)

0 commit comments

Comments
 (0)