Skip to content

Commit 3c9918a

Browse files
committed
Merge remote-tracking branch 'origin/enh/cifti2' into enh/cifti2
* origin/enh/cifti2: BUG: Fixed string encoding for python 3
2 parents 4668e26 + ecc4892 commit 3c9918a

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

nibabel/cifti/cifti.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
1919
'''
2020
from __future__ import division, print_function, absolute_import
21+
from ..externals.six import string_types
2122

2223
import numpy as np
2324

@@ -81,7 +82,7 @@ def __init__(self, nvpair=None):
8182
def _add_remove_metadata(self, metadata, func):
8283
pairs = []
8384
if isinstance(metadata, (list, tuple)):
84-
if isinstance(metadata[0], basestring):
85+
if isinstance(metadata[0], string_types):
8586
if len(metadata) != 2:
8687
raise ValueError('nvpair must be a 2-list or 2-tuple')
8788
pairs = [tuple((metadata[0], metadata[1]))]
@@ -806,7 +807,7 @@ def to_filename(self, filename):
806807
from ..nifti1 import Nifti1Extension
807808
data = np.reshape(self.data, [1, 1, 1, 1] + list(self.data.shape))
808809
header = self.extra
809-
extension = Nifti1Extension(32, self.header.to_xml())
810+
extension = Nifti1Extension(32, self.header.to_xml().encode())
810811
header.extensions.append(extension)
811812
img = Nifti2Image(data, None, header)
812813
img.to_filename(filename)

nibabel/cifti/parse_cifti_fast.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from distutils.version import LooseVersion
1212

13-
from ..externals.six import StringIO
13+
from ..externals.six import BytesIO
1414
from xml.parsers.expat import ParserCreate, ExpatError
1515

1616
import numpy as np
@@ -306,25 +306,25 @@ def flush_chardata(self):
306306
pair[1] = data
307307
elif self.write_to == 'Vertices':
308308
# conversion to numpy array
309-
c = StringIO(data.strip().decode('utf-8'))
309+
c = BytesIO(data.strip().encode())
310310
vertices = self.struct_state[-1]
311311
vertices.vertices = np.genfromtxt(c, dtype=np.int)
312312
c.close()
313313
elif self.write_to == 'VoxelIndices':
314314
# conversion to numpy array
315-
c = StringIO(data.strip().decode('utf-8'))
315+
c = BytesIO(data.strip().encode())
316316
parent = self.struct_state[-1]
317317
parent.voxelIndicesIJK.indices = np.genfromtxt(c, dtype=np.int)
318318
c.close()
319319
elif self.write_to == 'VertexIndices':
320320
# conversion to numpy array
321-
c = StringIO(data.strip())
321+
c = BytesIO(data.strip().encode())
322322
index = self.struct_state[-1]
323323
index.indices = np.genfromtxt(c, dtype=np.int)
324324
c.close()
325325
elif self.write_to == 'TransformMatrix':
326326
# conversion to numpy array
327-
c = StringIO(data.strip())
327+
c = BytesIO(data.strip().encode())
328328
transform = self.struct_state[-1]
329329
transform.matrix = np.genfromtxt(c, dtype=np.float)
330330
c.close()

0 commit comments

Comments
 (0)