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

integers(x, x) can generate (x-1) if x is an int64 #1667

Closed
dycw opened this issue Nov 5, 2018 · 3 comments
Closed

integers(x, x) can generate (x-1) if x is an int64 #1667

dycw opened this issue Nov 5, 2018 · 3 comments
Assignees
Labels
bug something is clearly wrong here

Comments

@dycw
Copy link

dycw commented Nov 5, 2018

Hi,

Just stumbled upon this by accident. Using hypothesis 3.68.0 and numpy 1.15.2:

from hypothesis import given
from hypothesis.strategies import data, integers
from hypothesis.extra.numpy import from_dtype, integer_dtypes

@given(data=data(), dtype=integer_dtypes())
def test_numpy_integers(data, dtype):
    x = data.draw(from_dtype(dtype))
    assert data.draw(integers(x, x)) == x

For example, with the int64 type we can fail with x = 9007199254740993, with integers() generating x - 1. I've not seen examples of anything other than x - 1 being generated.

@Zac-HD Zac-HD added the bug something is clearly wrong here label Nov 6, 2018
@Zalathar
Copy link
Contributor

Zalathar commented Nov 6, 2018

I had a quick look into this, and was surprised to find that floor(x) != x for some values of x that are numpy.int64.

Since we call floor and ceil on the arguments to integers(), this causes strange things to happen.

I haven't had a chance to figure out what's actually going on here.

@Zac-HD
Copy link
Member

Zac-HD commented Nov 6, 2018

The return type of numpy.ceil is float64, just like math.ceil in Python 2. Apparently there is also an intermediate cast to float in the __ceil__ method of integer dtype values - for example x = 9007199254740993 = 2 ** 53 + 1, and np.ceil(x) == 9007199254740992.0. This is actually also the Python2 behaviour of math.ceil (which we work around in Hypothesis), so it's certainly not unprecedented!

I've added a comment to the upstream issue, but for us the best option is probably to use the Python 2 implementation on all versions for now.

@dycw
Copy link
Author

dycw commented Nov 6, 2018

Thanks @Zac-HD, so efficient!

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

No branches or pull requests

3 participants