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