Skip to content

Commit 94febbc

Browse files
authored
Merge pull request #101 from ev-br/astype_complex_prohibit
ENH: prohibit astype(complex, not complex)
2 parents d086c61 + 8457354 commit 94febbc

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

array_api_strict/_data_type_functions.py

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ def astype(
4242

4343
if not copy and dtype == x.dtype:
4444
return x
45+
46+
if isdtype(x.dtype, 'complex floating') and not isdtype(dtype, 'complex floating'):
47+
raise TypeError(
48+
f'The Array API standard stipulates that casting {x.dtype} to {dtype} should not be permitted. '
49+
'array-api-strict thus prohibits this conversion.'
50+
)
51+
4552
return Array._new(x._array.astype(dtype=dtype._np_dtype, copy=copy), device=device)
4653

4754

0 commit comments

Comments
 (0)