Repository: iterative/dvc
Pull request #9197 (2023-03-16 11:25:12)

deps: bump `dvc-render>=0.3.1<0.4.0`.
Improve performance by removing unnecessary `json.dumps` calls.
See https://github.com/iterative/dvc-render/pull/124


codecov[bot]: ## [Codecov](https://codecov.io/gh/iterative/dvc/pull/9197?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative) Report
Patch coverage: **`100.00`**% and project coverage change: **`-0.41`** :warning:
> Comparison is base [(`58029e9`)](https://codecov.io/gh/iterative/dvc/commit/58029e97191b0a2c6c041e4d6bc929b5f17c079b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative) 92.90% compared to head [(`ede277b`)](https://codecov.io/gh/iterative/dvc/pull/9197?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative) 92.49%.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main    #9197      +/-   ##
==========================================
- Coverage   92.90%   92.49%   -0.41%     
==========================================
  Files         457      457              
  Lines       36935    36933       -2     
  Branches     5332     5323       -9     
==========================================
- Hits        34313    34160     -153     
- Misses       2095     2203     +108     
- Partials      527      570      +43     
```


| [Impacted Files](https://codecov.io/gh/iterative/dvc/pull/9197?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative) | Coverage Δ | |
|---|---|---|
| [dvc/render/convert.py](https://codecov.io/gh/iterative/dvc/pull/9197?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative#diff-ZHZjL3JlbmRlci9jb252ZXJ0LnB5) | `86.66% <ø> (-0.44%)` | :arrow_down: |
| [tests/unit/command/test\_plots.py](https://codecov.io/gh/iterative/dvc/pull/9197?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative#diff-dGVzdHMvdW5pdC9jb21tYW5kL3Rlc3RfcGxvdHMucHk=) | `100.00% <ø> (ø)` | |
| [dvc/commands/plots.py](https://codecov.io/gh/iterative/dvc/pull/9197?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative#diff-ZHZjL2NvbW1hbmRzL3Bsb3RzLnB5) | `88.88% <100.00%> (-0.07%)` | :arrow_down: |
| [tests/unit/render/test\_convert.py](https://codecov.io/gh/iterative/dvc/pull/9197?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative#diff-dGVzdHMvdW5pdC9yZW5kZXIvdGVzdF9jb252ZXJ0LnB5) | `100.00% <100.00%> (ø)` | |

... and [38 files with indirect coverage changes](https://codecov.io/gh/iterative/dvc/pull/9197/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative)

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative)

</details>

[:umbrella: View full report in Codecov by Sentry](https://codecov.io/gh/iterative/dvc/pull/9197?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative).


Patch:
diff --git a/dvc/commands/plots.py b/dvc/commands/plots.py
index 04a3d65d0..d368e67ce 100644
--- a/dvc/commands/plots.py
+++ b/dvc/commands/plots.py
@@ -1,5 +1,4 @@
 import argparse
-import json
 import logging
 import os
 
@@ -136,7 +135,7 @@ class CmdPlots(CmdBase):
             if self.args.show_vega:
                 renderer = first(filter(lambda r: r.TYPE == "vega", renderers))
                 if renderer:
-                    ui.write_json(json.loads(renderer.get_filled_template()))
+                    ui.write_json(renderer.get_filled_template(as_string=False))
                 return 0
 
             output_file: Path = (Path.cwd() / out).resolve() / "index.html"
diff --git a/dvc/render/convert.py b/dvc/render/convert.py
index 828f5383b..1d576fc3a 100644
--- a/dvc/render/convert.py
+++ b/dvc/render/convert.py
@@ -1,4 +1,3 @@
-import json
 from collections import defaultdict
 from typing import Dict, List, Union
 
@@ -32,15 +31,17 @@ def to_json(renderer, split: bool = False) -> List[Dict]:
     if renderer.TYPE == "vega":
         grouped = _group_by_rev(renderer.datapoints)
         if split:
-            content = renderer.get_filled_template(skip_anchors=["data"])
+            content = renderer.get_filled_template(
+                skip_anchors=["data"], as_string=False
+            )
         else:
-            content = renderer.get_filled_template()
+            content = renderer.get_filled_template(as_string=False)
         if grouped:
             return [
                 {
                     TYPE_KEY: renderer.TYPE,
                     REVISIONS_KEY: sorted(grouped.keys()),
-                    "content": json.loads(content),
+                    "content": content,
                     "datapoints": grouped,
                 }
             ]
diff --git a/pyproject.toml b/pyproject.toml
index 40d3edada..da5f7c485 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -36,7 +36,7 @@ dependencies = [
     "dpath<3,>=2.1.0",
     "dvc-data>=0.44.0,<0.45",
     "dvc-http",
-    "dvc-render>=0.1.2",
+    "dvc-render>=0.3.1,<0.4.0",
     "dvc-studio-client>=0.5.0,<1",
     "dvc-task>=0.2.0,<1",
     "flatten_dict<1,>=0.4.1",


Test patch:
diff --git a/tests/unit/command/test_plots.py b/tests/unit/command/test_plots.py
index 35e3c21e6..bb2f67ce4 100644
--- a/tests/unit/command/test_plots.py
+++ b/tests/unit/command/test_plots.py
@@ -129,7 +129,7 @@ def test_plots_diff_vega(dvc, mocker, capsys, plots_data):
     mocker.patch("dvc.repo.plots.diff.diff", return_value=plots_data)
     mocker.patch(
         "dvc_render.VegaRenderer.get_filled_template",
-        return_value=json.dumps({"this": "is vega json"}),
+        return_value={"this": "is vega json"},
     )
     render_mock = mocker.patch("dvc_render.render_html")
     assert cmd.run() == 0
diff --git a/tests/unit/render/test_convert.py b/tests/unit/render/test_convert.py
index 44b83acb2..ea61e857d 100644
--- a/tests/unit/render/test_convert.py
+++ b/tests/unit/render/test_convert.py
@@ -5,7 +5,7 @@ from dvc.render.convert import to_json
 def test_to_json_vega(mocker):
     vega_renderer = mocker.MagicMock()
     vega_renderer.TYPE = "vega"
-    vega_renderer.get_filled_template.return_value = '{"this": "is vega"}'
+    vega_renderer.get_filled_template.return_value = {"this": "is vega"}
     vega_renderer.datapoints = [
         {
             "x": 1,
@@ -50,7 +50,7 @@ def test_to_json_vega(mocker):
 def test_to_json_vega_split(mocker):
     vega_renderer = mocker.MagicMock()
     vega_renderer.TYPE = "vega"
-    vega_renderer.get_filled_template.return_value = '{"this": "is split vega"}'
+    vega_renderer.get_filled_template.return_value = {"this": "is split vega"}
     vega_renderer.datapoints = [
         {
             "x": 1,
@@ -89,7 +89,9 @@ def test_to_json_vega_split(mocker):
             ],
         },
     }
-    vega_renderer.get_filled_template.assert_called_with(skip_anchors=["data"])
+    vega_renderer.get_filled_template.assert_called_with(
+        as_string=False, skip_anchors=["data"]
+    )
 
 
 def test_to_json_image(mocker):