to_typed_array_spec encodes bdata in host byte order; plotly.js always decodes it as little-endian
Maintainer thường phản hồi trong vòng 3 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 79/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- numpy, python
- Lĩnh vực
- backend, data-visualization
Hướng nghiên cứu
Bắt đầu tại _plotly_utils/utils.py, ở to_typed_array_spec (khoảng dòng 84), rồi theo dõi cách dtype của mảng được chọn và các byte của nó được mã hóa. Kiểm tra hành vi với các mảng little-endian và big-endian, bao gồm cả ví dụ tái hiện được cung cấp. Hoàn thành khi dữ liệu đã mã hóa được giải mã theo little-endian thành các giá trị số ban đầu và có kiểm thử hồi quy bao quát trường hợp được báo cáo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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;
- Ngôn ngữ chính
- Python
- Star
- 18.9k
- Fork
- 2.9k
- Merge trung bình
- 5 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 14
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của plotly/plotly.py
-
[BUG]: NaT inside a datetime64 array serializes as the string "NaT" instead of nullCó thể đã có người làm @senanurcetin đã nhận 2 ngày trước. Đang mởbug P3 size: 1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
plotly/plotly.py#5829 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[BUG]: Integer and string properties reject NumPy scalarsCó thể đã có người làm @RaphaelFakhri đã nhận 4 ngày trước. Đang mởbug P3 size: 1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
plotly/plotly.py#5827 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[BUG]: Single-color requests raise ZeroDivisionError in palette helpersCó thể đã có người làm @MokiMeow đã nhận 13 ngày trước. Đang mởbug P3 size: 1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
plotly/plotly.py#5805 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[BUG]: Unnecessary `UserWarning` when using `fig.write_image()` with `kaleido.start_sync_server()`Có thể đã có người làm @jayzhou2309 đã nhận 21 ngày trước. Đang mởbug P3 size: 1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
plotly/plotly.py#5786 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
P3 size: 1 task
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
plotly/plotly.py#5769 · 1 reaction ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của plotly/plotly.py
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
MISP/misp-workbench#496 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
fossasia/visdom-dev#69 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[Bug] Parameters named like a property break to_xcal()Có thể đã có người làm @atharvasalunke1267 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
collective/icalendar#2018 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày