Skip to content

TST Common tests between KDTree and BallTree#15148

Merged
thomasjpfan merged 7 commits intoscikit-learn:masterfrom
rth:factorize-neighbour-tests
Oct 9, 2019
Merged

TST Common tests between KDTree and BallTree#15148
thomasjpfan merged 7 commits intoscikit-learn:masterfrom
rth:factorize-neighbour-tests

Conversation

@rth
Copy link
Copy Markdown
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.



def test_node_heap(n_nodes=50):
rng = np.random.RandomState(42)
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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