Skip to content

Commit b4e307c

Browse files
authored
Merge pull request #4301 from itsluketwist/feature/update-json-funcs
Update to_plotly_json docstring, and add new to_json_string helper method
2 parents c838fec + 01bbae9 commit b4e307c

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

Diff for: CHANGELOG.md

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

55
## UNRELEASED
6-
- Fixed two issues with px.imshow: [[#4330](https://github.com/plotly/plotly.py/issues/4330)] when facet_col is an earlier dimension than animation_frame for xarrays and [[#4329](https://github.com/plotly/plotly.py/issues/4329)] when facet_col has string coordinates in xarrays [[#4331](https://github.com/plotly/plotly.py/pull/4331)]
6+
7+
### Updated
8+
- Improved json docstrings, added `BasePlotlyType.to_json()` method [[#4301](https://github.com/plotly/plotly.py/pull/4301)]
9+
10+
### Fixed
11+
- Fixed two issues with px.imshow: [[#4330](https://github.com/plotly/plotly.py/issues/4330)] when facet_col is an earlier dimension than animation_frame for xarrays and [[#4329](https://github.com/plotly/plotly.py/issues/4329)] when facet_col has string coordinates in xarrays [[#4331](https://github.com/plotly/plotly.py/pull/4331)]
712

813
## [5.16.1] - 2023-08-16
914

Diff for: packages/python/plotly/plotly/basedatatypes.py

+39
Original file line numberDiff line numberDiff line change
@@ -3318,6 +3318,9 @@ def to_plotly_json(self):
33183318
"""
33193319
Convert figure to a JSON representation as a Python dict
33203320
3321+
Note: May include some JSON-invalid data types, use the `PlotlyJSONEncoder` util
3322+
or the `to_json` method to encode to a string.
3323+
33213324
Returns
33223325
-------
33233326
dict
@@ -5597,12 +5600,48 @@ def to_plotly_json(self):
55975600
"""
55985601
Return plotly JSON representation of object as a Python dict
55995602
5603+
Note: May include some JSON-invalid data types, use the `PlotlyJSONEncoder` util
5604+
or the `to_json` method to encode to a string.
5605+
56005606
Returns
56015607
-------
56025608
dict
56035609
"""
56045610
return deepcopy(self._props if self._props is not None else {})
56055611

5612+
def to_json(self, *args, **kwargs):
5613+
"""
5614+
Convert object to a JSON string representation
5615+
5616+
Parameters
5617+
----------
5618+
validate: bool (default True)
5619+
True if the object 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+
5636+
Returns
5637+
-------
5638+
str
5639+
Representation of object as a JSON string
5640+
"""
5641+
import plotly.io as pio
5642+
5643+
return pio.to_json(self, *args, **kwargs)
5644+
56065645
@staticmethod
56075646
def _vals_equal(v1, v2):
56085647
"""

0 commit comments

Comments
 (0)