Skip to content

Commit

Permalink
drop terrible idea of holding all data as strings
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Nov 14, 2023
1 parent b50b671 commit 1d367d0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dvc/commands/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def run(self) -> int: # noqa: C901, PLR0911, PLR0912
if self.args.show_vega:
renderer = first(filter(lambda r: r.TYPE == "vega", renderers))
if renderer:
ui.write_json(renderer.get_filled_template(as_string=False))
ui.write_json(renderer.get_filled_template())
return 0

output_file: Path = (Path.cwd() / out).resolve() / "index.html"
Expand Down
2 changes: 1 addition & 1 deletion dvc/render/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def to_json(renderer, split: bool = False) -> List[Dict]:
if split:
content, split_content = renderer.get_partial_filled_template()
else:
content = renderer.get_filled_template(as_string=False)
content = renderer.get_filled_template()
split_content = {}

return [
Expand Down
26 changes: 14 additions & 12 deletions tests/integration/plots/test_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,20 @@ def verify_vega(
assert j[0]["type"] == "vega"
assert set(j[0]["revisions"]) == set(versions)

assert json_result[0]["content"]["data"]["values"] == json.loads(
split_json_result[0]["anchor_definitions"]["<DVC_METRIC_DATA>"]
assert (
json_result[0]["content"]["data"]["values"]
== split_json_result[0]["anchor_definitions"]["<DVC_METRIC_DATA>"]
)

assert set(versions) == set(json_result[0]["revisions"])

assert json_result[0]["content"]["data"]["values"]
assert html_result["data"]["values"]
assert "<DVC_METRIC_DATA>" in split_json_result[0]["content"]
assert "<DVC_METRIC_X_LABEL>" in split_json_result[0]["content"]
assert "<DVC_METRIC_Y_LABEL>" in split_json_result[0]["content"]

content_str = json.dumps(split_json_result[0]["content"])
assert "<DVC_METRIC_DATA>" in content_str
assert "<DVC_METRIC_X_LABEL>" in content_str
assert "<DVC_METRIC_Y_LABEL>" in content_str

def _assert_templates_equal(
html_template, filled_template, split_template, title, x_label, y_label
Expand All @@ -133,7 +137,7 @@ def _assert_templates_equal(
tmp1 = deepcopy(html_template)
tmp2 = deepcopy(filled_template)
tmp3 = json.loads(
split_template[:]
json.dumps(split_template)
.replace('"<DVC_METRIC_COLUMN_WIDTH>"', "300")
.replace('"<DVC_METRIC_PLOT_HEIGHT>"', "300")
.replace('"<DVC_METRIC_PLOT_WIDTH>"', "300")
Expand Down Expand Up @@ -486,11 +490,9 @@ def test_repo_with_config_plots(tmp_dir, capsys, repo_with_config_plots):

assert html_result["linear_train_vs_test"]["data"]["values"] == ble
assert (
json.loads(
split_json_result["data"]["linear_train_vs_test"][0]["anchor_definitions"][
"<DVC_METRIC_DATA>"
]
)
split_json_result["data"]["linear_train_vs_test"][0]["anchor_definitions"][
"<DVC_METRIC_DATA>"
]
== ble
)

Expand All @@ -501,7 +503,7 @@ def test_repo_with_dvclive_plots(tmp_dir, capsys, repo_with_dvclive_plots):

for s in ("show", "diff"):
_, json_result, split_json_result = call(capsys, subcommand=s)
expected_result = {
expected_result: Dict[str, Dict[str, list[str]]] = {
"data": {
"dvclive/plots/metrics/metric.tsv": [],
},
Expand Down

0 comments on commit 1d367d0

Please sign in to comment.