Skip to content
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

hypothesis.extra.numpy.from_dtype is difficult to use with complex dtypes #3573

Closed
felixdivo opened this issue Feb 6, 2023 · 1 comment · Fixed by #3574
Closed

hypothesis.extra.numpy.from_dtype is difficult to use with complex dtypes #3573

felixdivo opened this issue Feb 6, 2023 · 1 comment · Fixed by #3574
Assignees
Labels
bug something is clearly wrong here

Comments

@felixdivo
Copy link
Contributor

felixdivo commented Feb 6, 2023

The following code ...

import numpy
from hypothesis.extra.numpy import from_dtype

print(repr(from_dtype(numpy.dtype("complex64"), max_magnitude=3).example()))

... generates this exception with varying values (line breaks added):

hypothesis.errors.InvalidArgument:
min_value=-2.958039891549808 cannot be exactly represented as a float of width 32
- use min_value=-2.9580399990081787 instead.

It is raised here (with a useless strack trace):

if min_value != min_arg:
raise InvalidArgument(
f"min_value={min_arg!r} cannot be exactly represented as a float "
f"of width {width} - use min_value={min_value!r} instead."
)

Curiously, the same setup works for hypothesis.strategies.complex_numbers:

from hypothesis.strategies import complex_numbers

print(repr(complex_numbers(max_magnitude=3).example()))

Tested on hypothesis 6.67.1.

@felixdivo
Copy link
Contributor Author

Thanks @honno for looking into this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something is clearly wrong here
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants