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
Fix average_size calculation #3160
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
RELEASE_TYPE: patch | ||
|
||
This release fixes some internal calculations related to collection sizes (:issue:`3143`). |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -320,3 +320,7 @@ def test_can_draw_arbitrary_fractions(p, b): | |
def test_samples_from_a_range_directly(): | ||
s = cu.check_sample(range(10 ** 1000), "") | ||
assert isinstance(s, range) | ||
|
||
|
||
def test_p_continue_to_average_saturates(): | ||
assert cu._p_continue_to_avg(1.1, 100) == 100 | ||
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. Can we replace this special case with an 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. We do actually have such an example, but also need this test to reliably get full coverage from our conjecture-coverage task (the other is in nocover). |
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.
In this case I think we can just return p_continue (or do nothing, thus skipping the zeroth iteration of the while loop)? If
1 - 1.0 / (1 + desired_avg)
is close enough to the correct answer that floating-point error causes p_continue to be an overestimate then we're close enough for practical purposes.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 agree that the estimate is close enough that we could just use the initial p_continue.
However, it's cheap to make this adjustment, and that allows us to test that our binary search always maintains a strict upper bound.