Skip to content

Commit 7f977c3

Browse files
committed
BF - set explicit dtype when creating test images
In commit 6501b44 I was creating images by passing in arrays of the default platform integer type. This is int64 for 64 bit platforms, and analyze images don't support int64. I set the dtype specifically to int16 which (currently) all images can support.
1 parent f6d1472 commit 7f977c3

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

nibabel/tests/test_spatialimages.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,25 +211,33 @@ def test_data_default(self):
211211
def test_data_shape(self):
212212
# Check shape correctly read
213213
img_klass = self.image_class
214-
img = img_klass(np.arange(4), np.eye(4))
214+
# Assumes all possible images support int16
215+
# See https://github.com/nipy/nibabel/issues/58
216+
arr = np.arange(4, dtype=np.int16)
217+
img = img_klass(arr, np.eye(4))
215218
assert_equal(img.shape, (4,))
216219
img = img_klass(np.zeros((2,3,4)), np.eye(4))
217220
assert_equal(img.shape, (2,3,4))
218221

219222
def test_str(self):
220223
# Check something comes back from string representation
221224
img_klass = self.image_class
222-
img = img_klass(np.arange(5), np.eye(4))
225+
# Assumes all possible images support int16
226+
# See https://github.com/nipy/nibabel/issues/58
227+
arr = np.arange(5, dtype=np.int16)
228+
img = img_klass(arr, np.eye(4))
223229
assert_true(len(str(img)) > 0)
224230
assert_equal(img.shape, (5,))
225-
img = img_klass(np.zeros((2,3,4)), np.eye(4))
231+
img = img_klass(np.zeros((2,3,4), dtype=np.int16), np.eye(4))
226232
assert_true(len(str(img)) > 0)
227233

228234
def test_get_shape(self):
229235
# Check there is a get_shape method
230236
# (it is deprecated)
231237
img_klass = self.image_class
232-
img = img_klass(np.arange(1), np.eye(4))
238+
# Assumes all possible images support int16
239+
# See https://github.com/nipy/nibabel/issues/58
240+
img = img_klass(np.arange(1, dtype=np.int16), np.eye(4))
233241
assert_equal(img.get_shape(), (1,))
234-
img = img_klass(np.zeros((2,3,4)), np.eye(4))
242+
img = img_klass(np.zeros((2,3,4), np.int16), np.eye(4))
235243
assert_equal(img.get_shape(), (2,3,4))

nibabel/tests/test_spm99analyze.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class TestSpm99AnalyzeImage(test_analyze.TestAnalyzeImage):
109109
def test_mat_read(self):
110110
# Test mat file reading and writing for the SPM analyze types
111111
img_klass = self.image_class
112-
arr = np.arange(24).reshape((2,3,4))
112+
arr = np.arange(24, dtype=np.int32).reshape((2,3,4))
113113
aff = np.diag([2,3,4,1]) # no LR flip in affine
114114
img = img_klass(arr, aff)
115115
fm = img.file_map

0 commit comments

Comments
 (0)