Skip to content

1.3 serialization regression: calc_fig fails on numbers outside 64-bit range #467

Description

@emilykl

Kaleido().calc_fig() fails when figure contains numbers outside the 64-bit range, which in practice seems to be anything equal to or greater than 2**64.

This seems to be due to an orjson limitation, and the same figure does not fail in Kaleido v1.2.

Steps to reproduce:

Run the following code with Kaleido 1.3 installed:

import plotly.express as px
fig = px.scatter(x=[1], y=[2**64])
fig.write_image(file="test.png")

Stack trace:

Traceback (most recent call last):
  File "/Users/ekl/code/plotly.js/64bit-bug.py", line 3, in <module>
    fig.write_image(file="test.png")
  File "/Users/ekl/code/plotly.js/venv/plotly.js/lib/python3.12/site-packages/plotly/basedatatypes.py", line 3895, in write_image
    return pio.write_image(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ekl/code/plotly.js/venv/plotly.js/lib/python3.12/site-packages/plotly/io/_kaleido.py", line 530, in write_image
    img_data = to_image(
               ^^^^^^^^^
  File "/Users/ekl/code/plotly.js/venv/plotly.js/lib/python3.12/site-packages/plotly/io/_kaleido.py", line 400, in to_image
    img_bytes = kaleido.calc_fig_sync(
                ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ekl/code/plotly.js/venv/plotly.js/lib/python3.12/site-packages/kaleido/__init__.py", line 170, in calc_fig_sync
    return _sync_server.oneshot_async_run(calc_fig, args=args, kwargs=kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ekl/code/plotly.js/venv/plotly.js/lib/python3.12/site-packages/kaleido/_sync_server.py", line 161, in oneshot_async_run
    raise res
  File "/Users/ekl/code/plotly.js/venv/plotly.js/lib/python3.12/site-packages/kaleido/_sync_server.py", line 152, in run
    q.put(asyncio.run(func(*args, **kwargs)))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.9/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.9/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.9/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/ekl/code/plotly.js/venv/plotly.js/lib/python3.12/site-packages/kaleido/__init__.py", line 104, in calc_fig
    return await k.calc_fig(
           ^^^^^^^^^^^^^^^^^
  File "/Users/ekl/code/plotly.js/venv/plotly.js/lib/python3.12/site-packages/kaleido/kaleido.py", line 618, in calc_fig
    return await self.write_fig_from_object(  # type: ignore[reportCallIssue]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ekl/code/plotly.js/venv/plotly.js/lib/python3.12/site-packages/kaleido/kaleido.py", line 493, in write_fig_from_object
    res = await asyncio.gather(*tasks, return_exceptions=not cancel_on_error)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ekl/code/plotly.js/venv/plotly.js/lib/python3.12/site-packages/kaleido/kaleido.py", line 358, in _render_task
    img_bytes = await asyncio.wait_for(
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.9/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/tasks.py", line 520, in wait_for
    return await fut
           ^^^^^^^^^
  File "/Users/ekl/code/plotly.js/venv/plotly.js/lib/python3.12/site-packages/kaleido/_kaleido_tab/_tab.py", line 152, in _calc_fig
    spec_str = orjson.dumps(
               ^^^^^^^^^^^^^
TypeError: Integer exceeds 64-bit range

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions