Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/test_optional/test_graph_objs/test_numpy.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
from datetime import datetime

import numpy as np
Expand All @@ -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]