diff --git a/dvc/compare.py b/dvc/compare.py index 0bf8c54da0..06eb02b277 100644 --- a/dvc/compare.py +++ b/dvc/compare.py @@ -153,6 +153,16 @@ def to_csv(self) -> str: 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 @@ def render(self, **kwargs: Any): 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) diff --git a/tests/unit/test_tabular_data.py b/tests/unit/test_tabular_data.py index a8439d2815..af4b06771a 100644 --- a/tests/unit/test_tabular_data.py +++ b/tests/unit/test_tabular_data.py @@ -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])