-
-
Notifications
You must be signed in to change notification settings - Fork 26k
TST Common tests between KDTree and BallTree #15148
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
TST Common tests between KDTree and BallTree #15148
Conversation
@@ -212,6 +159,7 @@ def test_neighbors_heap(n_pts=5, n_nbrs=10): | |||
|
|||
|
|||
def test_node_heap(n_nodes=50): | |||
rng = np.random.RandomState(42) |
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.
A global mutable RNG was previously reused which is not great with respect to test determinism (given that order of tests can change).
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.
Small nitpicks but otherwise LGTM.
sklearn/neighbors/tests/test_tree.py
Outdated
'Cls, metric', | ||
itertools.chain( | ||
[(KDTree, metric) for metric in KD_TREE_METRICS], | ||
[(BallTree, metric) for metric in BALL_TREE_METRICS])) |
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.
nice trick
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.
LGTM, please rename sklearn/neighbors/tests/test_tree.py
to sklearn/neighbors/tests/test_nearest_neighbors_tree.py
as suggested #15148 (comment)
Co-Authored-By: Thomas J Fan <thomasjpfan@gmail.com>
Thanks @thomasjpfan, should be good now. (Renamed to |
Thank you @rth! |
The API of KDTree and BallTree is almost identical, and yet they have separate test files probably because they were written when pytest parametization were not used.
This puts some of redundant tests from
test_kd_tree.py
andtest_ball_tree.py
into a common filetest_tree.py
.Started with two tests, but more tests could be factorized in the future. This helps ensure that the API is consistent, and reduce the amount of redundant edits that are needed when we change something.