From 51f7e8a12b5bf8f188773ab15c47bdbc3379d200 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Tue, 7 Apr 2020 19:13:30 +0300 Subject: [PATCH] metrics: diff: fix float precision formatting Texttable will try to detect the column type automatically, which results in a low precision of the float that it is showing. We need to disable that auto-formatting and just use `str(val)` instead. --- dvc/command/metrics.py | 3 +++ tests/unit/command/test_metrics.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/dvc/command/metrics.py b/dvc/command/metrics.py index ddc9a2bd52..0f07bffc12 100644 --- a/dvc/command/metrics.py +++ b/dvc/command/metrics.py @@ -121,6 +121,9 @@ def _show_diff(diff): table = Texttable() + # disable automatic formatting + table.set_cols_dtype(["t", "t", "t", "t"]) + # remove borders to make it easier for users to copy stuff table.set_chars(("", "", "", "")) table.set_deco(0) diff --git a/tests/unit/command/test_metrics.py b/tests/unit/command/test_metrics.py index 7a520dddfc..d254da4e56 100644 --- a/tests/unit/command/test_metrics.py +++ b/tests/unit/command/test_metrics.py @@ -119,3 +119,12 @@ def test_metrics_show(dvc, mocker): all_branches=True, all_commits=True, ) + + +def test_metrics_diff_prec(): + assert _show_diff( + {"other.json": {"a.b": {"old": 0.0042, "new": 0.0043, "diff": 0.0001}}} + ) == ( + " Path Metric Value Change\n" + "other.json a.b 0.0043 0.0001" + )