Skip to content

Commit

Permalink
Fix: Empty string as template in CustomPlot.init (#841)
Browse files Browse the repository at this point in the history
* 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 <18718008+skshetry@users.noreply.github.com>

* 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 <18718008+skshetry@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 5, 2024
1 parent afec921 commit 6888462
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/dvclive/plots/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def __init__(
) -> None:
super().__init__(name, output_folder)
self.name = self.name.replace(".json", "")
if not template:
template = None

config = {
"template": template,
"x": x,
Expand Down
27 changes: 27 additions & 0 deletions tests/plots/test_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,30 @@ def test_log_custom_plot_multi_y(tmp_dir):
"x_label": "x_label",
"y_label": "y_label",
}


def test_log_custom_plot_with_template_as_empty_string(tmp_dir):
live = Live()
out = tmp_dir / live.plots_dir / CustomPlot.subfolder

datapoints = [{"x": 1, "y": 2}, {"x": 3, "y": 4}]
live.log_plot(
"custom_linear",
datapoints,
x="x",
y="y",
template="",
title="custom_title",
x_label="x_label",
y_label="y_label",
)

assert json.loads((out / "custom_linear.json").read_text()) == datapoints
# 'template' should not be in plot_config. Default template will be assigned later.
assert live._plots["custom_linear"].plot_config == {
"title": "custom_title",
"x": "x",
"y": "y",
"x_label": "x_label",
"y_label": "y_label",
}

0 comments on commit 6888462

Please sign in to comment.