Skip to content

Commit 07a1d62

Browse files
committed
Correct fill_value values for test_full_like() + relevant assertions
1 parent 2b414ab commit 07a1d62

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

array_api_tests/test_creation_functions.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from hypothesis.strategies._internal.core import sampled_from
12
from ._array_module import (asarray, arange, ceil, empty, empty_like, eye, full,
23
full_like, equal, all, linspace, ones, ones_like,
34
zeros, zeros_like, isnan)
5+
from . import _array_module as xp
46
from .array_helpers import (is_integer_dtype, dtype_ranges,
57
assert_exactly_equal, isintegral, is_float_dtype)
68
from .hypothesis_helpers import (numeric_dtypes, dtypes, MAX_ARRAY_SIZE,
@@ -157,9 +159,11 @@ def test_full(shape, fill_value, dtype):
157159

158160
@composite
159161
def fill_values(draw):
162+
# If dtype has been specified, fill_value should be inferred from it
160163
dtype = draw(shared_optional_dtypes)
164+
# If dtype=None, fill_value can be anything - full_like should infer the dtype
161165
if dtype is None:
162-
dtype = draw(shared_dtypes)
166+
dtype = draw(sampled_from([xp.bool, xp.int32, xp.float32]))
163167
return draw(xps.from_dtype(dtype))
164168

165169
@given(
@@ -168,13 +172,17 @@ def fill_values(draw):
168172
dtype=shared_optional_dtypes,
169173
)
170174
def test_full_like(x, fill_value, dtype):
171-
kwargs = {} if dtype is None else {'dtype': dtype}
172-
173-
x_like = full_like(x, fill_value, **kwargs)
175+
x_like = full_like(x, fill_value, dtype=dtype)
174176

175177
if dtype is None:
176-
# TODO: Should it actually match x.dtype?
177-
pass
178+
if isinstance(fill_value, bool):
179+
assert x_like.dtype == xp.bool, f"{fill_value=}, but full_like() did not produce a boolean array - instead was {x_like.dtype}"
180+
elif isinstance(fill_value, int):
181+
assert x_like.dtype in (xp.int32, xp.int64), f"{fill_value=}, but full_like() did not produce a int32 or int64 array - instead was {x_like.dtype}"
182+
elif isinstance(fill_value, float):
183+
assert x_like.dtype in (xp.float32, xp.float64), f"{fill_value=}, but full_like() did not produce a float32 or float64 array - instead was {x_like.dtype}"
184+
else:
185+
raise Exception(f"Sanity check failed, indiciating a bug in the test suite. {fill_value=} - should be a bool, int or float")
178186
else:
179187
assert x_like.dtype == dtype
180188

0 commit comments

Comments
 (0)