Skip to content

Commit 86b0597

Browse files
committed
FIX: Preserve
1 parent 6ffea1b commit 86b0597

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

nibabel/nifti1.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,18 +2443,18 @@ def _get_analyze_compat_dtype(arr):
24432443
return np.dtype('int16' if arr.max() <= np.iinfo(np.int16).max else 'int32')
24442444

24452445
mn, mx = arr.min(), arr.max()
2446+
if np.can_cast(mn, np.int32) and np.can_cast(mx, np.int32):
2447+
return np.dtype('int32')
2448+
if np.can_cast(mn, np.float32) and np.can_cast(mx, np.float32):
2449+
return np.dtype('float32')
24462450
if isinstance(mn, int) and isinstance(mx, int):
24472451
info = np.finfo('int32')
24482452
if mn >= info.min and mx <= info.max:
24492453
return np.dtype('int32')
2450-
elif isinstance(mn, float) and isinstance(mx, float):
2454+
if isinstance(mn, float) and isinstance(mx, float):
24512455
info = np.finfo('float32')
24522456
if mn >= info.min and mx <= info.max:
24532457
return np.dtype('float32')
2454-
elif np.can_cast(mn, np.int32) and np.can_cast(mx, np.int32):
2455-
return np.dtype('int32')
2456-
elif np.can_cast(mn, np.float32) and np.can_cast(mx, np.float32):
2457-
return np.dtype('float32')
24582458

24592459
raise ValueError(
24602460
f'Cannot find analyze-compatible dtype for array with dtype={dtype} (min={mn}, max={mx})'

0 commit comments

Comments
 (0)