mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
TabularData: Decouple pcp from render.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
from collections import Counter, OrderedDict, defaultdict
|
||||
from datetime import date, datetime
|
||||
from fnmatch import fnmatch
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Dict, Iterable, Optional
|
||||
|
||||
from funcy import lmap
|
||||
@@ -472,7 +472,6 @@ def show_experiments(
|
||||
if kwargs.get("only_changed", False) or pcp:
|
||||
td.drop_duplicates("cols", ignore_empty=False)
|
||||
|
||||
pcp_args = {}
|
||||
if pcp:
|
||||
td.dropna("rows", how="all")
|
||||
td.column("Experiment")[:] = [
|
||||
@@ -481,23 +480,25 @@ def show_experiments(
|
||||
for x in td.column("Experiment")
|
||||
]
|
||||
out = kwargs.get("out") or "dvc_plots"
|
||||
pcp_args["output_path"] = (Path.cwd() / out).resolve()
|
||||
pcp_args["color_by"] = kwargs.get("sort_by") or "Experiment"
|
||||
ui.write(
|
||||
td.to_parallel_coordinates(
|
||||
output_path=os.path.abspath(out),
|
||||
color_by=kwargs.get("sort_by") or "Experiment",
|
||||
)
|
||||
)
|
||||
if kwargs.get("open"):
|
||||
return ui.open_browser(os.path.join(out, "index.html"))
|
||||
|
||||
td.render(
|
||||
pager=pager,
|
||||
borders="horizontals",
|
||||
rich_table=True,
|
||||
header_styles=styles,
|
||||
row_styles=row_styles,
|
||||
csv=csv,
|
||||
markdown=markdown,
|
||||
pcp=pcp,
|
||||
**pcp_args,
|
||||
)
|
||||
|
||||
if pcp and kwargs.get("open"):
|
||||
return ui.open_browser(Path(out) / "index.html")
|
||||
else:
|
||||
td.render(
|
||||
pager=pager,
|
||||
borders="horizontals",
|
||||
rich_table=True,
|
||||
header_styles=styles,
|
||||
row_styles=row_styles,
|
||||
csv=csv,
|
||||
markdown=markdown,
|
||||
)
|
||||
|
||||
|
||||
def _normalize_headers(names, count):
|
||||
|
||||
+4
-9
@@ -21,6 +21,7 @@ from typing import (
|
||||
from funcy import reraise
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from dvc.types import StrPath
|
||||
from dvc.ui.table import CellT
|
||||
|
||||
|
||||
@@ -153,7 +154,9 @@ class TabularData(MutableSequence[Sequence["CellT"]]):
|
||||
writer.writerow(row)
|
||||
return buff.getvalue()
|
||||
|
||||
def to_parallel_coordinates(self, output_path, color_by):
|
||||
def to_parallel_coordinates(
|
||||
self, output_path: "StrPath", color_by: str = None
|
||||
) -> str:
|
||||
from dvc.render.html import write
|
||||
from dvc.render.plotly import ParallelCoordinatesRenderer
|
||||
|
||||
@@ -185,14 +188,6 @@ class TabularData(MutableSequence[Sequence["CellT"]]):
|
||||
|
||||
if kwargs.pop("csv", False):
|
||||
ui.write(self.to_csv(), end="")
|
||||
|
||||
elif kwargs.pop("pcp", False):
|
||||
ui.write(
|
||||
self.to_parallel_coordinates(
|
||||
kwargs["output_path"], kwargs.get("color_by")
|
||||
)
|
||||
)
|
||||
|
||||
else:
|
||||
ui.table(self, headers=self.keys(), **kwargs)
|
||||
|
||||
|
||||
@@ -787,9 +787,7 @@ def test_show_experiments_pcp(tmp_dir, mocker):
|
||||
|
||||
td.dropna.assert_called_with("rows", how="all")
|
||||
|
||||
render_kwargs = td.render.call_args[1]
|
||||
kwargs = td.to_parallel_coordinates.call_args[1]
|
||||
|
||||
for arg in ["pcp", "output_path", "color_by"]:
|
||||
assert arg in render_kwargs
|
||||
assert render_kwargs["output_path"] == tmp_dir / "dvc_plots"
|
||||
assert render_kwargs["color_by"] == "Experiment"
|
||||
assert kwargs["output_path"] == str(tmp_dir / "dvc_plots")
|
||||
assert kwargs["color_by"] == "Experiment"
|
||||
|
||||
@@ -337,7 +337,7 @@ def test_to_parallel_coordinates(tmp_dir, mocker):
|
||||
)
|
||||
renderer = renderer_class.return_value
|
||||
|
||||
td.render(pcp=True, output_path="foo")
|
||||
td.to_parallel_coordinates(output_path="foo")
|
||||
|
||||
renderer_class.assert_called_with(td, None, td._fill_value)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user