Skip to content

Commit

Permalink
add mean transform to linear plot tooltip (#151)
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Seddon <[email protected]>
  • Loading branch information
dberenbaum and mattseddon authored Jan 23, 2024
1 parent 012111f commit 7215e84
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ module = [
ignore_missing_imports = true

[tool.codespell]
ignore-words-list = " "
ignore-words-list = "fpr"

[tool.ruff]
ignore = [
Expand Down
1 change: 1 addition & 0 deletions src/dvc_render/vega_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ class SmoothLinearTemplate(Template):
{"calculate": Template.anchor("pivot_field"), "as": "pivot_field"},
{
"pivot": "pivot_field",
"op": "mean",
"value": Template.anchor("y"),
"groupby": [Template.anchor("x")],
},
Expand Down
40 changes: 40 additions & 0 deletions tests/test_vega.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,46 @@ def test_no_revs_with_datapoints():
}


# https://github.com/iterative/studio/issues/8851
def test_linear_tooltip_groupby():
datapoints = [
{
"filename": "roc.json",
"fpr": 0.00399400898652022,
"tpr": 0.193158953722334,
"rev": "main",
"threshold": 0.84,
},
{
"filename": "roc.json",
"fpr": 0.00399400898652022,
"tpr": 0.2012072434607646,
"rev": "main",
"threshold": 0.829854797979798,
},
{
"filename": "roc.json",
"fpr": 0.00399400898652022,
"tpr": 0.20724346076458752,
"rev": "main",
"threshold": 0.8266666666666667,
},
]

props = {
"anchors_y_definitions": [{"filename": "test", "field": "fpr"}],
"revs_with_datapoints": ["main"],
"template": "linear",
"x": "fpr",
"y": "tpr",
}

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

assert plot_content["layer"][3]["transform"][1]["op"] == "mean"


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

0 comments on commit 7215e84

Please sign in to comment.