Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch revs_with_datapoints not being provided #150

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests would not run locally without this change

"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