Skip to content

Commit 590ce4f

Browse files
committed
do not convert to in32 when not in bounds
1 parent 5902656 commit 590ce4f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

test/image/convert_b64.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
'float64': 'f8'
1414
}
1515

16+
int32bounds = numpy.iinfo(numpy.int32)
17+
uint32bounds = numpy.iinfo(numpy.uint32)
18+
1619
# List mainly including keys with type of 'info_array'
1720
# Simply having two items the b64 option is not supported by plotly.js
1821
# This list also includes cases of type 'any' that we don't to be converted
@@ -73,8 +76,16 @@ def arraysToB64(obj, newObj) :
7376

7477
# convert Big Ints until we could support them in plotly.js
7578
if str(arr.dtype) == 'int64' :
79+
if arr.max() > int32bounds.max or arr.min() < int32bounds.min :
80+
newObj[key] = val
81+
continue
82+
7683
arr = arr.astype(numpy.int32)
7784
elif str(arr.dtype) == 'uint64' :
85+
if arr.max() > uint32bounds.max or arr.min() < uint32bounds.min :
86+
newObj[key] = val
87+
continue
88+
7889
arr = arr.astype(numpy.uint32)
7990

8091
if str(arr.dtype) in plotlyjsTypes :

0 commit comments

Comments
 (0)