1212 'float64' : 'f8'
1313}
1414
15+ int8bounds = numpy .iinfo (numpy .int8 )
16+ int16bounds = numpy .iinfo (numpy .int16 )
1517int32bounds = numpy .iinfo (numpy .int32 )
18+ uint8bounds = numpy .iinfo (numpy .uint8 )
19+ uint16bounds = numpy .iinfo (numpy .uint16 )
1620uint32bounds = numpy .iinfo (numpy .uint32 )
1721
1822skipKeys = [
@@ -49,20 +53,31 @@ def arraysToB64(obj, newObj) :
4953 newObj [key ] = val
5054 continue
5155
52- # convert Big Ints until we could support them in plotly.js
56+ # convert default Big Ints until we could support them in plotly.js
5357 if str (arr .dtype ) == 'int64' :
54- if arr .max () > int32bounds .max or arr .min () < int32bounds .min :
58+ max = arr .max ()
59+ min = arr .min ()
60+ if max <= int8bounds .max and min >= int8bounds .min :
61+ arr = arr .astype (numpy .int8 )
62+ elif max <= int16bounds .max and min >= int16bounds .min :
63+ arr = arr .astype (numpy .int16 )
64+ elif max <= int32bounds .max and min >= int32bounds .min :
65+ arr = arr .astype (numpy .int32 )
66+ else :
5567 newObj [key ] = val
5668 continue
5769
58- arr = arr .astype (numpy .int32 )
5970 elif str (arr .dtype ) == 'uint64' :
60- if arr .max () > uint32bounds .max or arr .min () < uint32bounds .min :
71+ if max <= uint8bounds .max and min >= uint8bounds .min :
72+ arr = arr .astype (numpy .uint8 )
73+ elif max <= uint16bounds .max and min >= uint16bounds .min :
74+ arr = arr .astype (numpy .uint16 )
75+ elif max <= uint32bounds .max and min >= uint32bounds .min :
76+ arr = arr .astype (numpy .uint32 )
77+ else :
6178 newObj [key ] = val
6279 continue
6380
64- arr = arr .astype (numpy .uint32 )
65-
6681 if str (arr .dtype ) in plotlyjsShortTypes :
6782 newObj [key ] = {
6883 'dtype' : plotlyjsShortTypes [str (arr .dtype )],
@@ -73,7 +88,6 @@ def arraysToB64(obj, newObj) :
7388 newObj [key ]['shape' ] = str (arr .shape )[1 :- 1 ]
7489
7590 #print(val)
76- #print('____________________')
7791 #print(newObj[key])
7892 #print('____________________')
7993 else :
0 commit comments