|
1 |
| -from hypothesis.strategies._internal.core import sampled_from |
2 | 1 | from ._array_module import (asarray, arange, ceil, empty, empty_like, eye, full,
|
3 | 2 | full_like, equal, all, linspace, ones, ones_like,
|
4 | 3 | zeros, zeros_like, isnan)
|
5 |
| -from . import _array_module as xp |
6 | 4 | from .array_helpers import (is_integer_dtype, dtype_ranges,
|
7 | 5 | assert_exactly_equal, isintegral, is_float_dtype)
|
8 | 6 | from .hypothesis_helpers import (numeric_dtypes, dtypes, MAX_ARRAY_SIZE,
|
9 | 7 | shapes, sizes, sqrt_sizes, shared_dtypes,
|
10 | 8 | scalars, xps)
|
11 | 9 |
|
12 | 10 | 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 |
14 | 12 |
|
15 | 13 |
|
16 | 14 | optional_dtypes = none() | shared_dtypes
|
@@ -157,34 +155,19 @@ def test_full(shape, fill_value, dtype):
|
157 | 155 | else:
|
158 | 156 | assert all(equal(a, asarray(fill_value, **kwargs))), "full() array did not equal the fill value"
|
159 | 157 |
|
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)) |
168 | 158 |
|
169 | 159 | @given(
|
170 | 160 | x=xps.arrays(dtype=shared_dtypes, shape=shapes),
|
171 |
| - fill_value=fill_values(), |
| 161 | + fill_value=shared_dtypes.flatmap(xps.from_dtype), |
172 | 162 | dtype=shared_optional_dtypes,
|
173 | 163 | )
|
174 | 164 | def test_full_like(x, fill_value, dtype):
|
175 | 165 | x_like = full_like(x, fill_value, dtype=dtype)
|
176 | 166 |
|
177 | 167 | 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}" |
186 | 169 | 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}" |
188 | 171 |
|
189 | 172 | assert x_like.shape == x.shape, "full_like() produced an array with incorrect shape"
|
190 | 173 | if is_float_dtype(x_like.dtype) and isnan(asarray(fill_value)):
|
|
0 commit comments