From 584c97a58dd130a74b98c75e8f8f2170fe7e644d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Redzy=C5=84ski?= Date: Fri, 12 Jun 2020 15:08:08 +0200 Subject: [PATCH] plots: fix handling of multiple plots from single revision (#4031) --- dvc/repo/plots/__init__.py | 4 +++- tests/func/plots/test_plots.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/dvc/repo/plots/__init__.py b/dvc/repo/plots/__init__.py index 11e09be6f..07d144a1a 100644 --- a/dvc/repo/plots/__init__.py +++ b/dvc/repo/plots/__init__.py @@ -43,7 +43,9 @@ class Plots: plots = _collect_plots(self.repo, targets, rev) for path_info, props in plots.items(): datafile = relpath(path_info, self.repo.root_dir) - data[rev] = {datafile: {"props": props}} + if rev not in data: + data[rev] = {} + data[rev].update({datafile: {"props": props}}) # Load data from git or dvc cache try: diff --git a/tests/func/plots/test_plots.py b/tests/func/plots/test_plots.py index 33a33d047..294515a8d 100644 --- a/tests/func/plots/test_plots.py +++ b/tests/func/plots/test_plots.py @@ -585,3 +585,24 @@ def test_plots_modify_not_existing_template(dvc): dvc.plots.modify( "metric.json", props={"template": "not-existing-template.json"} ) + + +def test_multiple_plots(tmp_dir, scm, dvc, run_copy_metrics): + metric1 = [ + OrderedDict([("first_val", 100), ("second_val", 100), ("val", 2)]), + OrderedDict([("first_val", 200), ("second_val", 300), ("val", 3)]), + ] + metric2 = [ + OrderedDict([("first_val", 100), ("second_val", 100), ("val", 2)]), + OrderedDict([("first_val", 200), ("second_val", 300), ("val", 3)]), + ] + _write_csv(metric1, "metric_t1.csv") + _write_json(tmp_dir, metric2, "metric_t2.json") + run_copy_metrics( + "metric_t1.csv", "metric1.csv", plots_no_cache=["metric1.csv"] + ) + run_copy_metrics( + "metric_t2.json", "metric2.json", plots_no_cache=["metric2.json"] + ) + + assert len(dvc.plots.show().keys()) == 2