Skip to content

Commit 56a8945

Browse files
committed
Rename new JSON functions:
- pio.json.to_plotly_json -> pio.json.to_json_plotly - pio.json.from_plotly_json -> pio.json.from_json_plotly
1 parent 66cab10 commit 56a8945

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

packages/python/plotly/plotly/io/_json.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def coerce_to_strict(const):
5858
return const
5959

6060

61-
def to_plotly_json(plotly_object, pretty=False, engine=None):
61+
def to_json_plotly(plotly_object, pretty=False, engine=None):
6262
"""
6363
Convert a plotly/Dash object to a JSON string representation
6464
@@ -198,7 +198,7 @@ def to_json(fig, validate=True, pretty=False, remove_uids=True, engine=None):
198198
199199
See Also
200200
--------
201-
to_plotly_json : Convert an arbitrary plotly graph_object or Dash component to JSON
201+
to_json_plotly : Convert an arbitrary plotly graph_object or Dash component to JSON
202202
"""
203203
# Validate figure
204204
# ---------------
@@ -210,7 +210,7 @@ def to_json(fig, validate=True, pretty=False, remove_uids=True, engine=None):
210210
for trace in fig_dict.get("data", []):
211211
trace.pop("uid", None)
212212

213-
return to_plotly_json(fig_dict, pretty=pretty, engine=engine)
213+
return to_json_plotly(fig_dict, pretty=pretty, engine=engine)
214214

215215

216216
def write_json(fig, file, validate=True, pretty=False, remove_uids=True, engine=None):
@@ -267,7 +267,7 @@ def write_json(fig, file, validate=True, pretty=False, remove_uids=True, engine=
267267
file.write(json_str)
268268

269269

270-
def from_plotly_json(value, engine=None):
270+
def from_json_plotly(value, engine=None):
271271
"""
272272
Parse JSON string using the specified JSON engine
273273
@@ -289,6 +289,10 @@ def from_plotly_json(value, engine=None):
289289
Returns
290290
-------
291291
dict
292+
293+
See Also
294+
--------
295+
from_json_plotly : Parse JSON with plotly conventions into a dict
292296
"""
293297
orjson = get_module("orjson", should_load=True)
294298

@@ -297,7 +301,7 @@ def from_plotly_json(value, engine=None):
297301
if not isinstance(value, (string_types, bytes)):
298302
raise ValueError(
299303
"""
300-
from_plotly_json requires a string or bytes argument but received value of type {typ}
304+
from_json_plotly requires a string or bytes argument but received value of type {typ}
301305
Received value: {value}""".format(
302306
typ=type(value), value=value
303307
)
@@ -368,7 +372,7 @@ def from_json(value, output_type="Figure", skip_invalid=False, engine=None):
368372

369373
# Decode JSON
370374
# -----------
371-
fig_dict = from_plotly_json(value, engine=engine)
375+
fig_dict = from_json_plotly(value, engine=engine)
372376

373377
# Validate coerce output type
374378
# ---------------------------

packages/python/plotly/plotly/io/json.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
from_json,
55
read_json,
66
config,
7-
to_plotly_json,
8-
from_plotly_json,
7+
to_json_plotly,
8+
from_json_plotly,
99
)

packages/python/plotly/plotly/tests/test_io/test_to_from_plotly_json.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ def build_test_dict_string(value_string, pretty=False):
5151

5252

5353
def check_roundtrip(value, engine, pretty):
54-
encoded = pio.to_plotly_json(value, engine=engine, pretty=pretty)
55-
decoded = pio.from_plotly_json(encoded, engine=engine)
56-
reencoded = pio.to_plotly_json(decoded, engine=engine, pretty=pretty)
54+
encoded = pio.to_json_plotly(value, engine=engine, pretty=pretty)
55+
decoded = pio.from_json_plotly(encoded, engine=engine)
56+
reencoded = pio.to_json_plotly(decoded, engine=engine, pretty=pretty)
5757
assert encoded == reencoded
5858

5959
# Check from_plotly_json with bytes on Python 3
6060
if sys.version_info.major == 3:
6161
encoded_bytes = encoded.encode("utf8")
62-
decoded_from_bytes = pio.from_plotly_json(encoded_bytes, engine=engine)
62+
decoded_from_bytes = pio.from_json_plotly(encoded_bytes, engine=engine)
6363
assert decoded == decoded_from_bytes
6464

6565

@@ -124,15 +124,15 @@ def datetime_array(request, datetime_value):
124124
# Encoding tests
125125
def test_graph_object_input(engine, pretty):
126126
scatter = go.Scatter(x=[1, 2, 3], y=np.array([4, 5, 6]))
127-
result = pio.to_plotly_json(scatter, engine=engine)
127+
result = pio.to_json_plotly(scatter, engine=engine)
128128
expected = """{"type":"scatter","x":[1,2,3],"y":[4,5,6]}"""
129129
assert result == expected
130130
check_roundtrip(result, engine=engine, pretty=pretty)
131131

132132

133133
def test_numeric_numpy_encoding(numeric_numpy_array, engine, pretty):
134134
value = build_test_dict(numeric_numpy_array)
135-
result = pio.to_plotly_json(value, engine=engine, pretty=pretty)
135+
result = pio.to_json_plotly(value, engine=engine, pretty=pretty)
136136

137137
array_str = to_json_test(numeric_numpy_array.tolist())
138138
expected = build_test_dict_string(array_str, pretty=pretty)
@@ -142,7 +142,7 @@ def test_numeric_numpy_encoding(numeric_numpy_array, engine, pretty):
142142

143143
def test_object_numpy_encoding(object_numpy_array, engine, pretty):
144144
value = build_test_dict(object_numpy_array)
145-
result = pio.to_plotly_json(value, engine=engine, pretty=pretty)
145+
result = pio.to_json_plotly(value, engine=engine, pretty=pretty)
146146

147147
array_str = to_json_test(object_numpy_array.tolist())
148148
expected = build_test_dict_string(array_str)
@@ -155,15 +155,15 @@ def test_datetime(datetime_value, engine, pretty):
155155
pytest.skip("legacy encoder doesn't strip timezone from scalar datetimes")
156156

157157
value = build_test_dict(datetime_value)
158-
result = pio.to_plotly_json(value, engine=engine, pretty=pretty)
158+
result = pio.to_json_plotly(value, engine=engine, pretty=pretty)
159159
expected = build_test_dict_string('"{}"'.format(isoformat_test(datetime_value)))
160160
assert result == expected
161161
check_roundtrip(result, engine=engine, pretty=pretty)
162162

163163

164164
def test_datetime_arrays(datetime_array, engine, pretty):
165165
value = build_test_dict(datetime_array)
166-
result = pio.to_plotly_json(value, engine=engine)
166+
result = pio.to_json_plotly(value, engine=engine)
167167

168168
if isinstance(datetime_array, pd.Series):
169169
dt_values = [d.isoformat() for d in datetime_array.dt.to_pydatetime().tolist()]

0 commit comments

Comments
 (0)