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

exclude-min/exclude-max not reliable when drawing arrays of floats #1899

Closed
rsokl opened this issue Mar 26, 2019 · 1 comment · Fixed by #2049
Closed

exclude-min/exclude-max not reliable when drawing arrays of floats #1899

rsokl opened this issue Mar 26, 2019 · 1 comment · Fixed by #2049
Labels
bug something is clearly wrong here legibility make errors helpful and Hypothesis grokable

Comments

@rsokl
Copy link
Contributor

rsokl commented Mar 26, 2019

hypothesis-4.14.0

I'm not sure if this is necessarily a bug or something that should be documented in the arrays strategy.

import numpy as np
import pytest
import hypothesis.strategies as st
import hypothesis.extra.numpy as hnp


@pytest.mark.parametrize("dtype", [np.float16, np.float32, np.float64])
@pytest.mark.parametrize("max_", [-1., 0., 1.])
@given(st.data())
def test_bad_exclude_min_in_array(dtype, max_, data):
    x = data.draw(
        hnp.arrays(
            dtype=dtype,
            shape=(1,),
            elements=st.floats(max_ - 1., max_, exclude_max=True)),
        label="x"
    )
    assert np.all(x < max_)

image

@pytest.mark.parametrize("dtype", [np.float16, np.float32, np.float64])
@pytest.mark.parametrize("min_", [-1., 0., 1.])
@given(st.data())
def test_bad_float_exclude_max_in_array(dtype, min_, data):
    x = data.draw(
        hnp.arrays(
            dtype=dtype,
            shape=(1,),
            elements=st.floats(min_, min_ + 1, exclude_min=True)),
        label="x"
    )
    assert np.all(min_ < x)

image

(Sorry to leave a terse issue - I caught this at work and wanted to document it ASAP. Gotta run!)

@rsokl rsokl added bug something is clearly wrong here question not sure it's a bug? questions welcome and removed bug something is clearly wrong here labels Mar 26, 2019
@Zac-HD
Copy link
Member

Zac-HD commented Mar 27, 2019

The problem is that downcasting rounds to an excluded endpoint (fine so far...) which is silently added to the array when it should be emitting a warning about lossy conversion.

@Zac-HD Zac-HD added bug something is clearly wrong here and removed question not sure it's a bug? questions welcome labels Mar 27, 2019
@Zac-HD Zac-HD added the legibility make errors helpful and Hypothesis grokable label Jul 13, 2019
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 legibility make errors helpful and Hypothesis grokable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants