Skip to content

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

Merged
merged 7 commits into from
Oct 9, 2019

Conversation

rth
Copy link
Member

@rth rth commented Oct 7, 2019

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 and test_ball_tree.py into a common file test_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.

@@ -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)
Copy link
Member Author

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).

Copy link
Member

@ogrisel ogrisel left a 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.

'Cls, metric',
itertools.chain(
[(KDTree, metric) for metric in KD_TREE_METRICS],
[(BallTree, metric) for metric in BALL_TREE_METRICS]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice trick

Copy link
Member

@thomasjpfan thomasjpfan left a 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)

rth and others added 2 commits October 9, 2019 18:05
@rth
Copy link
Member Author

rth commented Oct 9, 2019

Thanks @thomasjpfan, should be good now. (Renamed to test_neighbors_tree.py to be shorter and more consistent with other test files).

@thomasjpfan thomasjpfan merged commit 6e02fee into scikit-learn:master Oct 9, 2019
@thomasjpfan
Copy link
Member

Thank you @rth!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants