Skip to content

Commit a92c8ca

Browse files
committed
RF: read_annot reverted to returning str in python2, bytes in
python3. Docstring updated accordingly. write_annot correctly outputs string termination character.
1 parent 4fe2520 commit a92c8ca

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

nibabel/freesurfer/io.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,8 @@ def read_annot(filepath, orig_ids=False):
357357
to any label and orig_ids=False, its id will be set to -1.
358358
ctab : ndarray, shape (n_labels, 5)
359359
RGBA + label id colortable array.
360-
names : list of str
360+
names : list of str (python 2), list of bytes (python 3)
361361
The names of the labels. The length of the list is n_labels.
362-
363362
"""
364363
with open(filepath, "rb") as fobj:
365364
dt = _ANNOT_DT
@@ -391,9 +390,6 @@ def read_annot(filepath, orig_ids=False):
391390
# generate annotation values for each LUT entry
392391
ctab[:, [4]] = _pack_rgba(ctab[:, :4])
393392

394-
# make sure names are strings, not bytes
395-
names = [n.decode('ascii') for n in names]
396-
397393
if not orig_ids:
398394
ord = np.argsort(ctab[:, -1])
399395
mask = labels != 0
@@ -522,6 +518,7 @@ def write(num, dtype=dt):
522518
np.array([num]).astype(dtype).tofile(fobj)
523519

524520
def write_string(s):
521+
s = s.encode() + b'\00'
525522
write(len(s))
526523
write(s, dtype='|S%d' % len(s))
527524

0 commit comments

Comments
 (0)