Skip to content

Commit 6888462

Browse files
anunayasriskshetrypre-commit-ci[bot]
authored
Fix: Empty string as template in CustomPlot.init (#841)
* Fix: Empty string as template in CustomPlot.init Fixed dvc issue #10482 at iterative/dvc#10482 * Fix None template in Custom Plot constructor * Update src/dvclive/plots/custom.py Co-authored-by: skshetry <[email protected]> * Remove unnecesary tests in plots/test_custom.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: skshetry <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent afec921 commit 6888462

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Diff for: src/dvclive/plots/custom.py

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def __init__(
2323
) -> None:
2424
super().__init__(name, output_folder)
2525
self.name = self.name.replace(".json", "")
26+
if not template:
27+
template = None
28+
2629
config = {
2730
"template": template,
2831
"x": x,

Diff for: tests/plots/test_custom.py

+27
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,30 @@ def test_log_custom_plot_multi_y(tmp_dir):
5656
"x_label": "x_label",
5757
"y_label": "y_label",
5858
}
59+
60+
61+
def test_log_custom_plot_with_template_as_empty_string(tmp_dir):
62+
live = Live()
63+
out = tmp_dir / live.plots_dir / CustomPlot.subfolder
64+
65+
datapoints = [{"x": 1, "y": 2}, {"x": 3, "y": 4}]
66+
live.log_plot(
67+
"custom_linear",
68+
datapoints,
69+
x="x",
70+
y="y",
71+
template="",
72+
title="custom_title",
73+
x_label="x_label",
74+
y_label="y_label",
75+
)
76+
77+
assert json.loads((out / "custom_linear.json").read_text()) == datapoints
78+
# 'template' should not be in plot_config. Default template will be assigned later.
79+
assert live._plots["custom_linear"].plot_config == {
80+
"title": "custom_title",
81+
"x": "x",
82+
"y": "y",
83+
"x_label": "x_label",
84+
"y_label": "y_label",
85+
}

0 commit comments

Comments
 (0)