Skip to content

Commit e1f4396

Browse files
authored
Skip no data plots while rendering (#4541)
1 parent 18e80b2 commit e1f4396

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

dvc/repo/plots/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ def _prepare_plots(data, revs, props):
187187
continue
188188

189189
for datafile, desc in data[rev].items():
190+
# We silently skip on an absent data file,
191+
# see also try/except/pass in .collect()
192+
if "data" not in desc:
193+
continue
194+
190195
# props from command line overwrite plot props from out definition
191196
full_props = {**desc["props"], **props}
192197

tests/func/plots/test_plots.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
NoFieldInDataError,
2121
TemplateNotFoundError,
2222
)
23+
from dvc.utils.fs import remove
2324
from dvc.utils.serialize import dump_yaml, dumps_yaml
2425

2526

@@ -342,6 +343,38 @@ def test_plot_even_if_metric_missing(
342343
assert plot_content["encoding"]["y"]["field"] == "y"
343344

344345

346+
def test_plot_cache_missing(tmp_dir, scm, dvc, caplog, run_copy_metrics):
347+
metric = [{"y": 2}, {"y": 3}]
348+
_write_json(tmp_dir, metric, "metric_t.json")
349+
stage = run_copy_metrics(
350+
"metric_t.json",
351+
"metric.json",
352+
plots=["metric.json"],
353+
commit="there is metric",
354+
)
355+
scm.tag("v1")
356+
357+
# Make a different plot and then remove its datafile
358+
metric = [{"y": 3}, {"y": 4}]
359+
_write_json(tmp_dir, metric, "metric_t.json")
360+
stage = run_copy_metrics(
361+
"metric_t.json",
362+
"metric.json",
363+
plots=["metric.json"],
364+
commit="there is an another metric",
365+
)
366+
scm.tag("v2")
367+
remove(stage.outs[0].fspath)
368+
remove(stage.outs[0].cache_path)
369+
370+
plots = dvc.plots.show(revs=["v1", "v2"], targets=["metric.json"])
371+
plot_content = json.loads(plots["metric.json"])
372+
assert plot_content["data"]["values"] == [
373+
{"y": 2, PlotData.INDEX_FIELD: 0, "rev": "v1"},
374+
{"y": 3, PlotData.INDEX_FIELD: 1, "rev": "v1"},
375+
]
376+
377+
345378
def test_throw_on_no_metric_at_all(tmp_dir, scm, dvc, caplog):
346379
tmp_dir.scm_gen("some_file", "content", commit="there is no metric")
347380
scm.tag("v1")

0 commit comments

Comments
 (0)