@@ -66,7 +66,7 @@ def test_init():
66
66
dtype = np .int32
67
67
arr = np .arange (24 , dtype = dtype ).reshape (shape )
68
68
bio .seek (16 )
69
- bio .write (arr .tostring (order = 'F' ))
69
+ bio .write (arr .tobytes (order = 'F' ))
70
70
hdr = FunkyHeader (shape )
71
71
ap = ArrayProxy (bio , hdr )
72
72
assert 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
@@ -98,7 +98,7 @@ def test_tuplespec():
98
98
dtype = np .int32
99
99
arr = np .arange (24 , dtype = dtype ).reshape (shape )
100
100
bio .seek (16 )
101
- bio .write (arr .tostring (order = 'F' ))
101
+ bio .write (arr .tobytes (order = 'F' ))
102
102
# Create equivalent header and tuple specs
103
103
hdr = FunkyHeader (shape )
104
104
tuple_spec = (hdr .get_data_shape (), hdr .get_data_dtype (),
@@ -129,7 +129,7 @@ def write_raw_data(arr, hdr, fileobj):
129
129
hdr .set_data_shape (arr .shape )
130
130
hdr .set_data_dtype (arr .dtype )
131
131
fileobj .write (b'\x00 ' * hdr .get_data_offset ())
132
- fileobj .write (arr .tostring (order = 'F' ))
132
+ fileobj .write (arr .tobytes (order = 'F' ))
133
133
134
134
135
135
def test_nifti1_init ():
@@ -167,15 +167,15 @@ def test_proxy_slicing():
167
167
for order , klass in ('F' , ArrayProxy ), ('C' , CArrayProxy ):
168
168
fobj = BytesIO ()
169
169
fobj .write (b'\0 ' * offset )
170
- fobj .write (arr .tostring (order = order ))
170
+ fobj .write (arr .tobytes (order = order ))
171
171
prox = klass (fobj , hdr )
172
172
for sliceobj in slicer_samples (shape ):
173
173
assert_array_equal (arr [sliceobj ], prox [sliceobj ])
174
174
# Check slicing works with scaling
175
175
hdr .set_slope_inter (2.0 , 1.0 )
176
176
fobj = BytesIO ()
177
177
fobj .write (b'\0 ' * offset )
178
- fobj .write (arr .tostring (order = 'F' ))
178
+ fobj .write (arr .tobytes (order = 'F' ))
179
179
prox = ArrayProxy (fobj , hdr )
180
180
sliceobj = (None , slice (None ), 1 , - 1 )
181
181
assert_array_equal (arr [sliceobj ] * 2.0 + 1.0 , prox [sliceobj ])
@@ -203,7 +203,7 @@ def test_reshape_dataobj():
203
203
bio = BytesIO ()
204
204
prox = ArrayProxy (bio , hdr )
205
205
arr = np .arange (np .prod (shape ), dtype = prox .dtype ).reshape (shape )
206
- bio .write (b'\x00 ' * prox .offset + arr .tostring (order = 'F' ))
206
+ bio .write (b'\x00 ' * prox .offset + arr .tobytes (order = 'F' ))
207
207
assert_array_equal (prox , arr )
208
208
assert_array_equal (reshape_dataobj (prox , (2 , 3 , 4 )),
209
209
np .reshape (arr , (2 , 3 , 4 )))
@@ -252,7 +252,7 @@ def get_slope_inter(self):
252
252
# Check standard read works
253
253
arr = np .arange (24 , dtype = np .int32 ).reshape (shape , order = 'F' )
254
254
bio .write (b'\x00 ' * hdr .get_data_offset ())
255
- bio .write (arr .tostring (order = 'F' ))
255
+ bio .write (arr .tobytes (order = 'F' ))
256
256
prox = ArrayProxy (bio , hdr )
257
257
assert_array_almost_equal (np .array (prox ), arr * 2.1 + 3.14 )
258
258
# Check unscaled read works
@@ -301,7 +301,7 @@ def check_mmap(hdr, offset, proxy_class,
301
301
with InTemporaryDirectory ():
302
302
with open (fname , 'wb' ) as fobj :
303
303
fobj .write (b' ' * offset )
304
- fobj .write (arr .tostring (order = 'F' ))
304
+ fobj .write (arr .tobytes (order = 'F' ))
305
305
for mmap , expected_mode in (
306
306
# mmap value, expected memmap mode
307
307
# mmap=None -> no mmap value
@@ -413,10 +413,10 @@ def test_keep_file_open_true_false_invalid():
413
413
# create the test data file
414
414
if filetype == 'gz' :
415
415
with gzip .open (fname , 'wb' ) as fobj :
416
- fobj .write (data .tostring (order = 'F' ))
416
+ fobj .write (data .tobytes (order = 'F' ))
417
417
else :
418
418
with open (fname , 'wb' ) as fobj :
419
- fobj .write (data .tostring (order = 'F' ))
419
+ fobj .write (data .tobytes (order = 'F' ))
420
420
# pass in a file name or open file handle. If the latter, we open
421
421
# two file handles, because we're going to create two proxies
422
422
# below.
@@ -467,7 +467,7 @@ def test_keep_file_open_true_false_invalid():
467
467
with InTemporaryDirectory ():
468
468
fname = 'testdata'
469
469
with open (fname , 'wb' ) as fobj :
470
- fobj .write (data .tostring (order = 'F' ))
470
+ fobj .write (data .tobytes (order = 'F' ))
471
471
472
472
for invalid_kfo in (55 , 'auto' , 'cauto' ):
473
473
with pytest .raises (ValueError ):
0 commit comments