Skip to content

Commit 9f2df66

Browse files
Bago AmirbekianBago Amirbekian
authored andcommitted
BF - fix RGB read issue + test
1 parent 78c7b7c commit 9f2df66

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

nibabel/analyze.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ def _chk_datatype(klass, hdr, fix=False):
828828
rep.problem_level = 40
829829
rep.problem_msg = 'data code %d not recognized' % code
830830
else:
831-
if dtype.type is np.void:
831+
if dtype.itemsize == 0:
832832
rep.problem_level = 40
833833
rep.problem_msg = 'data code %d not supported' % code
834834
else:

nibabel/tests/test_analyze.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ def test_log_checks(self):
114114
assert_equal(message, 'sizeof_hdr should be 348; '
115115
'set sizeof_hdr to 348')
116116
assert_raises(*raiser)
117+
# RGB datatype does not raise error
118+
hdr = HC()
119+
hdr.set_data_dtype('RGB')
120+
fhdr, message, raiser = self.log_chk(hdr, 0)
117121
# datatype not recognized
118122
hdr = HC()
119123
hdr['datatype'] = -1 # severity 40
@@ -194,14 +198,17 @@ def test_data_dtype(self):
194198
(8, np.int32),
195199
(16, np.float32),
196200
(32, np.complex64),
197-
(64, np.float64))
201+
(64, np.float64),
202+
(128, np.dtype([('R','u1'),
203+
('G', 'u1'),
204+
('B', 'u1')])))
198205
# and unsupported - here using some labels instead
199206
unsupported_types = (np.void, 'none', 'all', 0)
200207
hdr = self.header_class()
201208
for code, npt in supported_types:
202209
# Can set with code value, or numpy dtype, both return the
203210
# dtype as output on get
204-
hdr.set_data_dtype(npt)
211+
hdr.set_data_dtype(code)
205212
assert_equal(hdr.get_data_dtype(), npt)
206213
for inp in unsupported_types:
207214
assert_raises(HeaderDataError,

0 commit comments

Comments
 (0)