Skip to content

Commit e62597e

Browse files
committed
RF+TEST - make tests for present data explicit - thanks to Marc-Alexandre Cote
1 parent 5b732b9 commit e62597e

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

nibabel/nifti1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,9 @@ def write_to(self, fileobj):
553553
def get_best_affine(self):
554554
''' Select best of available transforms '''
555555
hdr = self._header_data
556-
if hdr['sform_code']:
556+
if hdr['sform_code'] != 0:
557557
return self.get_sform()
558-
if hdr['qform_code']:
558+
if hdr['qform_code'] != 0:
559559
return self.get_qform()
560560
return self.get_base_affine()
561561

nibabel/spatialimages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def get_data(self):
321321

322322
@property
323323
def shape(self):
324-
if self._data:
324+
if not self._data is None:
325325
return self._data.shape
326326

327327
def get_data_dtype(self):

nibabel/tests/test_spatialimages.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,12 @@ def test_data_default(self):
198198
header = hdr_klass()
199199
img = img_klass(data, affine, header)
200200
yield assert_equal(img.get_data_dtype(), np.dtype(np.float32))
201+
202+
def test_data_shape(self):
203+
# Check shape correctly read
204+
img_klass = self.image_class
205+
img = img_klass(None, np.eye(4))
206+
assert_true(img.shape is None)
207+
img = img_klass(np.zeros((2,3,4)), np.eye(4))
208+
assert_equal(img.shape, (2,3,4))
209+

0 commit comments

Comments
 (0)