12
12
'float64' : 'f8'
13
13
}
14
14
15
+ int8bounds = numpy .iinfo (numpy .int8 )
16
+ int16bounds = numpy .iinfo (numpy .int16 )
15
17
int32bounds = numpy .iinfo (numpy .int32 )
18
+ uint8bounds = numpy .iinfo (numpy .uint8 )
19
+ uint16bounds = numpy .iinfo (numpy .uint16 )
16
20
uint32bounds = numpy .iinfo (numpy .uint32 )
17
21
18
22
skipKeys = [
@@ -49,20 +53,31 @@ def arraysToB64(obj, newObj) :
49
53
newObj [key ] = val
50
54
continue
51
55
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
53
57
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 :
55
67
newObj [key ] = val
56
68
continue
57
69
58
- arr = arr .astype (numpy .int32 )
59
70
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 :
61
78
newObj [key ] = val
62
79
continue
63
80
64
- arr = arr .astype (numpy .uint32 )
65
-
66
81
if str (arr .dtype ) in plotlyjsShortTypes :
67
82
newObj [key ] = {
68
83
'dtype' : plotlyjsShortTypes [str (arr .dtype )],
@@ -73,7 +88,6 @@ def arraysToB64(obj, newObj) :
73
88
newObj [key ]['shape' ] = str (arr .shape )[1 :- 1 ]
74
89
75
90
#print(val)
76
- #print('____________________')
77
91
#print(newObj[key])
78
92
#print('____________________')
79
93
else :
0 commit comments