From 1d367d0f4f2543b766069b66f9a8d838ec27dd5c Mon Sep 17 00:00:00 2001 From: Matt Seddon Date: Thu, 9 Nov 2023 09:48:25 +1100 Subject: [PATCH] drop terrible idea of holding all data as strings --- dvc/commands/plots.py | 2 +- dvc/render/convert.py | 2 +- tests/integration/plots/test_plots.py | 26 ++++++++++++++------------ 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/dvc/commands/plots.py b/dvc/commands/plots.py index a53be3f35e8..4c22ea2fe74 100644 --- a/dvc/commands/plots.py +++ b/dvc/commands/plots.py @@ -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" diff --git a/dvc/render/convert.py b/dvc/render/convert.py index b5466839b39..bfbc6fa40e5 100644 --- a/dvc/render/convert.py +++ b/dvc/render/convert.py @@ -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 [ diff --git a/tests/integration/plots/test_plots.py b/tests/integration/plots/test_plots.py index 630278eced9..20053b0683a 100644 --- a/tests/integration/plots/test_plots.py +++ b/tests/integration/plots/test_plots.py @@ -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"][""] + assert ( + json_result[0]["content"]["data"]["values"] + == split_json_result[0]["anchor_definitions"][""] ) + assert set(versions) == set(json_result[0]["revisions"]) assert json_result[0]["content"]["data"]["values"] assert html_result["data"]["values"] - assert "" in split_json_result[0]["content"] - assert "" in split_json_result[0]["content"] - assert "" in split_json_result[0]["content"] + + content_str = json.dumps(split_json_result[0]["content"]) + assert "" in content_str + assert "" in content_str + assert "" in content_str def _assert_templates_equal( html_template, filled_template, split_template, title, x_label, y_label @@ -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('""', "300") .replace('""', "300") .replace('""', "300") @@ -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"][ - "" - ] - ) + split_json_result["data"]["linear_train_vs_test"][0]["anchor_definitions"][ + "" + ] == ble ) @@ -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": [], },