diff --git a/CHANGELOG.md b/CHANGELOG.md index 91c0c93b306..61716a7fbef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [5.2.2] - ??? + +### Fixed + - Fixed error when using the orjson engine with non-string keys + ## [5.2.1] - 2021-08-13 ### Updated diff --git a/packages/python/plotly/plotly/io/_json.py b/packages/python/plotly/plotly/io/_json.py index d36a8a17eca..63c70101dd8 100644 --- a/packages/python/plotly/plotly/io/_json.py +++ b/packages/python/plotly/plotly/io/_json.py @@ -462,7 +462,7 @@ def clean_to_json_compatible(obj, **kwargs): return obj if isinstance(obj, dict): - return {k: clean_to_json_compatible(v, **kwargs) for k, v in obj.items()} + return {str(k): clean_to_json_compatible(v, **kwargs) for k, v in obj.items()} elif isinstance(obj, (list, tuple)): if obj: # Must process list recursively even though it may be slow diff --git a/packages/python/plotly/plotly/tests/test_io/test_to_from_plotly_json.py b/packages/python/plotly/plotly/tests/test_io/test_to_from_plotly_json.py index 63283803e61..b97b76b8228 100644 --- a/packages/python/plotly/plotly/tests/test_io/test_to_from_plotly_json.py +++ b/packages/python/plotly/plotly/tests/test_io/test_to_from_plotly_json.py @@ -209,3 +209,9 @@ def test_object_array(engine, pretty): fig = px.scatter(px.data.tips(), x="total_bill", y="tip", custom_data=["sex"]) result = fig.to_plotly_json() check_roundtrip(result, engine=engine, pretty=pretty) + + +def test_nonstring_key(engine, pretty): + value = build_test_dict({0: 1}) + result = pio.to_json_plotly(value, engine=engine) + check_roundtrip(result, engine=engine, pretty=pretty)