Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

to_typed_array_spec encodes bdata in host byte order; plotly.js always decodes it as little-endian

Đang mở Phù hợp với người mới
#5,837 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

@Vikram12301 đang làm issue này rồi.

Từ ngày 22/10/2026.

  • #5838 của @Vikram12301 — đang mở

Đá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

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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của plotly/plotly.py

Tất cả issue của plotly/plotly.py

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.