Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix test bug where size-1 sample may be used (with top_k=2) #46

Merged
merged 3 commits into from
Aug 3, 2023

Conversation

EliahKagan
Copy link
Collaborator

@EliahKagan EliahKagan commented Aug 3, 2023

Closes #45

This changes the range of possible sample sizes in TestKnnClassifier.test_predict to have a lower bound of 2 instead of 1, so that the test, which always uses a top_k of 2, no longer occasionally fails.

The change is actually very simple, but I did it in a few commits to verify and show that a lower bound of 1 was the problem. The sample size is being selected randomly, so it would otherwise not be immediately clear that this change really fixes the bug.

This temporarily modifies test_predict so it produces the problem
in every test run, in order to verify that the immediately
forthcoming fix is effective.

Because this commit decreases the general usefulness of the test,
it needs to be undone/reverted after that has been verified.
This puts the upper bound for the randomly determined sample size
back to 50. The immediately preceding commits verified that the
bug can be fixed by a change in the lower bound, but we don't
always want to use a lower bound of 2!

It may be best to choose the sample size non-randomly, perhaps
testing multiple sample sizes per run using parametrization or
subtests. But that is more extensive than the small change needed
for bazingagin#45, and thus beyond the scope here.
@EliahKagan EliahKagan marked this pull request as ready for review August 3, 2023 18:38
@bazingagin
Copy link
Owner

I think this situation will happen whenever the number of samples is smaller than k value. We can add constraint on that in the future but for now, it's all good. Thanks!

@bazingagin bazingagin merged commit 4c27a92 into bazingagin:main Aug 3, 2023
@EliahKagan EliahKagan deleted the fix-45 branch August 3, 2023 21:59
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test occasionally fails using top_k of 2 with just 1 sample
2 participants