@@ -48,6 +48,9 @@ def asarray(
48
48
from ._array_object import Array , CPU_DEVICE
49
49
50
50
_check_valid_dtype (dtype )
51
+ _np_dtype = None
52
+ if dtype is not None :
53
+ _np_dtype = dtype ._np_dtype
51
54
if device not in [CPU_DEVICE , None ]:
52
55
raise ValueError (f"Unsupported device { device !r} " )
53
56
if copy in (False , np ._CopyMode .IF_NEEDED ):
@@ -57,15 +60,13 @@ def asarray(
57
60
if dtype is not None and obj .dtype != dtype :
58
61
copy = True
59
62
if copy in (True , np ._CopyMode .ALWAYS ):
60
- return Array ._new (np .array (obj ._array , copy = True , dtype = dtype ))
63
+ return Array ._new (np .array (obj ._array , copy = True , dtype = _np_dtype ))
61
64
return obj
62
65
if dtype is None and isinstance (obj , int ) and (obj > 2 ** 64 or obj < - (2 ** 63 )):
63
66
# Give a better error message in this case. NumPy would convert this
64
67
# to an object array. TODO: This won't handle large integers in lists.
65
68
raise OverflowError ("Integer out of bounds for array dtypes" )
66
- if dtype is not None :
67
- dtype = dtype ._np_dtype
68
- res = np .asarray (obj , dtype = dtype )
69
+ res = np .asarray (obj , dtype = _np_dtype )
69
70
return Array ._new (res )
70
71
71
72
0 commit comments