MCPcopy Index your code
hub / github.com/plotly/plotly.js / arraysToB64

Function arraysToB64

test/image/convert_b64.py:28–105  ·  view source on GitHub ↗
(obj, newObj)

Source from the content-addressed store, hash-verified

26]
27
28def arraysToB64(obj, newObj) :
29 for key, val in obj.items() :
30 if key in skipKeys :
31 newObj[key] = val
32 elif isinstance(val, dict) :
33 newObj[key] = dict()
34 arraysToB64(val, newObj[key])
35 elif isinstance(val, list) :
36 try :
37 arr = numpy.array(val)
38 except Exception :
39 newObj[key] = val
40 continue
41
42 if arr.dtype == 'object' :
43 newList = list()
44 for v in val :
45 if isinstance(v, dict) :
46 newList.append(arraysToB64(v, dict()))
47 else :
48 newList.append(v)
49
50 newObj[key] = newList
51 else :
52 # In a real application one does not need to convert
53 # small arrays like those that only have 2 items.
54 # But here we convert 2 item array to test typed arrays
55 # in more places.
56
57 # skip converting arrays with no items
58 if(arr.ndim == 1 and arr.shape[0] < 1) :
59 newObj[key] = val
60 continue
61
62 # convert default Big Ints until we could support them in plotly.js
63 if str(arr.dtype) == 'int64' :
64 max = arr.max()
65 min = arr.min()
66 if max <= int8bounds.max and min >= int8bounds.min :
67 arr = arr.astype(numpy.int8)
68 elif max <= int16bounds.max and min >= int16bounds.min :
69 arr = arr.astype(numpy.int16)
70 elif max <= int32bounds.max and min >= int32bounds.min :
71 arr = arr.astype(numpy.int32)
72 else :
73 newObj[key] = val
74 continue
75
76 elif str(arr.dtype) == 'uint64' :
77 if max <= uint8bounds.max and min >= uint8bounds.min :
78 arr = arr.astype(numpy.uint8)
79 elif max <= uint16bounds.max and min >= uint16bounds.min :
80 arr = arr.astype(numpy.uint16)
81 elif max <= uint32bounds.max and min >= uint32bounds.min :
82 arr = arr.astype(numpy.uint32)
83 else :
84 newObj[key] = val
85 continue

Callers 2

make_baselines_asyncFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…