Skip to content

Commit 2398cc3

Browse files
author
Mathieu Scheltienne
committed
use combination of getattr and hasattr, include float96 and complex192 to the list
1 parent 4cdba01 commit 2398cc3

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

nibabel/casting.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,24 @@ class CastingError(Exception):
2525

2626
# np.sctypes is deprecated in numpy 2.0 and np.core.sctypes should not be used instead.
2727
sctypes = {
28-
'int': [np.int8, np.int16, np.int32, np.int64],
29-
'uint': [np.uint8, np.uint16, np.uint32, np.uint64],
30-
'float': [np.float16, np.float32, np.float64, np.longdouble],
31-
'complex': [np.complex64, np.complex128, np.complex256],
28+
'int': [
29+
getattr(np, dtype) for dtype in ('int8', 'int16', 'int32', 'int64') if hasattr(np, dtype)
30+
],
31+
'uint': [
32+
getattr(np, dtype)
33+
for dtype in ('uint8', 'uint16', 'uint32', 'uint64')
34+
if hasattr(np, dtype)
35+
],
36+
'float': [
37+
getattr(np, dtype)
38+
for dtype in ('float16', 'float32', 'float64', 'float96', 'float128')
39+
if hasattr(np, dtype)
40+
],
41+
'complex': [
42+
getattr(np, dtype)
43+
for dtype in ('complex64', 'complex128', 'complex192', 'complex256')
44+
if hasattr(np, dtype)
45+
],
3246
'others': [bool, object, bytes, str, np.void],
3347
}
3448

0 commit comments

Comments
 (0)