plots: find metric data in yaml dictionary (#3992)

This commit is contained in:
Paweł Redzyński
2020-06-09 16:42:28 +03:00
committed by GitHub
parent 593e67318b
commit 56833387ce
2 changed files with 32 additions and 0 deletions
+4
View File
@@ -237,6 +237,10 @@ class YAMLPlotData(PlotData):
return yaml.load(self.content, OrderedLoader)
def _processors(self):
parent_processors = super()._processors()
return [_find_data] + parent_processors
def _load_from_revision(repo, datafile, revision):
from dvc.repo.tree import RepoTree
+28
View File
@@ -10,9 +10,11 @@ import yaml
from funcy import first
from dvc.repo.plots.data import (
JSONPlotData,
NoMetricInHistoryError,
PlotData,
PlotMetricTypeError,
YAMLPlotData,
)
from dvc.repo.plots.template import (
NoDataForTemplateError,
@@ -581,3 +583,29 @@ def test_raise_on_wrong_field(tmp_dir, scm, dvc, run_copy_metrics):
with pytest.raises(NoFieldInDataError):
dvc.plots.show("metric.json", props={"y": "no_val"})
def test_load_metric_from_dict_json(tmp_dir):
metric = [{"acccuracy": 1, "loss": 2}, {"accuracy": 3, "loss": 4}]
dmetric = {"train": metric}
plot_data = JSONPlotData("-", "revision", json.dumps(dmetric))
expected = metric
for d in expected:
d["rev"] = "revision"
assert list(map(dict, plot_data.to_datapoints())) == expected
def test_load_metric_from_dict_yaml(tmp_dir):
metric = [{"acccuracy": 1, "loss": 2}, {"accuracy": 3, "loss": 4}]
dmetric = {"train": metric}
plot_data = YAMLPlotData("-", "revision", yaml.dump(dmetric))
expected = metric
for d in expected:
d["rev"] = "revision"
assert list(map(dict, plot_data.to_datapoints())) == expected