@@ -658,20 +658,29 @@ def _get_unscaled(self, slicer):
658
658
def _get_scaled (self , dtype , slicer ):
659
659
raw_data = self ._get_unscaled (slicer )
660
660
if self ._slice_scaling is None :
661
- if dtype is None or raw_data . dtype >= np . dtype ( dtype ) :
661
+ if dtype is None :
662
662
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 )
664
665
665
666
# Broadcast scaling to shape of original data
666
667
slopes , inters = self ._slice_scaling
667
668
fake_data = strided_scalar (self ._shape )
668
669
_ , slopes , inters = np .broadcast_arrays (fake_data , slopes , inters )
669
670
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 ]
672
681
673
682
# Slice scaling to give output shape
674
- return raw_data * slopes . astype ( dtype )[ slicer ] + inters . astype ( dtype )[ slicer ]
683
+ return raw_data * slopes + inters
675
684
676
685
677
686
def get_scaled (self , dtype = None ):
0 commit comments