@@ -658,20 +658,29 @@ def _get_unscaled(self, slicer):
658658 def _get_scaled (self , dtype , slicer ):
659659 raw_data = self ._get_unscaled (slicer )
660660 if self ._slice_scaling is None :
661- if dtype is None or raw_data . dtype >= np . dtype ( dtype ) :
661+ if dtype is None :
662662 return raw_data
663- return np .asanyarray (raw_data , dtype = dtype )
663+ final_type = np .promote_types (raw_data .dtype , dtype )
664+ return raw_data .astype (final_type , copy = False )
664665
665666 # Broadcast scaling to shape of original data
666667 slopes , inters = self ._slice_scaling
667668 fake_data = strided_scalar (self ._shape )
668669 _ , slopes , inters = np .broadcast_arrays (fake_data , slopes , inters )
669670
670- if dtype is None :
671- dtype = max (slopes .dtype , inters .dtype )
671+ final_type = np .result_type (raw_data , slopes , inters )
672+ if dtype is not None :
673+ final_type = np .promote_types (final_type , dtype )
674+
675+ slopes = slopes .astype (final_type )
676+ inters = inters .astype (final_type )
677+
678+ if slicer is not None :
679+ slopes = slopes [slicer ]
680+ inters = inters [slicer ]
672681
673682 # Slice scaling to give output shape
674- return raw_data * slopes . astype ( dtype )[ slicer ] + inters . astype ( dtype )[ slicer ]
683+ return raw_data * slopes + inters
675684
676685
677686 def get_scaled (self , dtype = None ):
0 commit comments