@@ -270,16 +270,21 @@ def _to_xml_element(self):
270
270
return DataTag (dataarray , encoding , datatype , ordering ).to_xml ()
271
271
272
272
273
- def _data_tag_element (dataarray , encoding , datatype , ordering ):
273
+ def _data_tag_element (dataarray , encoding , dtype , ordering ):
274
274
""" Creates data tag with given `encoding`, returns as XML element
275
275
"""
276
276
import zlib
277
- ord = array_index_order_codes .npcode [ordering ]
277
+ order = array_index_order_codes .npcode [ordering ]
278
278
enclabel = gifti_encoding_codes .label [encoding ]
279
279
if enclabel == 'ASCII' :
280
- da = _arr2txt (dataarray , datatype )
280
+ # XXX Accommodating data_tag API
281
+ # On removal (nibabel 4.0) drop str case
282
+ da = _arr2txt (dataarray , dtype if isinstance (dtype , str ) else KIND2FMT [dtype .kind ])
281
283
elif enclabel in ('B64BIN' , 'B64GZ' ):
282
- out = dataarray .tostring (ord )
284
+ # XXX Accommodating data_tag API - don't try to fix dtype
285
+ if isinstance (dtype , str ):
286
+ dtype = dataarray .dtype
287
+ out = np .asanyarray (dataarray , dtype ).tostring (order )
283
288
if enclabel == 'B64GZ' :
284
289
out = zlib .compress (out )
285
290
da = base64 .b64encode (out ).decode ()
@@ -462,11 +467,10 @@ def _to_xml_element(self):
462
467
if self .coordsys is not None :
463
468
data_array .append (self .coordsys ._to_xml_element ())
464
469
# write data array depending on the encoding
465
- dt_kind = data_type_codes .dtype [self .datatype ].kind
466
470
data_array .append (
467
471
_data_tag_element (self .data ,
468
472
gifti_encoding_codes .specs [self .encoding ],
469
- KIND2FMT [ dt_kind ],
473
+ data_type_codes . dtype [ self . datatype ],
470
474
self .ind_ord ))
471
475
472
476
return data_array
0 commit comments