-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Add uint64 support to IntervalTree #20651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,33 +12,36 @@ def closed(request): | |
return request.param | ||
|
||
|
||
@pytest.fixture( | ||
scope='class', params=['int32', 'int64', 'float32', 'float64', 'uint64']) | ||
def dtype(request): | ||
return request.param | ||
|
||
|
||
@pytest.fixture(scope='class') | ||
def tree(dtype): | ||
left = np.arange(5, dtype=dtype) | ||
return IntervalTree(left, left + 2) | ||
|
||
|
||
class TestIntervalTree(object): | ||
def setup_method(self, method): | ||
def gentree(dtype): | ||
left = np.arange(5, dtype=dtype) | ||
right = left + 2 | ||
return IntervalTree(left, right) | ||
|
||
self.tree = gentree('int64') | ||
self.trees = {dtype: gentree(dtype) | ||
for dtype in ['int32', 'int64', 'float32', 'float64']} | ||
|
||
def test_get_loc(self): | ||
for dtype, tree in self.trees.items(): | ||
tm.assert_numpy_array_equal(tree.get_loc(1), | ||
np.array([0], dtype='int64')) | ||
tm.assert_numpy_array_equal(np.sort(tree.get_loc(2)), | ||
np.array([0, 1], dtype='int64')) | ||
with pytest.raises(KeyError): | ||
tree.get_loc(-1) | ||
|
||
def test_get_indexer(self): | ||
for dtype, tree in self.trees.items(): | ||
tm.assert_numpy_array_equal( | ||
tree.get_indexer(np.array([1.0, 5.5, 6.5])), | ||
np.array([0, 4, -1], dtype='int64')) | ||
with pytest.raises(KeyError): | ||
tree.get_indexer(np.array([3.0])) | ||
self.tree = tree('int64') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prob don't need setup_method this if you pass tree into other methods There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fixture makes more sense if you plan on using more than one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
def test_get_loc(self, tree): | ||
tm.assert_numpy_array_equal(tree.get_loc(1), | ||
np.array([0], dtype='int64')) | ||
tm.assert_numpy_array_equal(np.sort(tree.get_loc(2)), | ||
np.array([0, 1], dtype='int64')) | ||
with pytest.raises(KeyError): | ||
tree.get_loc(-1) | ||
|
||
def test_get_indexer(self, tree): | ||
tm.assert_numpy_array_equal( | ||
tree.get_indexer(np.array([1.0, 5.5, 6.5])), | ||
np.array([0, 4, -1], dtype='int64')) | ||
with pytest.raises(KeyError): | ||
tree.get_indexer(np.array([3.0])) | ||
|
||
def test_get_indexer_non_unique(self): | ||
indexer, missing = self.tree.get_indexer_non_unique( | ||
|
@@ -51,8 +54,9 @@ def test_get_indexer_non_unique(self): | |
np.array([-1], dtype='int64')) | ||
tm.assert_numpy_array_equal(missing, np.array([2], dtype='int64')) | ||
|
||
def test_duplicates(self): | ||
tree = IntervalTree([0, 0, 0], [1, 1, 1]) | ||
def test_duplicates(self, dtype): | ||
left = np.array([0, 0, 0], dtype=dtype) | ||
tree = IntervalTree(left, left + 1) | ||
tm.assert_numpy_array_equal(np.sort(tree.get_loc(0.5)), | ||
np.array([0, 1, 2], dtype='int64')) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not entirely sure if this is necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine. Even if your tests pass without it, I would still keep it for consistency.