TabularData: Add to_parallel_coordinates.

Uses `ParallelCoordinatesRenderer` and `dvc.render.html.write`.

pre-requisite #4455
This commit is contained in:
David de la Iglesia Castro
2021-12-17 14:45:12 +09:00
committed by Peter Rowlands (변기호)
parent 19b3c82698
commit a5b7c5ea19
2 changed files with 36 additions and 0 deletions
+18
View File
@@ -153,6 +153,16 @@ class TabularData(MutableSequence[Sequence["CellT"]]):
writer.writerow(row)
return buff.getvalue()
def to_parallel_coordinates(self, output_path, color_by):
from dvc.render.html import write
from dvc.render.plotly import ParallelCoordinatesRenderer
index_path = write(
output_path,
renderers=[ParallelCoordinatesRenderer(self, color_by)],
)
return index_path.as_uri()
def add_column(self, name: str) -> None:
self._columns[name] = Column([self._fill_value] * len(self))
self._keys.append(name)
@@ -173,6 +183,14 @@ class TabularData(MutableSequence[Sequence["CellT"]]):
if kwargs.pop("csv", False):
ui.write(self.to_csv(), end="")
elif kwargs.pop("html", False):
ui.write(
self.to_parallel_coordinates(
kwargs["output_path"], kwargs.get("color_by")
)
)
else:
ui.table(self, headers=self.keys(), **kwargs)
+18
View File
@@ -264,3 +264,21 @@ def test_drop_duplicates_invalid_axis():
with pytest.raises(ValueError, match="Invalid 'axis' value foo."):
td.drop_duplicates("foo")
def test_to_parallel_coordinates(tmp_dir, mocker):
(tmp_dir / "foo").mkdir()
td = TabularData(["categorical", "scalar"])
td.extend([["foo", "0.1"], ["bar", "2"]])
write = mocker.patch("dvc.render.html.write")
renderer_class = mocker.patch(
"dvc.render.plotly.ParallelCoordinatesRenderer"
)
renderer = renderer_class.return_value
td.render(html=True, output_path="foo")
renderer_class.assert_called_with(td, None)
write.assert_called_with("foo", renderers=[renderer])