22from itertools import count
33from typing import Iterator , NamedTuple , Union
44
5- from hypothesis import assume , given
5+ from hypothesis import assume , given , note
66from hypothesis import strategies as st
77
88from . import _array_module as xp
@@ -214,15 +214,16 @@ def test_asarray_scalars(shape, data):
214214 elements_strat = xps .from_dtype (_dtype )
215215 size = math .prod (shape )
216216 obj_strat = st .lists (elements_strat , min_size = size , max_size = size )
217+ scalar_type = dh .get_scalar_type (_dtype )
217218 if dtype is None :
218219 # For asarray to infer the dtype we're testing, obj requires at least
219220 # one element to be the scalar equivalent of the inferred dtype, and so
220221 # we filter out invalid examples. Note we use type() as Python booleans
221222 # instance check with ints e.g. isinstance(False, int) == True.
222- scalar_type = dh .get_scalar_type (_dtype )
223223 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 = } " )
226227
227228 out = xp .asarray (obj , ** kw )
228229
@@ -240,6 +241,9 @@ def test_asarray_scalars(shape, data):
240241 assert kw ["dtype" ] == _dtype # sanity check
241242 ph .assert_kw_dtype ("asarray" , _dtype , out .dtype )
242243 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 )
243247
244248
245249# TODO: test asarray with arrays and copy (in a seperate method)
0 commit comments