Skip to content

Commit 7ef805c

Browse files
committed
Use faster plotly.io serialization.
1 parent eae0c14 commit 7ef805c

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

packages/python/plotly/plotly/basedatatypes.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5609,15 +5609,38 @@ def to_plotly_json(self):
56095609
"""
56105610
return deepcopy(self._props if self._props is not None else {})
56115611

5612-
def to_json(self):
5612+
def to_json(self, *args, **kwargs):
56135613
"""
56145614
Convert to a JSON string representation.
56155615
5616+
Parameters
5617+
----------
5618+
validate: bool (default True)
5619+
True if the figure should be validated before being converted to
5620+
JSON, False otherwise.
5621+
5622+
pretty: bool (default False)
5623+
True if JSON representation should be pretty-printed, False if
5624+
representation should be as compact as possible.
5625+
5626+
remove_uids: bool (default True)
5627+
True if trace UIDs should be omitted from the JSON representation
5628+
5629+
engine: str (default None)
5630+
The JSON encoding engine to use. One of:
5631+
- "json" for an encoder based on the built-in Python json module
5632+
- "orjson" for a fast encoder the requires the orjson package
5633+
If not specified, the default encoder is set to the current value of
5634+
plotly.io.json.config.default_encoder.
5635+
56165636
Returns
56175637
-------
56185638
str
5639+
Representation of figure as a JSON string
56195640
"""
5620-
return json.dumps(self.to_plotly_json(), cls=PlotlyJSONEncoder)
5641+
import plotly.io as pio
5642+
5643+
return pio.to_json(self, *args, **kwargs)
56215644

56225645
@staticmethod
56235646
def _vals_equal(v1, v2):

0 commit comments

Comments
 (0)