8000 Fix error in orjson engine when a dict has a non-string value as a key by jonmmease · Pull Request #3351 · plotly/plotly.py · GitHub
[go: up one dir, main page]

Skip to content

Fix error in orjson engine when a dict has a non-string value as a key #3351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Convert dict keys to strings during cleaning for orjson encoder
  • Loading branch information
jonmmease committed Aug 19, 2021
commit 639c456006fe22f98c9259f4781ef752e14792b0
2 changes: 1 addition & 1 deletion packages/python/plotly/plotly/io/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
0