-
Notifications
You must be signed in to change notification settings - Fork 586
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
Float strategy can generate infinite values, even if explicitly excluded #1859
Comments
|
Gah, I'd handled the Unfortunately the solution will involve |
|
There is therefore a related question : It seems somewhere along the way my large float (likely around 64bits representable float limitations) has been reinterpreted as infinite. |
|
Your problem here is that If you want a finite float that is always valid as an exclusive finite bound, you can draw one from |
|
Thanks I managed to cover my use case for now. In case it helps someone later, I first generate a mpmath.mpi (multiprecision interval) with : @composite
def mpi_strat(draw)
low_bound = draw(hypothesis.strategies.floats(allow_nan=False))
high_bound = draw(
hypothesis.strategies.floats(allow_nan=False, min_value=low_bound)
)
return mpmath.mpi(low_bound, high_bound)And then to draw a float outside that interval when possible (with potentially infinite bounds). @composite
def underbounds(draw,):
b = draw(mpi_strat())
assume(isfinite(b.a) and sys.float_info.min < float(b.a) < sys.float_info.max)
v = draw(floats(max_value=float(b.a), exclude_max=True, allow_infinity=False))
return v, bI cannot test outside the representable float range, but it should be enough for my use-case (I m using mpmath for precision tracking purposes, not large numbers) so I'm fine with that. |
When specifying infinity as the max of min value for a float, and then excluding this value, it can still be generated.
This is easy to fix with simple strategies, but when generating min and max values from another strategy, and relying on the
excludeparameter to specify open or closed intervals to draw a float, it may cause problems.Here is a sample code to reproduce the problem :
I would have expected the strategy to fail somehow... but it succeeds and generate only infinity, even tho it should be excluded.
So running this script I get :
The text was updated successfully, but these errors were encountered: