13
13
# Orca configuration class
14
14
# ------------------------
15
15
class JsonConfig (object ):
16
- _valid_engines = ("legacy" , " json" , "orjson" , "auto" )
16
+ _valid_engines = ("json" , "orjson" , "auto" )
17
17
18
18
def __init__ (self ):
19
19
self ._default_engine = "auto"
@@ -74,7 +74,6 @@ def to_json_plotly(plotly_object, pretty=False, engine=None):
74
74
The JSON encoding engine to use. One of:
75
75
- "json" for an engine based on the built-in Python json module
76
76
- "orjson" for a faster engine that requires the orjson package
77
- - "legacy" for the legacy JSON engine.
78
77
- "auto" for the "orjson" engine if available, otherwise "json"
79
78
If not specified, the default engine is set to the current value of
80
79
plotly.io.json.config.default_engine.
@@ -99,7 +98,7 @@ def to_json_plotly(plotly_object, pretty=False, engine=None):
99
98
engine = "orjson"
100
99
else :
101
100
engine = "json"
102
- elif engine not in ["orjson" , "json" , "legacy" ]:
101
+ elif engine not in ["orjson" , "json" ]:
103
102
raise ValueError ("Invalid json engine: %s" % engine )
104
103
105
104
modules = {
@@ -111,43 +110,17 @@ def to_json_plotly(plotly_object, pretty=False, engine=None):
111
110
112
111
# Dump to a JSON string and return
113
112
# --------------------------------
114
- if engine in ( "json" , "legacy" ) :
113
+ if engine == "json" :
115
114
opts = {"sort_keys" : True }
116
115
if pretty :
117
116
opts ["indent" ] = 2
118
117
else :
119
118
# Remove all whitespace
120
119
opts ["separators" ] = ("," , ":" )
121
120
122
- if engine == "json" :
123
- cleaned = clean_to_json_compatible (
124
- plotly_object ,
125
- numpy_allowed = False ,
126
- datetime_allowed = False ,
127
- modules = modules ,
128
- )
129
- encoded_o = json .dumps (cleaned , ** opts )
130
-
131
- if not ("NaN" in encoded_o or "Infinity" in encoded_o ):
132
- return encoded_o
133
-
134
- # now:
135
- # 1. `loads` to switch Infinity, -Infinity, NaN to None
136
- # 2. `dumps` again so you get 'null' instead of extended JSON
137
- try :
138
- new_o = json .loads (encoded_o , parse_constant = coerce_to_strict )
139
- except ValueError :
140
- # invalid separators will fail here. raise a helpful exception
141
- raise ValueError (
142
- "Encoding into strict JSON failed. Did you set the separators "
143
- "valid JSON separators?"
144
- )
145
- else :
146
- return json .dumps (new_o , ** opts )
147
- else :
148
- from _plotly_utils .utils import PlotlyJSONEncoder
121
+ from _plotly_utils .utils import PlotlyJSONEncoder
149
122
150
- return json .dumps (plotly_object , cls = PlotlyJSONEncoder , ** opts )
123
+ return json .dumps (plotly_object , cls = PlotlyJSONEncoder , ** opts )
151
124
elif engine == "orjson" :
152
125
JsonConfig .validate_orjson ()
153
126
opts = orjson .OPT_SORT_KEYS | orjson .OPT_SERIALIZE_NUMPY
@@ -197,7 +170,6 @@ def to_json(fig, validate=True, pretty=False, remove_uids=True, engine=None):
197
170
The JSON encoding engine to use. One of:
198
171
- "json" for an engine based on the built-in Python json module
199
172
- "orjson" for a faster engine that requires the orjson package
200
- - "legacy" for the legacy JSON engine.
201
173
- "auto" for the "orjson" engine if available, otherwise "json"
202
174
If not specified, the default engine is set to the current value of
203
175
plotly.io.json.config.default_engine.
@@ -249,7 +221,6 @@ def write_json(fig, file, validate=True, pretty=False, remove_uids=True, engine=
249
221
The JSON encoding engine to use. One of:
250
222
- "json" for an engine based on the built-in Python json module
251
223
- "orjson" for a faster engine that requires the orjson package
252
- - "legacy" for the legacy JSON engine.
253
224
- "auto" for the "orjson" engine if available, otherwise "json"
254
225
If not specified, the default engine is set to the current value of
255
226
plotly.io.json.config.default_engine.
@@ -289,7 +260,7 @@ def from_json_plotly(value, engine=None):
289
260
290
261
engine: str (default None)
291
262
The JSON decoding engine to use. One of:
292
- - if "json" or "legacy" , parse JSON using built in json module
263
+ - if "json", parse JSON using built in json module
293
264
- if "orjson", parse using the faster orjson module, requires the orjson
294
265
package
295
266
- if "auto" use orjson module if available, otherwise use the json module
@@ -327,7 +298,7 @@ def from_json_plotly(value, engine=None):
327
298
engine = "orjson"
328
299
else :
329
300
engine = "json"
330
- elif engine not in ["orjson" , "json" , "legacy" ]:
301
+ elif engine not in ["orjson" , "json" ]:
331
302
raise ValueError ("Invalid json engine: %s" % engine )
332
303
333
304
if engine == "orjson" :
@@ -362,7 +333,7 @@ def from_json(value, output_type="Figure", skip_invalid=False, engine=None):
362
333
363
334
engine: str (default None)
364
335
The JSON decoding engine to use. One of:
365
- - if "json" or "legacy" , parse JSON using built in json module
336
+ - if "json", parse JSON using built in json module
366
337
- if "orjson", parse using the faster orjson module, requires the orjson
367
338
package
368
339
- if "auto" use orjson module if available, otherwise use the json module
@@ -416,7 +387,7 @@ def read_json(file, output_type="Figure", skip_invalid=False, engine=None):
416
387
417
388
engine: str (default None)
418
389
The JSON decoding engine to use. One of:
419
- - if "json" or "legacy" , parse JSON using built in json module
390
+ - if "json", parse JSON using built in json module
420
391
- if "orjson", parse using the faster orjson module, requires the orjson
421
392
package
422
393
- if "auto" use orjson module if available, otherwise use the json module
0 commit comments