Skip to content

Commit

Permalink
Ensure dtype=None fails
Browse files Browse the repository at this point in the history
  • Loading branch information
honno committed Sep 16, 2021
1 parent 9b083ff commit f9df07a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
RELEASE_TYPE: patch

This release fixes ``None`` being inferred as the float64 dtype in
:func:`~xps.from_dtype()` and :func:`~xps.arrays()` from the
:ref:`Array API extra <array-api>`.
6 changes: 5 additions & 1 deletion hypothesis-python/src/hypothesis/extra/array_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ def find_castable_builtin_for_dtype(
return int

float_dtypes, float_stubs = partition_attributes_and_stubs(xp, FLOAT_NAMES)
if dtype in float_dtypes:
# None equals NumPy's xp.float64 object, so we specifically skip it here to
# ensure that InvalidArgument is still raised. xp.float64 is in fact an
# alias of np.dtype('float64'), and its equality with None is meant to be
# deprecated at some point - see https://github.com/numpy/numpy/issues/18434.
if dtype is not None and dtype in float_dtypes:
return float

stubs.extend(int_stubs)
Expand Down
3 changes: 3 additions & 0 deletions hypothesis-python/tests/array_api/test_argument_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def e(a, **kwargs):
@pytest.mark.parametrize(
("function", "kwargs"),
[
e(xps.arrays, dtype=1, shape=5),
e(xps.arrays, dtype=None, shape=5),
e(xps.arrays, dtype=xp.int8, shape=(0.5,)),
e(xps.arrays, dtype=xp.int8, shape=1, fill=3),
e(xps.arrays, dtype=xp.int8, shape=1, elements="not a strategy"),
Expand All @@ -40,6 +42,7 @@ def e(a, **kwargs):
e(xps.array_shapes, min_dims="not an int"),
e(xps.array_shapes, max_dims="not an int"),
e(xps.from_dtype, dtype=1),
e(xps.from_dtype, dtype=None),
e(xps.from_dtype, dtype=xp.int8, min_value="not an int"),
e(xps.from_dtype, dtype=xp.int8, max_value="not an int"),
e(xps.from_dtype, dtype=xp.float32, min_value="not a float"),
Expand Down

0 comments on commit f9df07a

Please sign in to comment.