Skip to content

Commit 312db69

Browse files
committed
Prematurely update test_full_like for proposed spec change
See data-apis/array-api#274
1 parent 8c26f50 commit 312db69

File tree

2 files changed

+4
-24
lines changed

2 files changed

+4
-24
lines changed

.github/workflows/numpy.yml

-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ jobs:
5151
"array_api_tests/test_signatures.py::test_function_positional_args[__index__]",
5252
"array_api_tests/test_signatures.py::test_function_keyword_only_args[prod]",
5353
"array_api_tests/test_signatures.py::test_function_keyword_only_args[sum]",
54-
55-
# https://github.com/data-apis/array-api-tests/pull/18#discussion_r715047213
56-
"array_api_tests/test_creation_functions.py::test_full_like"
5754
)
5855
5956
def pytest_collection_modifyitems(config, items):

array_api_tests/test_creation_functions.py

+4-21
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
from hypothesis.strategies._internal.core import sampled_from
21
from ._array_module import (asarray, arange, ceil, empty, empty_like, eye, full,
32
full_like, equal, all, linspace, ones, ones_like,
43
zeros, zeros_like, isnan)
5-
from . import _array_module as xp
64
from .array_helpers import (is_integer_dtype, dtype_ranges,
75
assert_exactly_equal, isintegral, is_float_dtype)
86
from .hypothesis_helpers import (numeric_dtypes, dtypes, MAX_ARRAY_SIZE,
97
shapes, sizes, sqrt_sizes, shared_dtypes,
108
scalars, xps)
119

1210
from hypothesis import assume, given
13-
from hypothesis.strategies import integers, floats, one_of, none, booleans, just, shared, composite
11+
from hypothesis.strategies import integers, floats, one_of, none, booleans, just, shared
1412

1513

1614
optional_dtypes = none() | shared_dtypes
@@ -157,34 +155,19 @@ def test_full(shape, fill_value, dtype):
157155
else:
158156
assert all(equal(a, asarray(fill_value, **kwargs))), "full() array did not equal the fill value"
159157

160-
@composite
161-
def fill_values(draw):
162-
# If dtype has been specified, fill_value should be inferred from it
163-
dtype = draw(shared_optional_dtypes)
164-
# If dtype=None, fill_value can be anything - full_like should infer the dtype
165-
if dtype is None:
166-
dtype = draw(sampled_from([xp.bool, xp.int32, xp.float32]))
167-
return draw(xps.from_dtype(dtype))
168158

169159
@given(
170160
x=xps.arrays(dtype=shared_dtypes, shape=shapes),
171-
fill_value=fill_values(),
161+
fill_value=shared_dtypes.flatmap(xps.from_dtype),
172162
dtype=shared_optional_dtypes,
173163
)
174164
def test_full_like(x, fill_value, dtype):
175165
x_like = full_like(x, fill_value, dtype=dtype)
176166

177167
if dtype is None:
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")
168+
assert x_like.dtype == x.dtype, f"{x.dtype=}, but full_like() did not produce a {x.dtype} array - instead was {x_like.dtype}"
186169
else:
187-
assert x_like.dtype == dtype
170+
assert x_like.dtype == None, f"{dtype=}, but full_like() did not produce a {dtype} array - instead was {x_like.dtype}"
188171

189172
assert x_like.shape == x.shape, "full_like() produced an array with incorrect shape"
190173
if is_float_dtype(x_like.dtype) and isnan(asarray(fill_value)):

0 commit comments

Comments
 (0)