@@ -195,6 +195,38 @@ def test_dataarray_init():
195195 assert gda (ext_offset = 12 ).ext_offset == 12
196196
197197
198+ @pytest .mark .parametrize ('label' , data_type_codes .value_set ('label' ))
199+ def test_dataarray_typing (label ):
200+ dtype = data_type_codes .dtype [label ]
201+ code = data_type_codes .code [label ]
202+ arr = np .zeros ((5 ,), dtype = dtype )
203+
204+ # Default interface: accept standards-conformant arrays, reject else
205+ if dtype in ('uint8' , 'int32' , 'float32' ):
206+ assert GiftiDataArray (arr ).datatype == code
207+ else :
208+ with pytest .raises (ValueError ):
209+ GiftiDataArray (arr )
210+
211+ # Explicit override - permit for now, may want to warn or eventually
212+ # error
213+ assert GiftiDataArray (arr , datatype = label ).datatype == code
214+ assert GiftiDataArray (arr , datatype = code ).datatype == code
215+ # Void is how we say we don't know how to do something, so it's not unique
216+ if dtype != np .dtype ('void' ):
217+ assert GiftiDataArray (arr , datatype = dtype ).datatype == code
218+
219+ # Side-load data array (as in parsing)
220+ # We will probably always want this to load legacy images, but it's
221+ # probably not ideal to make it easy to silently propagate nonconformant
222+ # arrays
223+ gda = GiftiDataArray ()
224+ gda .data = arr
225+ gda .datatype = data_type_codes .code [label ]
226+ assert gda .data .dtype == dtype
227+ assert gda .datatype == data_type_codes .code [label ]
228+
229+
198230def test_labeltable ():
199231 img = GiftiImage ()
200232 assert len (img .labeltable .labels ) == 0
0 commit comments