Skip to content

Commit 3ff7421

Browse files
committed
ENH: Suppress warnings by passing more reasonable data types
1 parent 6789354 commit 3ff7421

File tree

5 files changed

+11
-12
lines changed

5 files changed

+11
-12
lines changed

nibabel/funcs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def squeeze_image(img):
3535
--------
3636
>>> import nibabel as nf
3737
>>> shape = (10,20,30,1,1)
38-
>>> data = np.arange(np.prod(shape)).reshape(shape)
38+
>>> data = np.arange(np.prod(shape), dtype='int32').reshape(shape)
3939
>>> affine = np.eye(4)
4040
>>> img = nf.Nifti1Image(data, affine)
4141
>>> img.shape == (10, 20, 30, 1, 1)
@@ -47,7 +47,7 @@ def squeeze_image(img):
4747
If the data are 3D then last dimensions of 1 are ignored
4848
4949
>>> shape = (10,1,1)
50-
>>> data = np.arange(np.prod(shape)).reshape(shape)
50+
>>> data = np.arange(np.prod(shape), dtype='int32').reshape(shape)
5151
>>> img = nf.ni1.Nifti1Image(data, affine)
5252
>>> img.shape == (10, 1, 1)
5353
True

nibabel/tests/test_filehandles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_multiload():
2626
# Make a tiny image, save, load many times. If we are leaking filehandles,
2727
# this will cause us to run out and generate an error
2828
N = SOFT_LIMIT + 100
29-
arr = np.arange(24).reshape((2, 3, 4))
29+
arr = np.arange(24, dtype='int32').reshape((2, 3, 4))
3030
img = Nifti1Image(arr, np.eye(4))
3131
imgs = []
3232
try:

nibabel/tests/test_funcs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ def test_concat():
5151
# second position.
5252
for data0_shape in all_shapes:
5353
data0_numel = np.asarray(data0_shape).prod()
54-
data0 = np.arange(data0_numel).reshape(data0_shape)
54+
data0 = np.arange(data0_numel, dtype='int32').reshape(data0_shape)
5555
img0_mem = Nifti1Image(data0, affine)
5656

5757
for data1_shape in all_shapes:
5858
data1_numel = np.asarray(data1_shape).prod()
59-
data1 = np.arange(data1_numel).reshape(data1_shape)
59+
data1 = np.arange(data1_numel, dtype='int32').reshape(data1_shape)
6060
img1_mem = Nifti1Image(data1, affine)
6161
img2_mem = Nifti1Image(data1, affine + 1) # bad affine
6262

nibabel/tests/test_processing.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def test_adapt_affine():
9797
@needs_scipy
9898
def test_resample_from_to(caplog):
9999
# Test resampling from image to image / image space
100-
data = np.arange(24).reshape((2, 3, 4))
100+
data = np.arange(24, dtype='int32').reshape((2, 3, 4))
101101
affine = np.diag([-4, 5, 6, 1])
102102
img = Nifti1Image(data, affine)
103103
img.header['descrip'] = 'red shirt image'
@@ -186,7 +186,7 @@ def test_resample_from_to(caplog):
186186
out = resample_from_to(img, (img_2d.shape, img_2d.affine))
187187
assert_array_equal(out.dataobj, data[:, :, 0])
188188
# 4D input and output also OK
189-
data_4d = np.arange(24 * 5).reshape((2, 3, 4, 5))
189+
data_4d = np.arange(24 * 5, dtype='int32').reshape((2, 3, 4, 5))
190190
img_4d = Nifti1Image(data_4d, affine)
191191
out = resample_from_to(img_4d, img_4d)
192192
assert_almost_equal(data_4d, out.dataobj)
@@ -202,7 +202,7 @@ def test_resample_from_to(caplog):
202202
def test_resample_to_output(caplog):
203203
# Test routine to sample iamges to output space
204204
# Image aligned to output axes - no-op
205-
data = np.arange(24).reshape((2, 3, 4))
205+
data = np.arange(24, dtype='int32').reshape((2, 3, 4))
206206
img = Nifti1Image(data, np.eye(4))
207207
# Check default resampling
208208
img2 = resample_to_output(img)
@@ -305,7 +305,7 @@ def test_resample_to_output(caplog):
305305
@needs_scipy
306306
def test_smooth_image(caplog):
307307
# Test image smoothing
308-
data = np.arange(24).reshape((2, 3, 4))
308+
data = np.arange(24, dtype='int32').reshape((2, 3, 4))
309309
aff = np.diag([-4, 5, 6, 1])
310310
img = Nifti1Image(data, aff)
311311
# Zero smoothing is no-op
@@ -332,7 +332,7 @@ def test_smooth_image(caplog):
332332
with pytest.raises(ValueError):
333333
smooth_image(img_2d, [8, 8, 8])
334334
# Isotropic in 4D has zero for last dimension in scalar case
335-
data_4d = np.arange(24 * 5).reshape((2, 3, 4, 5))
335+
data_4d = np.arange(24 * 5, dtype='int32').reshape((2, 3, 4, 5))
336336
img_4d = Nifti1Image(data_4d, aff)
337337
exp_out = spnd.gaussian_filter(data_4d, list(sd) + [0], mode='nearest')
338338
assert_array_equal(smooth_image(img_4d, 8).dataobj, exp_out)

nibabel/tests/test_round_trip.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717

1818

1919
def round_trip(arr, out_dtype):
20-
img = Nifti1Image(arr, np.eye(4))
20+
img = Nifti1Image(arr, np.eye(4), dtype=out_dtype)
2121
img.file_map['image'].fileobj = BytesIO()
22-
img.set_data_dtype(out_dtype)
2322
img.to_file_map()
2423
back = Nifti1Image.from_file_map(img.file_map)
2524
# Recover array and calculated scaling from array proxy object

0 commit comments

Comments
 (0)