You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
to_typed_array_spec encodes bdata in host byte order; plotly.js always decodes it as little-endian #5837
with no explicit byte-order normalization before encoding, so bdata follows whatever byte order the array's dtype naturally has, which for an array built without an explicit </> prefix is the host's native order.
plotly.js decodes bdata with new Float64Array(buffer), which always reads in the platform's native order, little-endian in every real browser. On a big-endian host, this means bdata ships bytes that no browser can read correctly.
Repro (confirmed on real big-endian hardware: z/OS/s390x, numpy 2.5.3)
Through the actual function, not just a standalone simulation:
importnumpyasnpfrom_plotly_utils.utilsimportto_typed_array_specv=np.array([1.1, 2.3, 3.5])
spec=to_typed_array_spec(v)
print(spec)
importbase64raw=base64.b64decode(spec["bdata"])
as_little=np.frombuffer(raw, dtype="<f8") # what plotly.js's Float64Array readsprint("decoded as browser Float64Array would read it:", as_little)
print("matches original:", np.array_equal(v, as_little))
Output:
{'dtype': 'f8', 'bdata': 'P/GZmZmZmZpAAmZmZmZmZkAMAAAAAAAA'}
decoded as browser Float64Array would read it: [-1.54234871e-180 1.90359857e+185 1.54938987e-320]
matches original: False
So any big-endian host produces charts with silently corrupted numeric data.
Suggested fix
Normalize v to little-endian before encoding, e.g. v = v.astype(v.dtype.newbyteorder("<")) immediately before the base64.b64encode(v) call. Verified this resolves it on the same hardware:
Activity