Skip to content

Commit e2f50b4

Browse files
committed
Merge remote-tracking branch 'upstream/maint/3.0.x'
2 parents 65d5fc6 + 80487b7 commit e2f50b4

28 files changed

+82
-83
lines changed

nibabel/analyze.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def data_to_fileobj(self, data, fileobj, rescale=True):
508508
>>> str_io = BytesIO()
509509
>>> data = np.arange(6).reshape(1,2,3)
510510
>>> hdr.data_to_fileobj(data, str_io)
511-
>>> data.astype(np.float64).tostring('F') == str_io.getvalue()
511+
>>> data.astype(np.float64).tobytes('F') == str_io.getvalue()
512512
True
513513
'''
514514
data = np.asanyarray(data)

nibabel/benchmarks/bench_fileslice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def run_slices(file_like, repeat=3, offset=0, order='F'):
4444
times_arr = np.zeros((n_dim, n_slicers))
4545
with ImageOpener(file_like, 'wb') as fobj:
4646
fobj.write(b'\0' * offset)
47-
fobj.write(arr.tostring(order=order))
47+
fobj.write(arr.tobytes(order=order))
4848
with ImageOpener(file_like, 'rb') as fobj:
4949
for i, L in enumerate(SHAPE):
5050
for j, slicer in enumerate(_slices_for_len(L)):

nibabel/dft.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ def as_png(self, index=None, scale_to_slice=True):
144144
max = data.max()
145145
data = data * 255 / (max - min)
146146
data = data.astype(numpy.uint8)
147-
im = frombytes('L', (self.rows, self.columns),
148-
data.tostring())
147+
im = frombytes('L', (self.rows, self.columns), data.tobytes())
149148

150149
s = BytesIO()
151150
im.save(s, 'PNG')
@@ -213,7 +212,7 @@ def as_nifti(self):
213212
s = BytesIO()
214213
hdr.write_to(s)
215214

216-
return s.getvalue() + data.tostring()
215+
return s.getvalue() + data.tobytes()
217216

218217
def nifti_size(self):
219218
return 352 + 2 * len(self.storage_instances) * self.columns * self.rows

nibabel/ecat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ def to_file_map(self, file_map=None):
979979

980980
# Write subheader
981981
subhdr = subheaders.subheaders[index]
982-
imgf.write(subhdr.tostring())
982+
imgf.write(subhdr.tobytes())
983983

984984
# Seek to the next image block
985985
pos = imgf.tell()

nibabel/externals/netcdf.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def flush(self):
421421
def _write(self):
422422
self.fp.seek(0)
423423
self.fp.write(b'CDF')
424-
self.fp.write(array(self.version_byte, '>b').tostring())
424+
self.fp.write(array(self.version_byte, '>b').tobytes())
425425

426426
# Write headers and data.
427427
self._write_numrecs()
@@ -531,7 +531,7 @@ def _write_var_data(self, name):
531531

532532
# Write data.
533533
if not var.isrec:
534-
self.fp.write(var.data.tostring())
534+
self.fp.write(var.data.tobytes())
535535
count = var.data.size * var.data.itemsize
536536
self._write_var_padding(var, var._vsize - count)
537537
else: # record variable
@@ -553,7 +553,7 @@ def _write_var_data(self, name):
553553
if not rec.shape and (rec.dtype.byteorder == '<' or
554554
(rec.dtype.byteorder == '=' and LITTLE_ENDIAN)):
555555
rec = rec.byteswap()
556-
self.fp.write(rec.tostring())
556+
self.fp.write(rec.tobytes())
557557
# Padding
558558
count = rec.size * rec.itemsize
559559
self._write_var_padding(var, var._vsize - count)
@@ -606,7 +606,7 @@ def _write_att_values(self, values):
606606
if not values.shape and (values.dtype.byteorder == '<' or
607607
(values.dtype.byteorder == '=' and LITTLE_ENDIAN)):
608608
values = values.byteswap()
609-
self.fp.write(values.tostring())
609+
self.fp.write(values.tobytes())
610610
count = values.size * values.itemsize
611611
self.fp.write(b'\x00' * (-count % 4)) # pad
612612

@@ -791,15 +791,15 @@ def _pack_begin(self, begin):
791791
self._pack_int64(begin)
792792

793793
def _pack_int(self, value):
794-
self.fp.write(array(value, '>i').tostring())
794+
self.fp.write(array(value, '>i').tobytes())
795795
_pack_int32 = _pack_int
796796

797797
def _unpack_int(self):
798798
return int(frombuffer(self.fp.read(4), '>i')[0])
799799
_unpack_int32 = _unpack_int
800800

801801
def _pack_int64(self, value):
802-
self.fp.write(array(value, '>q').tostring())
802+
self.fp.write(array(value, '>q').tobytes())
803803

804804
def _unpack_int64(self):
805805
return frombuffer(self.fp.read(8), '>q')[0]
@@ -1045,7 +1045,7 @@ def _get_encoded_fill_value(self):
10451045
"""
10461046
if '_FillValue' in self._attributes:
10471047
fill_value = np.array(self._attributes['_FillValue'],
1048-
dtype=self.data.dtype).tostring()
1048+
dtype=self.data.dtype).tobytes()
10491049
if len(fill_value) == self.itemsize():
10501050
return fill_value
10511051
else:

nibabel/freesurfer/io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ def _serialize_volume_info(volume_info):
613613
if not (np.array_equal(volume_info[key], [20]) or np.array_equal(
614614
volume_info[key], [2, 0, 20])):
615615
warnings.warn("Unknown extension code.")
616-
strings.append(np.array(volume_info[key], dtype='>i4').tostring())
616+
strings.append(np.array(volume_info[key], dtype='>i4').tobytes())
617617
elif key in ('valid', 'filename'):
618618
val = volume_info[key]
619619
strings.append('{0} = {1}\n'.format(key, val).encode('utf-8'))

nibabel/freesurfer/mghformat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def writehdr_to(self, fileobj):
406406
buffer=self.binaryblock)
407407
# goto the very beginning of the file-like obj
408408
fileobj.seek(0)
409-
fileobj.write(hdr_nofooter.tostring())
409+
fileobj.write(hdr_nofooter.tobytes())
410410

411411
def writeftr_to(self, fileobj):
412412
''' Write footer to fileobj
@@ -426,7 +426,7 @@ def writeftr_to(self, fileobj):
426426
ftr_nd = np.ndarray((), dtype=self._ftrdtype,
427427
buffer=self.binaryblock, offset=ftr_loc_in_hdr)
428428
fileobj.seek(self.get_footer_offset())
429-
fileobj.write(ftr_nd.tostring())
429+
fileobj.write(ftr_nd.tobytes())
430430

431431
def copy(self):
432432
''' Return copy of structure '''

nibabel/freesurfer/tests/test_io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def gen_old_annot_file(fpath, nverts, labels, rgba, names):
304304
# number of vertices
305305
fbytes += struct.pack(dt, nverts)
306306
# vertices + annotation values
307-
fbytes += bytes(vdata.astype(dt).tostring())
307+
fbytes += vdata.astype(dt).tobytes()
308308
# is there a colour table?
309309
fbytes += struct.pack(dt, 1)
310310
# number of entries in colour table
@@ -316,7 +316,7 @@ def gen_old_annot_file(fpath, nverts, labels, rgba, names):
316316
# length of entry name (+1 for terminating byte)
317317
fbytes += struct.pack(dt, len(names[i]) + 1)
318318
fbytes += names[i].encode('ascii') + b'\x00'
319-
fbytes += bytes(rgba[i, :].astype(dt).tostring())
319+
fbytes += rgba[i, :].astype(dt).tobytes()
320320
with open(fpath, 'wb') as f:
321321
f.write(fbytes)
322322
with InTemporaryDirectory():

nibabel/gifti/gifti.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def _data_tag_element(dataarray, encoding, dtype, ordering):
281281
# XXX Accommodating data_tag API - don't try to fix dtype
282282
if isinstance(dtype, str):
283283
dtype = dataarray.dtype
284-
out = np.asanyarray(dataarray, dtype).tostring(order)
284+
out = np.asanyarray(dataarray, dtype).tobytes(order)
285285
if enclabel == 'B64GZ':
286286
out = zlib.compress(out)
287287
da = base64.b64encode(out).decode()

nibabel/nicom/tests/test_dicomwrappers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ def test_data_real(self):
646646
# data hash depends on the endianness
647647
if endian_codes[data.dtype.byteorder] == '>':
648648
data = data.byteswap()
649-
dat_str = data.tostring()
649+
dat_str = data.tobytes()
650650
assert sha1(dat_str).hexdigest() == '149323269b0af92baa7508e19ca315240f77fa8c'
651651

652652
@dicom_test

0 commit comments

Comments
 (0)