From 84573542760b325ac96d3aa7bd696a4d2dd0f7cc Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Tue, 26 Nov 2024 16:09:39 +0200 Subject: [PATCH] ENH: prohibit astype(complex, not complex) --- array_api_strict/_data_type_functions.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/array_api_strict/_data_type_functions.py b/array_api_strict/_data_type_functions.py index 046dfc7..acd8967 100644 --- a/array_api_strict/_data_type_functions.py +++ b/array_api_strict/_data_type_functions.py @@ -42,6 +42,13 @@ def astype( if not copy and dtype == x.dtype: return x + + if isdtype(x.dtype, 'complex floating') and not isdtype(dtype, 'complex floating'): + raise TypeError( + f'The Array API standard stipulates that casting {x.dtype} to {dtype} should not be permitted. ' + 'array-api-strict thus prohibits this conversion.' + ) + return Array._new(x._array.astype(dtype=dtype._np_dtype, copy=copy), device=device)