Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

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

Offen Anfängerfreundlich
#5,837 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 3 Tagen

@Vikram12301 arbeitet bereits daran.

Seit 22.10.2026.

  • #5838 von @Vikram12301 — offen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
79/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
numpy, python

Rechercherichtung

Beginne in _plotly_utils/utils.py bei to_typed_array_spec (etwa bei Zeile 84) und verfolge, wie der dtype des Arrays ausgewählt und seine Bytes kodiert werden. Prüfe das Verhalten bei Arrays mit Little- und Big-Endian, einschließlich der bereitgestellten Reproduktion. Erledigt ist die Aufgabe, wenn die kodierten Daten als Little-Endian zu den ursprünglichen numerischen Werten dekodiert werden und ein Regressionstest den gemeldeten Fall abdeckt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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;

Vorherrschende Sprache
Python
Sterne
18.9k
Forks
2.9k
Ø Merge
5 T. 1 Std.
Gemergte PRs (30 T.)
14

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus plotly/plotly.py

Alle Issues in plotly/plotly.py

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.