Skip to content

Commit 014d676

Browse files
committed
FIX: Cast scaling parameters only when safe
1 parent c238441 commit 014d676

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

nibabel/arrayproxy.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,13 @@ def _get_scaled(self, dtype, slicer):
360360
scl_slope = np.asanyarray(self._slope)
361361
scl_inter = np.asanyarray(self._inter)
362362
use_dtype = scl_slope.dtype if dtype is None else dtype
363-
slope = scl_slope.astype(use_dtype)
364-
inter = scl_inter.astype(use_dtype)
363+
364+
if np.can_cast(scl_slope, use_dtype):
365+
scl_slope = scl_slope.astype(use_dtype)
366+
if np.can_cast(scl_inter, use_dtype):
367+
scl_inter = scl_inter.astype(use_dtype)
365368
# Read array and upcast as necessary for big slopes, intercepts
366-
scaled = apply_read_scaling(self._get_unscaled(slicer=slicer), slope, inter)
369+
scaled = apply_read_scaling(self._get_unscaled(slicer=slicer), scl_slope, scl_inter)
367370
if dtype is not None:
368371
scaled = scaled.astype(np.promote_types(scaled.dtype, dtype), copy=False)
369372
return scaled

0 commit comments

Comments
 (0)