plots: accept list of y vals

This commit is contained in:
dberenbaum
2022-12-20 14:32:40 +01:00
committed by David de la Iglesia Castro
parent 23e4d376c9
commit b4b5db4b4e
2 changed files with 73 additions and 15 deletions
+16 -15
View File
@@ -126,25 +126,26 @@ class VegaConverter(Converter):
break
def _infer_x_y(self):
def _infer_files(from_name, to_name):
from_value = self.properties.get(from_name, None)
to_value = self.properties.get(to_name, None)
x = self.properties.get("x", None)
y = self.properties.get("y", None)
if isinstance(to_value, str):
self.inferred_properties[to_name] = {}
if isinstance(from_value, dict):
for file in from_value.keys():
self.inferred_properties[to_name][file] = to_value
else:
self.inferred_properties[to_name][self.plot_id] = to_value
# Infer x.
if isinstance(x, str):
self.inferred_properties["x"] = {}
# If multiple y files, duplicate x for each file.
if isinstance(y, dict):
for file in y.keys():
self.inferred_properties["x"][file] = x
# Otherwise use plot ID as file.
else:
self.inferred_properties[to_name] = to_value
self.inferred_properties["x"][self.plot_id] = x
_infer_files("y", "x")
_infer_files("x", "y")
if self.inferred_properties.get("y", None) is None:
# Infer y.
if y is None:
self._infer_y_from_data()
# If y files not provided, use plot ID as file.
elif not isinstance(y, dict):
self.inferred_properties["y"] = {self.plot_id: y}
def _find_datapoints(self):
result = {}
+57
View File
@@ -274,6 +274,63 @@ def test_finding_lists(dictionary, expected_result):
{"x": "v", "y": "v2", "x_label": "v", "y_label": "v2"},
id="multi_file_json",
),
pytest.param(
{"f": {"metric": [{"v": 1, "v2": 0.1}, {"v": 2, "v2": 0.2}]}},
{"y": ["v", "v2"]},
[
{
"dvc_inferred_y_value": 1,
"v": 1,
"v2": 0.1,
"step": 0,
VERSION_FIELD: {
"revision": "r",
"filename": "f",
"field": "v",
},
},
{
"dvc_inferred_y_value": 2,
"v": 2,
"v2": 0.2,
"step": 1,
VERSION_FIELD: {
"revision": "r",
"filename": "f",
"field": "v",
},
},
{
"dvc_inferred_y_value": 0.1,
"v": 1,
"v2": 0.1,
"step": 0,
VERSION_FIELD: {
"revision": "r",
"filename": "f",
"field": "v2",
},
},
{
"dvc_inferred_y_value": 0.2,
"v": 2,
"v2": 0.2,
"step": 1,
VERSION_FIELD: {
"revision": "r",
"filename": "f",
"field": "v2",
},
},
],
{
"x": "step",
"y": "dvc_inferred_y_value",
"x_label": "step",
"y_label": "y",
},
id="y_list",
),
],
)
def test_convert(