Skip to content

Commit 6df4a95

Browse files
committed
FIX: Disable direct creation of non-conformant GiftiDataArrays
1 parent b8b57cc commit 6df4a95

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

nibabel/gifti/gifti.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,21 @@ def __init__(
460460
self.data = None if data is None else np.asarray(data)
461461
self.intent = intent_codes.code[intent]
462462
if datatype is None:
463-
datatype = 'none' if self.data is None else self.data.dtype
463+
if self.data is None:
464+
datatype = 'none'
465+
elif self.data.dtype in (
466+
np.dtype('uint8'),
467+
np.dtype('int32'),
468+
np.dtype('float32'),
469+
):
470+
datatype = self.data.dtype
471+
else:
472+
raise ValueError(
473+
f'Data array has type {self.data.dtype}. '
474+
'The GIFTI standard only supports uint8, int32 and float32 arrays.\n'
475+
'Explicitly cast the data array to a supported dtype or pass an '
476+
'explicit "datatype" parameter to GiftiDataArray().'
477+
)
464478
self.datatype = data_type_codes.code[datatype]
465479
self.encoding = gifti_encoding_codes.code[encoding]
466480
self.endian = gifti_endian_codes.code[endian]

0 commit comments

Comments
 (0)