Skip to content
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 dvc/repo/metrics/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import csv
import json
import logging
from jsonpath_rw import parse
from jsonpath_ng.ext import parse

from dvc.exceptions import OutputNotFoundError, BadMetricError, NoMetricsError
from dvc.utils.compat import builtin_str, open, StringIO, csv_reader
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ nanotime>=0.5.2
pyasn1>=0.4.1
schema>=0.6.7
paramiko>=2.4.1
jsonpath-rw==1.4.0
jsonpath-ng>=1.4.3
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to update setup.py as well.

requests>=2.18.4
wheel>=0.31.1
futures>=3.2.0; python_version == "2.7"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def run(self):
"nanotime>=0.5.2",
"pyasn1>=0.4.1",
"schema>=0.6.7",
"jsonpath-rw==1.4.0",
"jsonpath-ng>=1.4.3",
"requests>=2.18.4",
"grandalf==0.6",
"asciimatics>=1.10.0",
Expand Down
52 changes: 52 additions & 0 deletions tests/func/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,43 @@ def setUp(self):
fd.write("branch\n")
fd.write(branch)

if branch == "foo":
deviation_mse_train = 0.173461
else:
deviation_mse_train = 0.356245

with open("metric_json_ext", "w+") as fd:
json.dump(
{
"metrics": [
{
"dataset": "train",
"deviation_mse": deviation_mse_train,
"value_mse": 0.421601,
},
{
"dataset": "testing",
"deviation_mse": 0.289545,
"value_mse": 0.297848,
},
{
"dataset": "validation",
"deviation_mse": 0.67528,
"value_mse": 0.671502,
},
]
},
fd,
)

files = [
"metric",
"metric_json",
"metric_tsv",
"metric_htsv",
"metric_csv",
"metric_hcsv",
"metric_json_ext",
]

self.dvc.run(metrics_no_cache=files, overwrite=True)
Expand Down Expand Up @@ -101,6 +131,26 @@ def test_show(self):
self.assertSequenceEqual(ret["bar"]["metric_hcsv"], ["bar"])
self.assertSequenceEqual(ret["baz"]["metric_hcsv"], ["baz"])

ret = self.dvc.metrics.show(
"metric_json_ext",
typ="json",
xpath="$.metrics[?(@.deviation_mse<0.30) & (@.value_mse>0.4)]",
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow, this is truly something 🙂 We should definitely document this. Could you please adjust --xpath description for json in https://dvc.org/doc/commands-reference/metrics-modify ?

all_branches=True,
)
self.assertEqual(len(ret), 1)
self.assertSequenceEqual(
ret["foo"]["metric_json_ext"],
[
{
"dataset": "train",
"deviation_mse": 0.173461,
"value_mse": 0.421601,
}
],
)
self.assertRaises(KeyError, lambda: ret["bar"])
self.assertRaises(KeyError, lambda: ret["baz"])

def test_unknown_type_ignored(self):
ret = self.dvc.metrics.show(
"metric_hcsv", typ="unknown", xpath="0,branch", all_branches=True
Expand Down Expand Up @@ -293,6 +343,7 @@ def assertMetricsHaveRelativePaths(self, metrics):
metric_htsv_path = os.path.join(root_relpath, "metric_htsv")
metric_csv_path = os.path.join(root_relpath, "metric_csv")
metric_hcsv_path = os.path.join(root_relpath, "metric_hcsv")
metric_json_ext_path = os.path.join(root_relpath, "metric_json_ext")
for branch in ["bar", "baz", "foo"]:
self.assertEqual(
set(metrics[branch].keys()),
Expand All @@ -303,6 +354,7 @@ def assertMetricsHaveRelativePaths(self, metrics):
metric_htsv_path,
metric_csv_path,
metric_hcsv_path,
metric_json_ext_path,
},
)

Expand Down