From dd727065b2dfd1b4cd01557949a4a11ac4f48051 Mon Sep 17 00:00:00 2001 From: SK Date: Tue, 24 Nov 2026 19:37:32 +0000 Subject: [PATCH] Test that int64 arrays with negative values survive serialization to_typed_array_spec sends int64 arrays as the smallest integer type that holds both their min and max. No test pinned that a value below the int8 range keeps the array out of int8. Co-Authored-By: Claude Opus 5.5 --- tests/test_optional/test_graph_objs/test_numpy.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_optional/test_graph_objs/test_numpy.py b/tests/test_optional/test_graph_objs/test_numpy.py index a234dc47830..c62ed3930e5 100644 --- a/tests/test_optional/test_graph_objs/test_numpy.py +++ b/tests/test_optional/test_graph_objs/test_numpy.py @@ -1,3 +1,4 @@ +import base64 from datetime import datetime import numpy as np @@ -14,3 +15,13 @@ def test_np_ns_datetime(): assert isinstance(scatter.x[0], datetime) # x value should match original numpy value at microsecond precision assert x[0].astype("datetime64[us]").item() == scatter.x[0] + + +def test_np_int64_negative_values_survive_serialization(): + # int64 arrays are sent to plotly.js as a smaller integer type when their + # values fit; a value below the int8 range must not wrap around + y = np.array([-1000, 5], dtype="int64") + spec = go.Figure(go.Scatter(y=y)).to_dict()["data"][0]["y"] + + decoded = np.frombuffer(base64.b64decode(spec["bdata"]), dtype=spec["dtype"]) + assert decoded.tolist() == [-1000, 5]