to_typed_array_spec encodes bdata in host byte order; plotly.js always decodes it as little-endian
维护者通常 3 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 79/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- numpy, python
调研方向
从 _plotly_utils/utils.py 中的 to_typed_array_spec(约第 84 行)开始,追踪数组 dtype 的选择方式以及字节的编码方式。检查 little endian 和 big endian 数组的行为,包括提供的复现示例。完成标准是:编码后的数据按 little-endian 解码后得到原始数值,并且有一个回归测试覆盖所报告的情况。
由索引模型根据 Issue 内容生成。
描述
Summary
to_typed_array_spec (_plotly_utils/utils.py:84) does:
arrObj = {
"dtype": plotlyjsShortTypes[dtype],
"bdata": base64.b64encode(v).decode("ascii"),
}
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:
import numpy as np
from _plotly_utils.utils import to_typed_array_spec
v = np.array([1.1, 2.3, 3.5])
spec = to_typed_array_spec(v)
print(spec)
import base64
raw = base64.b64decode(spec["bdata"])
as_little = np.frombuffer(raw, dtype="<f8") # what plotly.js's Float64Array reads
print("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:
v_fixed = v.astype(v.dtype.newbyteorder("<"))
bdata_fixed = base64.b64encode(v_fixed).decode("ascii")
raw_fixed = base64.b64decode(bdata_fixed)
as_little_fixed = np.frombuffer(raw_fixed, dtype="<f8")
print(np.array_equal(v, as_little_fixed)) # True
Originally spotted by @chrikrah in #5833;
- 主要语言
- Python
- 星标
- 18.9k
- 派生
- 2.9k
- 平均合并
- 5 天 1 小时
- 30 天内合并 PR
- 14
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
plotly/plotly.py 的其他 Issue
-
[BUG]: NaT inside a datetime64 array serializes as the string "NaT" instead of null可能已有人在做 @senanurcetin 于 2 天前认领。 未关闭bug P3 size: 1
难度 2/5 1-3 小时 新手友好度 82/100
plotly/plotly.py#5829 · 3 条评论 ·
维护者通常 3 天内回复
-
[BUG]: Integer and string properties reject NumPy scalars可能已有人在做 @RaphaelFakhri 于 4 天前认领。 未关闭bug P3 size: 1
难度 2/5 1-3 小时 新手友好度 70/100
plotly/plotly.py#5827 · 1 条评论 ·
维护者通常 3 天内回复
-
[BUG]: Single-color requests raise ZeroDivisionError in palette helpers可能已有人在做 @MokiMeow 于 13 天前认领。 未关闭bug P3 size: 1
难度 2/5 1-3 小时 新手友好度 82/100
plotly/plotly.py#5805 · 1 条评论 ·
维护者通常 3 天内回复
-
[BUG]: Unnecessary `UserWarning` when using `fig.write_image()` with `kaleido.start_sync_server()`可能已有人在做 @jayzhou2309 于 21 天前认领。 未关闭bug P3 size: 1
难度 2/5 1-3 小时 新手友好度 74/100
plotly/plotly.py#5786 · 1 条评论 ·
维护者通常 3 天内回复
-
P3 size: 1 task
难度 2/5 1-3 小时 新手友好度 65/100
plotly/plotly.py#5769 · 1 个 reaction ·
维护者通常 3 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
aws-samples/sample-per-model-bedrock#464 ·
维护者通常 1 天内回复
-
lesson-submission pending-review
难度 2/5 1-3 小时 新手友好度 67/100
Ikalus1988/MisakaNet#3789 ·
维护者通常 1 天内回复
-
Python Volcengine provider returns failures instead of raising them可能已有人在做 @Ricardo-M-L 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 79/100
agent-infra/sandbox#248 ·
-
[Bug] cloud JSON directory loading assumes a Key field in fsspec listings可能已有人在做 @Ricardo-M-L 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
hiyouga/LlamaFactory#10910 ·
维护者通常 1 天内回复
-
Bundled uv is never updated and trusts the compromised eMudhra certificates可能已有人在做 @FabienDanieau 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 76/100