Skip to content

Test that int64 arrays with negative values survive serialization - #5905

Open
Trenyx wants to merge 1 commit into
plotly:mainfrom
Trenyx:test/int64-negative-values
Open

Trenyx wants to merge 1 commit into
plotly:mainfrom
Trenyx:test/int64-negative-values

Conversation

@Trenyx

@Trenyx Trenyx commented Nov 24, 2026

Copy link
Copy Markdown

Link to issue

No linked issue: this PR only adds a test.

Description of change

If the int64 downcast in to_typed_array_spec ever checked only the max, an array such as np.array([-1000, 5]) would be squeezed into int8 and wrap, so the chart would plot 24 instead of -1000 with no error, and no test would notice.

Tests only: one test (+10 lines, plus import base64) in tests/test_optional/test_graph_objs/test_numpy.py. No change to library code.

Demo

Not applicable (no behaviour change).

Testing strategy

The test builds go.Figure(go.Scatter(y=np.array([-1000, 5], dtype="int64"))), takes to_dict()["data"][0]["y"], decodes bdata with the dtype it reports, and checks the values read back as [-1000, 5]. It does not pin which integer type is chosen.

On main 52ae6233:

  • python -m pytest tests/test_optional/test_graph_objs/test_numpy.py: 2 passed.
  • ruff format and ruff check are clean on the file.
  • With the downcast condition changed to if max <= int8max: (the min >= int8min check dropped), this new test is the only one that fails ([24, 5] == [-1000, 5]); tests/test_core, tests/test_plotly_utils, tests/test_optional and tests/test_io show no other new failure.

Additional information (optional)

Tests only, so I did not add a changelog entry; the no-changelog label may be needed.

Guidelines

This test was written with Claude Code during a planted-bug run by SK @ Trenyx.

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 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant