Skip to content

Commit bd17799

Browse files
authored
Fix error in orjson engine when a dict has a non-string value as a key (#3351)
* Convert dict keys to strings during cleaning for orjson encoder * CHANGELOG.md entry
1 parent c8bd6ee commit bd17799

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [5.2.2] - ???
6+
7+
### Fixed
8+
- Fixed error when using the orjson engine with non-string keys
9+
510
## [5.2.1] - 2021-08-13
611

712
### Updated

packages/python/plotly/plotly/io/_json.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def clean_to_json_compatible(obj, **kwargs):
462462
return obj
463463

464464
if isinstance(obj, dict):
465-
return {k: clean_to_json_compatible(v, **kwargs) for k, v in obj.items()}
465+
return {str(k): clean_to_json_compatible(v, **kwargs) for k, v in obj.items()}
466466
elif isinstance(obj, (list, tuple)):
467467
if obj:
468468
# Must process list recursively even though it may be slow

packages/python/plotly/plotly/tests/test_io/test_to_from_plotly_json.py

+6
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,9 @@ def test_object_array(engine, pretty):
209209
fig = px.scatter(px.data.tips(), x="total_bill", y="tip", custom_data=["sex"])
210210
result = fig.to_plotly_json()
211211
check_roundtrip(result, engine=engine, pretty=pretty)
212+
213+
214+
def test_nonstring_key(engine, pretty):
215+
value = build_test_dict({0: 1})
216+
result = pio.to_json_plotly(value, engine=engine)
217+
check_roundtrip(result, engine=engine, pretty=pretty)

0 commit comments

Comments
 (0)