Skip to content

Commit 7d301f2

Browse files
David-Wu1119claude
andcommitted
Fix unformatted placeholders in two ValueError messages
The error raised when adding a trace with `secondary_y=True` to a subplot that was not created with the `secondary_y` spec, and the error raised for an invalid `output_type` in `plotly.io.from_json`/`read_json`, were plain strings that were never formatted, so users saw the literal "{subplot_type}", "({row}, {col})" and "{output_type}". Format them like the neighbouring messages in the same functions already do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent f670752 commit 7d301f2

4 files changed

Lines changed: 16 additions & 2 deletions

File tree

‎plotly/_subplots.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ def _set_trace_grid_reference(trace, layout, grid_ref, row, col, secondary_y=Fal
14251425
Subplot with type '{subplot_type}' at grid position ({row}, {col}) was not
14261426
created with the secondary_y spec property set to True. See the docstring
14271427
for the specs argument to plotly.subplots.make_subplots for more information.
1428-
"""
1428+
""".format(subplot_type=subplot_refs[0].subplot_type, row=row, col=col)
14291429
)
14301430
trace_kwargs = subplot_refs[1].trace_kwargs
14311431
else:

‎plotly/io/_utils.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def validate_coerce_output_type(output_type):
3838
raise ValueError(
3939
"""
4040
Invalid output type: {output_type}
41-
Must be one of: 'Figure', 'FigureWidget'"""
41+
Must be one of: 'Figure', 'FigureWidget'""".format(output_type=output_type)
4242
)
4343
return cls
4444

‎tests/test_core/test_subplots/test_make_subplots.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,3 +2038,12 @@ def test_make_subplots_spacing_error():
20382038
ValueError, match=r"^Vertical spacing must be between 0 and 1\.$"
20392039
):
20402040
subplots.make_subplots(1, 1, vertical_spacing=1.01)
2041+
2042+
2043+
def test_secondary_y_without_spec_error():
2044+
fig = subplots.make_subplots(rows=1, cols=2)
2045+
with pytest.raises(
2046+
ValueError,
2047+
match=r"Subplot with type 'xy' at grid position \(1, 2\) was not",
2048+
):
2049+
fig.add_scatter(x=[1], y=[1], row=1, col=2, secondary_y=True)

‎tests/test_io/test_to_from_json.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ def test_from_json_invalid(fig1):
118118
pio.from_json(bad_json)
119119

120120

121+
def test_from_json_invalid_output_type(fig1):
122+
with pytest.raises(ValueError, match="Invalid output type: Bogus"):
123+
pio.from_json(pio.to_json(fig1), output_type="Bogus")
124+
125+
121126
def test_from_json_skip_invalid(fig1):
122127
dict1 = fig1.to_dict()
123128

0 commit comments

Comments
 (0)