mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
plots: grouping: stop using dpath.util.search
This commit is contained in:
committed by
Ruslan Kuprieiev
parent
6794dd28f7
commit
20c7b0e3e6
+12
-14
@@ -1,4 +1,4 @@
|
||||
from typing import TYPE_CHECKING, Dict, List, Optional
|
||||
from typing import TYPE_CHECKING, Dict, Optional
|
||||
|
||||
import dpath.util
|
||||
|
||||
@@ -10,20 +10,18 @@ if TYPE_CHECKING:
|
||||
from dvc.types import StrPath
|
||||
|
||||
|
||||
def get_files(plots_data: Dict) -> List:
|
||||
files = set()
|
||||
for rev in plots_data.keys():
|
||||
for file in plots_data[rev].get("data", {}).keys():
|
||||
files.add(file)
|
||||
sorted_files = sorted(files)
|
||||
return sorted_files
|
||||
|
||||
|
||||
def group_by_filename(plots_data: Dict) -> Dict:
|
||||
files = get_files(plots_data)
|
||||
grouped = {
|
||||
file: dpath.util.search(plots_data, ["*", "*", file]) for file in files
|
||||
}
|
||||
grouped: Dict[str, Dict] = {}
|
||||
|
||||
for revision in plots_data.keys():
|
||||
data = plots_data[revision].get("data", {})
|
||||
for file in data.keys():
|
||||
content = data.get(file)
|
||||
if content:
|
||||
dpath.util.new(
|
||||
grouped, [file, revision, "data", file], content
|
||||
)
|
||||
|
||||
return grouped
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import pytest
|
||||
from funcy import first
|
||||
|
||||
from dvc import stage as stage_module
|
||||
from dvc.render.match import get_files
|
||||
|
||||
pytest.importorskip("dvclive", reason="no dvclive")
|
||||
|
||||
@@ -122,7 +121,7 @@ def test_live_provides_metrics(tmp_dir, dvc, live_stage):
|
||||
|
||||
assert (tmp_dir / "logs").is_dir()
|
||||
plots_data = dvc.plots.show()
|
||||
files = get_files(plots_data)
|
||||
files = list(plots_data["workspace"]["data"])
|
||||
assert os.path.join("logs", "scalars", "accuracy.tsv") in files
|
||||
assert os.path.join("logs", "scalars", "loss.tsv") in files
|
||||
assert os.path.join("logs", "images", "0", "image.jpg") in files
|
||||
|
||||
@@ -1,22 +1,10 @@
|
||||
from dvc.render.match import (
|
||||
get_files,
|
||||
group_by_filename,
|
||||
match_renderers,
|
||||
squash_plots_properties,
|
||||
)
|
||||
|
||||
|
||||
def test_get_files_on_error():
|
||||
plots_data = {
|
||||
"v2": {"error": "ERROR"},
|
||||
"v1": {
|
||||
"data": {"file.json": {"data": [{"y": 2}, {"y": 3}], "props": {}}}
|
||||
},
|
||||
}
|
||||
files = get_files(plots_data)
|
||||
assert files == ["file.json"]
|
||||
|
||||
|
||||
def test_group_by_filename():
|
||||
error = FileNotFoundError()
|
||||
data = {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
from dvc.render.match import get_files
|
||||
|
||||
|
||||
def test_plots_order(tmp_dir, dvc):
|
||||
tmp_dir.gen(
|
||||
@@ -28,9 +26,9 @@ def test_plots_order(tmp_dir, dvc):
|
||||
name="stage2",
|
||||
)
|
||||
|
||||
assert get_files(dvc.plots.show()) == [
|
||||
assert list(dvc.plots.show()["workspace"]["data"]) == [
|
||||
"p.json",
|
||||
os.path.join("sub", "p4.json"),
|
||||
"p1.json",
|
||||
os.path.join("sub", "p3.json"),
|
||||
os.path.join("sub", "p4.json"),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user