2
2
from itertools import count
3
3
from typing import Iterator , NamedTuple , Union
4
4
5
- from hypothesis import assume , given
5
+ from hypothesis import assume , given , note
6
6
from hypothesis import strategies as st
7
7
8
8
from . import _array_module as xp
@@ -214,15 +214,16 @@ def test_asarray_scalars(shape, data):
214
214
elements_strat = xps .from_dtype (_dtype )
215
215
size = math .prod (shape )
216
216
obj_strat = st .lists (elements_strat , min_size = size , max_size = size )
217
+ scalar_type = dh .get_scalar_type (_dtype )
217
218
if dtype is None :
218
219
# For asarray to infer the dtype we're testing, obj requires at least
219
220
# one element to be the scalar equivalent of the inferred dtype, and so
220
221
# we filter out invalid examples. Note we use type() as Python booleans
221
222
# instance check with ints e.g. isinstance(False, int) == True.
222
- scalar_type = dh .get_scalar_type (_dtype )
223
223
obj_strat = obj_strat .filter (lambda l : any (type (e ) == scalar_type for e in l ))
224
- obj_strat = obj_strat .map (lambda l : sh .reshape (l , shape ))
225
- obj = data .draw (obj_strat , label = "obj" )
224
+ _obj = data .draw (obj_strat , label = "_obj" )
225
+ obj = sh .reshape (_obj , shape )
226
+ note (f"{ obj = } " )
226
227
227
228
out = xp .asarray (obj , ** kw )
228
229
@@ -240,6 +241,9 @@ def test_asarray_scalars(shape, data):
240
241
assert kw ["dtype" ] == _dtype # sanity check
241
242
ph .assert_kw_dtype ("asarray" , _dtype , out .dtype )
242
243
ph .assert_shape ("asarray" , out .shape , shape )
244
+ for idx , v_expect in zip (sh .ndindex (out .shape ), _obj ):
245
+ v = scalar_type (out [idx ])
246
+ ph .assert_scalar_equals ("asarray" , scalar_type , idx , v , v_expect , ** kw )
243
247
244
248
245
249
# TODO: test asarray with arrays and copy (in a seperate method)
0 commit comments