Skip to content

Commit

Permalink
patch revs_with_datapoints not being provided
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Jan 22, 2024
1 parent f1cb983 commit f3f491f
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ tests = [
"dvc-render[table]",
"dvc-render[markdown]",
"pytest==7.2.0",
"pytest-sugar==0.9.5",
"pytest-sugar==0.9.7",
"pytest-cov==3.0.0",
"pytest-mock==3.8.2",
"mypy==1.2.0",
Expand Down
13 changes: 12 additions & 1 deletion src/dvc_render/vega.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,18 @@ def get_revs(self):
"""
Returns all revisions that were collected that have datapoints.
"""
return self.properties.get("revs_with_datapoints", [])
return (
self.properties.get("revs_with_datapoints", [])
or self._get_revs_from_datapoints()
)

def _get_revs_from_datapoints(self):
revs = []
for datapoint in self.datapoints:
rev = datapoint.get("rev")
if rev and rev not in revs:
revs.append(rev)
return revs

def _process_optional_anchors(self, split_anchors: List[str]):
optional_anchors = [
Expand Down
78 changes: 78 additions & 0 deletions tests/test_vega.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,84 @@ def test_optional_anchors_linear( # noqa: PLR0913
assert plot_content["layer"][0]["transform"][0]["groupby"] == group_by


# https://github.com/iterative/dvc-render/issues/149
def test_no_revs_with_datapoints():
datapoints = [
{
"rev": "B",
"acc": "0.05",
"filename": "test",
"field": "acc",
"step": 1,
},
{
"rev": "B",
"acc": "0.1",
"filename": "test",
"field": "acc",
"step": 2,
},
{
"rev": "C",
"acc": "0.05",
"filename": "test",
"field": "acc",
"step": 1,
},
{
"rev": "C",
"acc": "0.1",
"filename": "test",
"field": "acc",
"step": 2,
},
{
"rev": "D",
"acc": "0.05",
"filename": "test",
"field": "acc",
"step": 1,
},
{
"rev": "D",
"acc": "0.1",
"filename": "test",
"field": "acc",
"step": 2,
},
{
"acc": "0.05",
"filename": "test",
"field": "acc",
"step": 1,
},
{
"acc": "0.05",
"filename": "test",
"field": "acc",
"step": 2,
},
]

props = {
"anchors_y_definitions": [{"filename": "test", "field": "acc"}],
"template": "linear",
"x": "step",
"y": "acc",
}

renderer = VegaRenderer(datapoints, "foo", **props)
plot_content = renderer.get_filled_template()

assert plot_content["encoding"]["color"] == {
"field": "rev",
"scale": {
"domain": ["B", "C", "D"],
"range": OPTIONAL_ANCHOR_RANGES["color"][0:3],
},
}


@pytest.mark.parametrize(
(
"anchors_y_definitions",
Expand Down

0 comments on commit f3f491f

Please sign in to comment.