mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-10 07:18:27 +01:00
plots: find metric data in yaml dictionary (#3992)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user