@@ -195,7 +195,7 @@ class DataLike(object):
195
195
shape = (3 ,)
196
196
197
197
def __array__ (self ):
198
- return np .arange (3 )
198
+ return np .arange (3 , dtype = np . int16 )
199
199
200
200
201
201
class TestSpatialImage (TestCase ):
@@ -249,8 +249,11 @@ def test_default_header(self):
249
249
def test_data_api (self ):
250
250
# Test minimal api data object can initialize
251
251
img = self .image_class (DataLike (), None )
252
- assert_array_equal (img .get_data (), np .arange (3 ))
253
- assert_equal (img .shape , (3 ,))
252
+ # Shape may be promoted to higher dimension, but may not reorder or
253
+ # change size
254
+ assert_array_equal (img .get_data ().flatten (), np .arange (3 ))
255
+ assert_equal (img .get_shape ()[:1 ], (3 ,))
256
+ assert_equal (np .prod (img .get_shape ()), 3 )
254
257
255
258
def check_dtypes (self , expected , actual ):
256
259
# Some images will want dtypes to be equal including endianness,
@@ -278,7 +281,10 @@ def test_data_shape(self):
278
281
# See https://github.com/nipy/nibabel/issues/58
279
282
arr = np .arange (4 , dtype = np .int16 )
280
283
img = img_klass (arr , np .eye (4 ))
281
- assert_equal (img .shape , (4 ,))
284
+ # Shape may be promoted to higher dimension, but may not reorder or
285
+ # change size
286
+ assert_equal (img .get_shape ()[:1 ], (4 ,))
287
+ assert_equal (np .prod (img .get_shape ()), 4 )
282
288
img = img_klass (np .zeros ((2 , 3 , 4 ), dtype = np .float32 ), np .eye (4 ))
283
289
assert_equal (img .shape , (2 , 3 , 4 ))
284
290
@@ -290,7 +296,10 @@ def test_str(self):
290
296
arr = np .arange (5 , dtype = np .int16 )
291
297
img = img_klass (arr , np .eye (4 ))
292
298
assert_true (len (str (img )) > 0 )
293
- assert_equal (img .shape , (5 ,))
299
+ # Shape may be promoted to higher dimension, but may not reorder or
300
+ # change size
301
+ assert_equal (img .shape [:1 ], (5 ,))
302
+ assert_equal (np .prod (img .shape ), 5 )
294
303
img = img_klass (np .zeros ((2 , 3 , 4 ), dtype = np .int16 ), np .eye (4 ))
295
304
assert_true (len (str (img )) > 0 )
296
305
@@ -302,7 +311,10 @@ def test_get_shape(self):
302
311
# See https://github.com/nipy/nibabel/issues/58
303
312
img = img_klass (np .arange (1 , dtype = np .int16 ), np .eye (4 ))
304
313
with suppress_warnings ():
305
- assert_equal (img .get_shape (), (1 ,))
314
+ # Shape may be promoted to higher dimension, but may not reorder or
315
+ # change size
316
+ assert_equal (img .get_shape ()[:1 ], (1 ,))
317
+ assert_equal (np .prod (img .get_shape ()), 1 )
306
318
img = img_klass (np .zeros ((2 , 3 , 4 ), np .int16 ), np .eye (4 ))
307
319
assert_equal (img .get_shape (), (2 , 3 , 4 ))
308
320
0 commit comments