|
8 | 8 | scalars, xps, shared_optional_promotable_dtypes)
|
9 | 9 |
|
10 | 10 | from hypothesis import assume, given
|
11 |
| -from hypothesis.strategies import integers, floats, one_of, none, booleans, just |
| 11 | +from hypothesis.strategies import integers, floats, one_of, none, booleans, just, shared, composite |
12 | 12 |
|
13 | 13 |
|
14 | 14 |
|
@@ -152,30 +152,36 @@ def test_full(shape, fill_value, dtype):
|
152 | 152 | else:
|
153 | 153 | assert all(equal(a, asarray(fill_value, **kwargs))), "full() array did not equal the fill value"
|
154 | 154 |
|
| 155 | +shared_optional_dtypes = shared(none() | shared_dtypes, key="optional_dtype") |
| 156 | + |
| 157 | +@composite |
| 158 | +def fill_value(draw): |
| 159 | + dtype = draw(shared_optional_dtypes) |
| 160 | + if dtype is None: |
| 161 | + dtype = draw(shared_dtypes) |
| 162 | + return draw(xps.from_dtype(dtype)) |
| 163 | + |
155 | 164 | @given(
|
156 |
| - a=xps.arrays( |
157 |
| - dtype=shared_dtypes, |
158 |
| - shape=shapes, |
159 |
| - ), |
160 |
| - fill_value=promotable_dtypes(shared_dtypes).flatmap(xps.from_dtype), |
161 |
| - dtype=shared_optional_promotable_dtypes, |
| 165 | + x=xps.arrays(dtype=shared_dtypes, shape=shapes), |
| 166 | + fill_value=fill_value(), |
| 167 | + dtype=shared_optional_dtypes, |
162 | 168 | )
|
163 |
| -def test_full_like(a, fill_value, dtype): |
| 169 | +def test_full_like(x, fill_value, dtype): |
164 | 170 | kwargs = {} if dtype is None else {'dtype': dtype}
|
165 | 171 |
|
166 |
| - a_like = full_like(a, fill_value, **kwargs) |
| 172 | + x_like = full_like(x, fill_value, **kwargs) |
167 | 173 |
|
168 | 174 | if dtype is None:
|
169 | 175 | # TODO: Should it actually match a.dtype?
|
170 | 176 | pass
|
171 | 177 | else:
|
172 |
| - assert a_like.dtype == dtype |
| 178 | + assert x_like.dtype == dtype |
173 | 179 |
|
174 |
| - assert a_like.shape == a.shape, "full_like() produced an array with incorrect shape" |
175 |
| - if is_float_dtype(a_like.dtype) and isnan(asarray(fill_value)): |
176 |
| - assert all(isnan(a_like)), "full_like() array did not equal the fill value" |
| 180 | + assert x_like.shape == x.shape, "full_like() produced an array with incorrect shape" |
| 181 | + if is_float_dtype(x_like.dtype) and isnan(asarray(fill_value)): |
| 182 | + assert all(isnan(x_like)), "full_like() array did not equal the fill value" |
177 | 183 | else:
|
178 |
| - assert all(equal(a_like, asarray(fill_value, dtype=a_like.dtype))), "full_like() array did not equal the fill value" |
| 184 | + assert all(equal(x_like, asarray(fill_value, dtype=x_like.dtype))), "full_like() array did not equal the fill value" |
179 | 185 |
|
180 | 186 |
|
181 | 187 | @given(scalars(shared_dtypes, finite=True),
|
|
0 commit comments