@@ -67,7 +67,7 @@ def test_init():
67
67
dtype = np .int32
68
68
arr = np .arange (24 , dtype = dtype ).reshape (shape )
69
69
bio .seek (16 )
70
- bio .write (arr .tostring (order = 'F' ))
70
+ bio .write (arr .tobytes (order = 'F' ))
71
71
hdr = FunkyHeader (shape )
72
72
ap = ArrayProxy (bio , hdr )
73
73
assert_true (ap .file_like is bio )
@@ -84,7 +84,7 @@ def test_init():
84
84
# C order also possible
85
85
bio = BytesIO ()
86
86
bio .seek (16 )
87
- bio .write (arr .tostring (order = 'C' ))
87
+ bio .write (arr .tobytes (order = 'C' ))
88
88
ap = CArrayProxy (bio , FunkyHeader ((2 , 3 , 4 )))
89
89
assert_array_equal (np .asarray (ap ), arr )
90
90
# Illegal init
@@ -97,7 +97,7 @@ def test_tuplespec():
97
97
dtype = np .int32
98
98
arr = np .arange (24 , dtype = dtype ).reshape (shape )
99
99
bio .seek (16 )
100
- bio .write (arr .tostring (order = 'F' ))
100
+ bio .write (arr .tobytes (order = 'F' ))
101
101
# Create equivalent header and tuple specs
102
102
hdr = FunkyHeader (shape )
103
103
tuple_spec = (hdr .get_data_shape (), hdr .get_data_dtype (),
@@ -125,7 +125,7 @@ def write_raw_data(arr, hdr, fileobj):
125
125
hdr .set_data_shape (arr .shape )
126
126
hdr .set_data_dtype (arr .dtype )
127
127
fileobj .write (b'\x00 ' * hdr .get_data_offset ())
128
- fileobj .write (arr .tostring (order = 'F' ))
128
+ fileobj .write (arr .tobytes (order = 'F' ))
129
129
130
130
131
131
def test_nifti1_init ():
@@ -163,15 +163,15 @@ def test_proxy_slicing():
163
163
for order , klass in ('F' , ArrayProxy ), ('C' , CArrayProxy ):
164
164
fobj = BytesIO ()
165
165
fobj .write (b'\0 ' * offset )
166
- fobj .write (arr .tostring (order = order ))
166
+ fobj .write (arr .tobytes (order = order ))
167
167
prox = klass (fobj , hdr )
168
168
for sliceobj in slicer_samples (shape ):
169
169
assert_array_equal (arr [sliceobj ], prox [sliceobj ])
170
170
# Check slicing works with scaling
171
171
hdr .set_slope_inter (2.0 , 1.0 )
172
172
fobj = BytesIO ()
173
173
fobj .write (b'\0 ' * offset )
174
- fobj .write (arr .tostring (order = 'F' ))
174
+ fobj .write (arr .tobytes (order = 'F' ))
175
175
prox = ArrayProxy (fobj , hdr )
176
176
sliceobj = (None , slice (None ), 1 , - 1 )
177
177
assert_array_equal (arr [sliceobj ] * 2.0 + 1.0 , prox [sliceobj ])
@@ -199,7 +199,7 @@ def test_reshape_dataobj():
199
199
bio = BytesIO ()
200
200
prox = ArrayProxy (bio , hdr )
201
201
arr = np .arange (np .prod (shape ), dtype = prox .dtype ).reshape (shape )
202
- bio .write (b'\x00 ' * prox .offset + arr .tostring (order = 'F' ))
202
+ bio .write (b'\x00 ' * prox .offset + arr .tobytes (order = 'F' ))
203
203
assert_array_equal (prox , arr )
204
204
assert_array_equal (reshape_dataobj (prox , (2 , 3 , 4 )),
205
205
np .reshape (arr , (2 , 3 , 4 )))
@@ -245,7 +245,7 @@ def get_slope_inter(self):
245
245
# Check standard read works
246
246
arr = np .arange (24 , dtype = np .int32 ).reshape (shape , order = 'F' )
247
247
bio .write (b'\x00 ' * hdr .get_data_offset ())
248
- bio .write (arr .tostring (order = 'F' ))
248
+ bio .write (arr .tobytes (order = 'F' ))
249
249
prox = ArrayProxy (bio , hdr )
250
250
assert_array_almost_equal (np .array (prox ), arr * 2.1 + 3.14 )
251
251
# Check unscaled read works
@@ -294,7 +294,7 @@ def check_mmap(hdr, offset, proxy_class,
294
294
with InTemporaryDirectory ():
295
295
with open (fname , 'wb' ) as fobj :
296
296
fobj .write (b' ' * offset )
297
- fobj .write (arr .tostring (order = 'F' ))
297
+ fobj .write (arr .tobytes (order = 'F' ))
298
298
for mmap , expected_mode in (
299
299
# mmap value, expected memmap mode
300
300
# mmap=None -> no mmap value
@@ -405,10 +405,10 @@ def test_keep_file_open_true_false_invalid():
405
405
# create the test data file
406
406
if filetype == 'gz' :
407
407
with gzip .open (fname , 'wb' ) as fobj :
408
- fobj .write (data .tostring (order = 'F' ))
408
+ fobj .write (data .tobytes (order = 'F' ))
409
409
else :
410
410
with open (fname , 'wb' ) as fobj :
411
- fobj .write (data .tostring (order = 'F' ))
411
+ fobj .write (data .tobytes (order = 'F' ))
412
412
# pass in a file name or open file handle. If the latter, we open
413
413
# two file handles, because we're going to create two proxies
414
414
# below.
@@ -459,7 +459,7 @@ def test_keep_file_open_true_false_invalid():
459
459
with InTemporaryDirectory ():
460
460
fname = 'testdata'
461
461
with open (fname , 'wb' ) as fobj :
462
- fobj .write (data .tostring (order = 'F' ))
462
+ fobj .write (data .tobytes (order = 'F' ))
463
463
464
464
for invalid_kfo in (55 , 'auto' , 'cauto' ):
465
465
with assert_raises (ValueError ):
0 commit comments