File tree 2 files changed +3
-32
lines changed
2 files changed +3
-32
lines changed Original file line number Diff line number Diff line change 16
16
17
17
import numpy as np
18
18
19
- @contextmanager
20
- def allow_array ():
21
- """
22
- Temporarily enable Array.__array__. This is needed for np.array to parse
23
- list of lists of Array objects.
24
- """
25
- from . import _array_object
26
- original_value = _array_object ._allow_array
27
- try :
28
- _array_object ._allow_array = True
29
- yield
30
- finally :
31
- _array_object ._allow_array = original_value
32
19
33
20
def _check_valid_dtype (dtype ):
34
21
# Note: Only spelling dtypes as the dtype objects is supported.
@@ -112,8 +99,8 @@ def asarray(
112
99
# Give a better error message in this case. NumPy would convert this
113
100
# to an object array. TODO: This won't handle large integers in lists.
114
101
raise OverflowError ("Integer out of bounds for array dtypes" )
115
- with allow_array ():
116
- res = np .array (obj , dtype = _np_dtype , copy = copy )
102
+
103
+ res = np .array (obj , dtype = _np_dtype , copy = copy )
117
104
return Array ._new (res , device = device )
118
105
119
106
Original file line number Diff line number Diff line change @@ -361,25 +361,9 @@ def test_array_conversion():
361
361
362
362
for device in ("device1" , "device2" ):
363
363
a = ones ((2 , 3 ), device = array_api_strict .Device (device ))
364
- with pytest .raises (RuntimeError , match = "Can not convert array" ):
364
+ with pytest .raises (( RuntimeError , TypeError ) ):
365
365
asarray ([a ])
366
366
367
- def test__array__ ():
368
- # __array__ should work for now
369
- a = ones ((2 , 3 ))
370
- np .array (a )
371
-
372
- # Test the _allow_array private global flag for disabling it in the
373
- # future.
374
- from .. import _array_object
375
- original_value = _array_object ._allow_array
376
- try :
377
- _array_object ._allow_array = False
378
- a = ones ((2 , 3 ))
379
- with pytest .raises (ValueError , match = "Conversion from an array_api_strict array to a NumPy ndarray is not supported" ):
380
- np .array (a )
381
- finally :
382
- _array_object ._allow_array = original_value
383
367
384
368
def test_allow_newaxis ():
385
369
a = ones (5 )
You can’t perform that action at this time.
0 commit comments