Skip to content

Commit f9df07a

Browse files
committed
Ensure dtype=None fails
1 parent 9b083ff commit f9df07a

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎hypothesis-python/RELEASE.rst‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RELEASE_TYPE: patch
2+
3+
This release fixes ``None`` being inferred as the float64 dtype in
4+
:func:`~xps.from_dtype()` and :func:`~xps.arrays()` from the
5+
:ref:`Array API extra <array-api>`.

‎hypothesis-python/src/hypothesis/extra/array_api.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ def find_castable_builtin_for_dtype(
130130
return int
131131

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

136140
stubs.extend(int_stubs)

‎hypothesis-python/tests/array_api/test_argument_validation.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def e(a, **kwargs):
2828
@pytest.mark.parametrize(
2929
("function", "kwargs"),
3030
[
31+
e(xps.arrays, dtype=1, shape=5),
32+
e(xps.arrays, dtype=None, shape=5),
3133
e(xps.arrays, dtype=xp.int8, shape=(0.5,)),
3234
e(xps.arrays, dtype=xp.int8, shape=1, fill=3),
3335
e(xps.arrays, dtype=xp.int8, shape=1, elements="not a strategy"),
@@ -40,6 +42,7 @@ def e(a, **kwargs):
4042
e(xps.array_shapes, min_dims="not an int"),
4143
e(xps.array_shapes, max_dims="not an int"),
4244
e(xps.from_dtype, dtype=1),
45+
e(xps.from_dtype, dtype=None),
4346
e(xps.from_dtype, dtype=xp.int8, min_value="not an int"),
4447
e(xps.from_dtype, dtype=xp.int8, max_value="not an int"),
4548
e(xps.from_dtype, dtype=xp.float32, min_value="not a float"),

0 commit comments

Comments
 (0)