jupyter-widgets / ipywidgets

Interactive Widgets for the Jupyter Notebook
https://ipywidgets.readthedocs.io
BSD 3-Clause "New" or "Revised" License
3.13k stars 950 forks source link

IEEE float serializers #3321

Open vidartf opened 2 years ago

vidartf commented 2 years ago

Problem

There are issues with using the default Python serialization for floats, as it might write invalid JSON including plain-text NaN, Infinity, -Infinity values. See e.g. https://github.com/jupyter-widgets/ipywidgets/issues/1531 and https://github.com/jupyter-widgets/pythreejs/issues/366 for examples of places where it might make sense to have support for IEEE values.

Proposed Solution

Add a set of convenience serializers (and possibly a separate trait type if that makes things easier?) for transmitting full IEEE float values. This would probably entail encoding nan/inf as strings (enum values).

Additional context

A very timely additional question is whether any of the core widgets should switch to using such a serialization. This would change the protocol for these widgets in a non-backwards compatible manner, making it a candidate for 8.0 (e.g. for https://github.com/jupyter-widgets/ipywidgets/issues/1531).

SylvainCorlay commented 2 years ago

This is a related issue in ipykernel/jupyter_client: https://github.com/jupyter/jupyter_client/pull/708