Skip to content

Commit 8061909

Browse files
committed
FIX: Avoid attempted coercion of str to dtype in comparison
1 parent 88480c6 commit 8061909

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

nibabel/nifti1.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,13 +2124,15 @@ def set_data_dtype(self, datatype):
21242124
>>> img.get_data_dtype() == np.dtype('int64')
21252125
True
21262126
"""
2127-
# Static aliases
2128-
if datatype == 'mask':
2129-
datatype = 'u1'
2130-
# Dynamic aliases
2131-
elif datatype in ('compat', 'smallest'):
2132-
self._dtype_alias = datatype
2133-
return
2127+
# Numpy dtype comparison can fail in odd ways, check for aliases only if str
2128+
if isinstance(datatype, str):
2129+
# Static aliases
2130+
if datatype == 'mask':
2131+
datatype = 'u1'
2132+
# Dynamic aliases
2133+
elif datatype in ('compat', 'smallest'):
2134+
self._dtype_alias = datatype
2135+
return
21342136

21352137
self._dtype_alias = None
21362138
super().set_data_dtype(datatype)

0 commit comments

Comments
 (0)