Skip to content

Commit

Permalink
plotly: Add missing cast to str for rich.Text conversion.
Browse files Browse the repository at this point in the history
DVC passes some values as `rich.Text` instead of string.
As an oversight in #69 , the refactor to use `list_dict_to_dict_list` removed this string casting, breaking `dvc exp show --pcp`
  • Loading branch information
daavoo committed Jul 26, 2022
1 parent 4fe35d8 commit f2a497a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/dvc_render/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def _get_plotly_data(self):

trace: Dict[str, Any] = {"type": "parcoords", "dimensions": []}
for label, values in tabular_dict.items():
values = list(map(str, values))
is_categorical = False
try:
float_values = [
Expand Down
14 changes: 13 additions & 1 deletion tests/test_parallel_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dvc_render.html import render_html
from dvc_render.plotly import ParallelCoordinatesRenderer

# pylint: disable=missing-function-docstring, unspecified-encoding
# pylint: disable=C0116, W1514, W0212, R0903


def expected_format(result):
Expand Down Expand Up @@ -170,3 +170,15 @@ def test_fill_value():
"label": "scalar",
"values": [None, 2.0],
}


def test_str_cast():
class Foo:
def __str__(self):
return "1"

datapoints = [{"foo": Foo()}]
renderer = ParallelCoordinatesRenderer(datapoints, fill_value="-")

result = renderer._get_plotly_data()
assert result["data"][0]["dimensions"][0]["values"] == [1.0]

0 comments on commit f2a497a

Please sign in to comment.