We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0a83329 commit 645ee13Copy full SHA for 645ee13
3 files changed
packages/python/plotly/plotly/io/_json.py
@@ -112,7 +112,7 @@ def to_json_plotly(plotly_object, pretty=False, engine=None):
112
# Dump to a JSON string and return
113
# --------------------------------
114
if engine == "json":
115
- opts = {"sort_keys": True}
+ opts = {}
116
if pretty:
117
opts["indent"] = 2
118
else:
@@ -124,7 +124,7 @@ def to_json_plotly(plotly_object, pretty=False, engine=None):
124
return json.dumps(plotly_object, cls=PlotlyJSONEncoder, **opts)
125
elif engine == "orjson":
126
JsonConfig.validate_orjson()
127
- opts = orjson.OPT_SORT_KEYS | orjson.OPT_SERIALIZE_NUMPY
+ opts = orjson.OPT_NON_STR_KEYS | orjson.OPT_SERIALIZE_NUMPY
128
129
130
opts |= orjson.OPT_INDENT_2
@@ -462,7 +462,7 @@ def clean_to_json_compatible(obj, **kwargs):
462
return obj
463
464
if isinstance(obj, dict):
465
- return {str(k): clean_to_json_compatible(v, **kwargs) for k, v in obj.items()}
+ return {k: clean_to_json_compatible(v, **kwargs) for k, v in obj.items()}
466
elif isinstance(obj, (list, tuple)):
467
if obj:
468
# Must process list recursively even though it may be slow
packages/python/plotly/plotly/tests/test_io/test_to_from_json.py
@@ -29,9 +29,8 @@ def fig1(request):
29
opts = {
30
"separators": (",", ":"),
31
"cls": plotly.utils.PlotlyJSONEncoder,
32
- "sort_keys": True,
33
}
34
-pretty_opts = {"indent": 2, "cls": plotly.utils.PlotlyJSONEncoder, "sort_keys": True}
+pretty_opts = {"indent": 2, "cls": plotly.utils.PlotlyJSONEncoder}
35
36
37
# to_json
packages/python/plotly/plotly/tests/test_io/test_to_from_plotly_json.py
@@ -135,7 +135,7 @@ def datetime_array(request, datetime_value):
135
def test_graph_object_input(engine, pretty):
136
scatter = go.Scatter(x=[1, 2, 3], y=np.array([4, 5, 6]))
137
result = pio.to_json_plotly(scatter, engine=engine)
138
- expected = """{"type":"scatter","x":[1,2,3],"y":[4,5,6]}"""
+ expected = """{"x":[1,2,3],"y":[4,5,6],"type":"scatter"}"""
139
assert result == expected
140
check_roundtrip(result, engine=engine, pretty=pretty)
141
@@ -215,3 +215,9 @@ def test_nonstring_key(engine, pretty):
215
value = build_test_dict({0: 1})
216
result = pio.to_json_plotly(value, engine=engine)
217
218
+
219
220
+def test_mixed_string_nonstring_key(engine, pretty):
221
+ value = build_test_dict({0: 1, "a": 2})
222
+ result = pio.to_json_plotly(value, engine=engine)
223
+ check_roundtrip(result, engine=engine, pretty=pretty)
0 commit comments