From 62acd393b965f771edb7742700e0d92944b0c77c Mon Sep 17 00:00:00 2001 From: David de la Iglesia Castro Date: Wed, 13 Oct 2021 14:16:52 +0200 Subject: [PATCH 01/11] Added `--md`/`--show-md` option to `exp show`. --- dvc/command/experiments.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/dvc/command/experiments.py b/dvc/command/experiments.py index 47d35c357c..eda76a73d2 100644 --- a/dvc/command/experiments.py +++ b/dvc/command/experiments.py @@ -382,7 +382,12 @@ def baseline_styler(typ): def show_experiments( - all_experiments, pager=True, no_timestamp=False, csv=False, **kwargs + all_experiments, + pager=True, + no_timestamp=False, + csv=False, + markdown=False, + **kwargs, ): from funcy.seqs import flatten as flatten_list @@ -473,6 +478,7 @@ def show_experiments( header_styles=styles, row_styles=row_styles, csv=csv, + markdown=markdown, ) @@ -530,6 +536,7 @@ def run(self): iso=iso, pager=not self.args.no_pager, csv=self.args.csv, + markdown=self.args.md, ) return 0 @@ -986,6 +993,13 @@ def add_parser(subparsers, parent_parser): default=False, help="Print output in csv format instead of a human-readable table.", ) + experiments_show_parser.add_argument( + "--md", + "--show-md", + action="store_true", + default=False, + help="Print output in Markdown format.", + ) experiments_show_parser.add_argument( "--precision", type=int, From 5a6086f87cf4007e783c437cfbec2effec3a17f9 Mon Sep 17 00:00:00 2001 From: David de la Iglesia Castro Date: Wed, 13 Oct 2021 14:25:24 +0200 Subject: [PATCH 02/11] Added test_show_experiments_md --- tests/unit/command/test_experiments.py | 35 +++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tests/unit/command/test_experiments.py b/tests/unit/command/test_experiments.py index 1439c9d768..54e766f922 100644 --- a/tests/unit/command/test_experiments.py +++ b/tests/unit/command/test_experiments.py @@ -379,7 +379,7 @@ def test_experiments_remove(dvc, scm, mocker, queue, clear_all, remote): } -def test_show_experiments(capsys): +def test_show_experiments_csv(capsys): show_experiments( all_experiments, precision=None, fill_value="", iso=True, csv=True ) @@ -407,6 +407,39 @@ def test_show_experiments(capsys): ) +def test_show_experiments_md(capsys): + all_experiments = { + "workspace": { + "baseline": { + "data": { + "timestamp": None, + "params": {"params.yaml": {"data": {"foo": 1}}}, + "queued": False, + "running": False, + "executor": None, + "metrics": { + "scores.json": {"data": {"bar": 0.9544670443829399}} + }, + } + } + }, + } + show_experiments( + all_experiments, precision=None, fill_value="", iso=True, markdown=True + ) + cap = capsys.readouterr() + + assert ( + "| Experiment | Created | bar | foo |" in cap.out + ) + assert ( + "|--------------|-----------|--------------------|-------|" in cap.out + ) + assert ( + "| workspace | | 0.9544670443829399 | 1 |" in cap.out + ) + + def test_experiments_init_config(dvc, mocker): with dvc.config.edit() as conf: conf["exp"] = {"code": "new_src", "models": "new_models"} From feab666a3ff97e36609ad9cfa1810c07ac9859b0 Mon Sep 17 00:00:00 2001 From: David de la Iglesia Castro Date: Wed, 13 Oct 2021 21:06:19 +0200 Subject: [PATCH 03/11] Fixed re-defining all_experiments --- tests/unit/command/test_experiments.py | 181 ++++++++++++------------- 1 file changed, 90 insertions(+), 91 deletions(-) diff --git a/tests/unit/command/test_experiments.py b/tests/unit/command/test_experiments.py index 54e766f922..cdfffdf3f8 100644 --- a/tests/unit/command/test_experiments.py +++ b/tests/unit/command/test_experiments.py @@ -282,104 +282,103 @@ def test_experiments_remove(dvc, scm, mocker, queue, clear_all, remote): ) -all_experiments = { - "workspace": { - "baseline": { - "data": { - "timestamp": None, - "params": { - "params.yaml": { - "data": { - "featurize": {"max_features": 3000, "ngrams": 1}, - "parent": 20170428, - "train": { - "n_est": 100, - "min_split": 36, - }, +def test_show_experiments_csv(capsys): + all_experiments = { + "workspace": { + "baseline": { + "data": { + "timestamp": None, + "params": { + "params.yaml": { + "data": { + "featurize": {"max_features": 3000, "ngrams": 1}, + "parent": 20170428, + "train": { + "n_est": 100, + "min_split": 36, + }, + } } - } - }, - "queued": False, - "running": False, - "executor": None, - "metrics": { - "scores.json": { - "data": { - "featurize": {"max_features": 3000, "ngrams": 1}, - "avg_prec": 0.5843640011189556, - "roc_auc": 0.9544670443829399, + }, + "queued": False, + "running": False, + "executor": None, + "metrics": { + "scores.json": { + "data": { + "featurize": {"max_features": 3000, "ngrams": 1}, + "avg_prec": 0.5843640011189556, + "roc_auc": 0.9544670443829399, + } } - } - }, + }, + } } - } - }, - "b05eecc666734e899f79af228ff49a7ae5a18cc0": { - "baseline": { - "data": { - "timestamp": datetime(2021, 8, 2, 16, 48, 14), - "params": { - "params.yaml": { - "data": { - "featurize": {"max_features": 3000, "ngrams": 1}, - "parent": 20170428, - "train": { - "n_est": 100, - "min_split": 2, - }, + }, + "b05eecc666734e899f79af228ff49a7ae5a18cc0": { + "baseline": { + "data": { + "timestamp": datetime(2021, 8, 2, 16, 48, 14), + "params": { + "params.yaml": { + "data": { + "featurize": {"max_features": 3000, "ngrams": 1}, + "parent": 20170428, + "train": { + "n_est": 100, + "min_split": 2, + }, + } } - } - }, - "queued": False, - "running": False, - "executor": None, - "metrics": { - "scores.json": { - "data": { - "featurize": {"max_features": 3000, "ngrams": 1}, - "avg_prec": 0.5325162867864254, - "roc_auc": 0.9106964878520005, + }, + "queued": False, + "running": False, + "executor": None, + "metrics": { + "scores.json": { + "data": { + "featurize": {"max_features": 3000, "ngrams": 1}, + "avg_prec": 0.5325162867864254, + "roc_auc": 0.9106964878520005, + } } - } - }, - "name": "master", - } - }, - "ae99936461d6c3092934160f8beafe66a294f98d": { - "data": { - "timestamp": datetime(2021, 8, 31, 14, 56, 55), - "params": { - "params.yaml": { - "data": { - "featurize": {"max_features": 3000, "ngrams": 1}, - "parent": 20170428, - "train": { - "n_est": 100, - "min_split": 36, - }, + }, + "name": "master", + } + }, + "ae99936461d6c3092934160f8beafe66a294f98d": { + "data": { + "timestamp": datetime(2021, 8, 31, 14, 56, 55), + "params": { + "params.yaml": { + "data": { + "featurize": {"max_features": 3000, "ngrams": 1}, + "parent": 20170428, + "train": { + "n_est": 100, + "min_split": 36, + }, + } } - } - }, - "queued": True, - "running": True, - "executor": None, - "metrics": { - "scores.json": { - "data": { - "featurize": {"max_features": 3000, "ngrams": 1}, - "avg_prec": 0.5843640011189556, - "roc_auc": 0.9544670443829399, + }, + "queued": True, + "running": True, + "executor": None, + "metrics": { + "scores.json": { + "data": { + "featurize": {"max_features": 3000, "ngrams": 1}, + "avg_prec": 0.5843640011189556, + "roc_auc": 0.9544670443829399, + } } - } - }, - "name": "exp-44136", - } + }, + "name": "exp-44136", + } + }, }, - }, -} - + } -def test_show_experiments_csv(capsys): show_experiments( all_experiments, precision=None, fill_value="", iso=True, csv=True ) @@ -408,7 +407,7 @@ def test_show_experiments_csv(capsys): def test_show_experiments_md(capsys): - all_experiments = { + md_experiments = { "workspace": { "baseline": { "data": { @@ -425,7 +424,7 @@ def test_show_experiments_md(capsys): }, } show_experiments( - all_experiments, precision=None, fill_value="", iso=True, markdown=True + md_experiments, precision=None, fill_value="", iso=True, markdown=True ) cap = capsys.readouterr() From f1234632784b8f6f2664adba685ce0c5b75f25bc Mon Sep 17 00:00:00 2001 From: David de la Iglesia Castro Date: Wed, 13 Oct 2021 21:06:31 +0200 Subject: [PATCH 04/11] Fixed all_experiments --- tests/unit/command/test_experiments.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/command/test_experiments.py b/tests/unit/command/test_experiments.py index cdfffdf3f8..68dbbb74a3 100644 --- a/tests/unit/command/test_experiments.py +++ b/tests/unit/command/test_experiments.py @@ -407,7 +407,7 @@ def test_show_experiments_csv(capsys): def test_show_experiments_md(capsys): - md_experiments = { + all_experiments = { "workspace": { "baseline": { "data": { @@ -424,7 +424,7 @@ def test_show_experiments_md(capsys): }, } show_experiments( - md_experiments, precision=None, fill_value="", iso=True, markdown=True + all_experiments, precision=None, fill_value="", iso=True, markdown=True ) cap = capsys.readouterr() From 2ca61995f8c5cfa962269770ccb752dc4cb90d42 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 13 Oct 2021 19:08:01 +0000 Subject: [PATCH 05/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/unit/command/test_experiments.py | 30 ++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/tests/unit/command/test_experiments.py b/tests/unit/command/test_experiments.py index 68dbbb74a3..fa7ae74608 100644 --- a/tests/unit/command/test_experiments.py +++ b/tests/unit/command/test_experiments.py @@ -291,7 +291,10 @@ def test_show_experiments_csv(capsys): "params": { "params.yaml": { "data": { - "featurize": {"max_features": 3000, "ngrams": 1}, + "featurize": { + "max_features": 3000, + "ngrams": 1, + }, "parent": 20170428, "train": { "n_est": 100, @@ -306,7 +309,10 @@ def test_show_experiments_csv(capsys): "metrics": { "scores.json": { "data": { - "featurize": {"max_features": 3000, "ngrams": 1}, + "featurize": { + "max_features": 3000, + "ngrams": 1, + }, "avg_prec": 0.5843640011189556, "roc_auc": 0.9544670443829399, } @@ -322,7 +328,10 @@ def test_show_experiments_csv(capsys): "params": { "params.yaml": { "data": { - "featurize": {"max_features": 3000, "ngrams": 1}, + "featurize": { + "max_features": 3000, + "ngrams": 1, + }, "parent": 20170428, "train": { "n_est": 100, @@ -337,7 +346,10 @@ def test_show_experiments_csv(capsys): "metrics": { "scores.json": { "data": { - "featurize": {"max_features": 3000, "ngrams": 1}, + "featurize": { + "max_features": 3000, + "ngrams": 1, + }, "avg_prec": 0.5325162867864254, "roc_auc": 0.9106964878520005, } @@ -352,7 +364,10 @@ def test_show_experiments_csv(capsys): "params": { "params.yaml": { "data": { - "featurize": {"max_features": 3000, "ngrams": 1}, + "featurize": { + "max_features": 3000, + "ngrams": 1, + }, "parent": 20170428, "train": { "n_est": 100, @@ -367,7 +382,10 @@ def test_show_experiments_csv(capsys): "metrics": { "scores.json": { "data": { - "featurize": {"max_features": 3000, "ngrams": 1}, + "featurize": { + "max_features": 3000, + "ngrams": 1, + }, "avg_prec": 0.5843640011189556, "roc_auc": 0.9544670443829399, } From 2bfe917d13e259a0fa4613f375c476e6cb90e1af Mon Sep 17 00:00:00 2001 From: David de la Iglesia Castro Date: Thu, 14 Oct 2021 16:34:53 +0200 Subject: [PATCH 06/11] Added dest markdown --- dvc/command/experiments.py | 3 ++- tests/unit/command/test_compat_flag.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dvc/command/experiments.py b/dvc/command/experiments.py index 5e1737dcac..4816718bc9 100644 --- a/dvc/command/experiments.py +++ b/dvc/command/experiments.py @@ -536,7 +536,7 @@ def run(self): iso=iso, pager=not self.args.no_pager, csv=self.args.csv, - markdown=self.args.md, + markdown=self.args.markdown, ) return 0 @@ -1001,6 +1001,7 @@ def add_parser(subparsers, parent_parser): "--show-md", action="store_true", default=False, + dest="markdown", help="Print output in Markdown format.", ) experiments_show_parser.add_argument( diff --git a/tests/unit/command/test_compat_flag.py b/tests/unit/command/test_compat_flag.py index 1c559a017a..6672275e8a 100644 --- a/tests/unit/command/test_compat_flag.py +++ b/tests/unit/command/test_compat_flag.py @@ -20,6 +20,8 @@ def _id_gen(val) -> str: (["experiments", "diff", "--show-md"], "markdown"), (["experiments", "show", "--show-json"], "json"), (["experiments", "show", "--show-csv"], "csv"), + (["experiments", "show", "--show-md"], "markdown"), + (["experiments", "show", "--md"], "markdown"), (["ls", "--show-json", "."], "json"), (["metrics", "diff", "--show-json"], "json"), (["metrics", "diff", "--show-md"], "markdown"), @@ -35,4 +37,5 @@ def test_backward_compat_flags(args, key): """Test support for --show-csv/--show-json/--show-md flags.""" cli_args = parse_args(args) d = vars(cli_args) + print(d) assert d[key] is True From bf0e400e620ea306c981deaf301cd4d1dba7180d Mon Sep 17 00:00:00 2001 From: David de la Iglesia Castro Date: Thu, 14 Oct 2021 16:42:12 +0200 Subject: [PATCH 07/11] Added textwrap.dedent --- tests/unit/command/test_experiments.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/unit/command/test_experiments.py b/tests/unit/command/test_experiments.py index 61f6947330..2c09cc08f2 100644 --- a/tests/unit/command/test_experiments.py +++ b/tests/unit/command/test_experiments.py @@ -2,6 +2,7 @@ from datetime import datetime import pytest +import textwrap from dvc.cli import parse_args from dvc.command.experiments import ( @@ -447,14 +448,12 @@ def test_show_experiments_md(capsys): ) cap = capsys.readouterr() - assert ( - "| Experiment | Created | bar | foo |" in cap.out - ) - assert ( - "|--------------|-----------|--------------------|-------|" in cap.out - ) - assert ( - "| workspace | | 0.9544670443829399 | 1 |" in cap.out + assert cap.out == textwrap.dedent( + """\ + | Experiment | Created | bar | foo | + |--------------|-----------|--------------------|-------| + | workspace | | 0.9544670443829399 | 1 |\n + """ ) From 8b5481b08cf47d0e40fb15f2a313acb3edea6abc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 14 Oct 2021 14:47:48 +0000 Subject: [PATCH 08/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/unit/command/test_experiments.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/command/test_experiments.py b/tests/unit/command/test_experiments.py index 2c09cc08f2..3b00c47167 100644 --- a/tests/unit/command/test_experiments.py +++ b/tests/unit/command/test_experiments.py @@ -1,8 +1,8 @@ import csv +import textwrap from datetime import datetime import pytest -import textwrap from dvc.cli import parse_args from dvc.command.experiments import ( From f36cded6ebafe829be559fddc2d2e4f2aa183f4c Mon Sep 17 00:00:00 2001 From: David de la Iglesia Castro Date: Thu, 14 Oct 2021 17:08:14 +0200 Subject: [PATCH 09/11] Update experiments.py --- dvc/command/experiments.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dvc/command/experiments.py b/dvc/command/experiments.py index 4816718bc9..263185b8ba 100644 --- a/dvc/command/experiments.py +++ b/dvc/command/experiments.py @@ -1002,7 +1002,7 @@ def add_parser(subparsers, parent_parser): action="store_true", default=False, dest="markdown", - help="Print output in Markdown format.", + help="Print output in Markdown table format.", ) experiments_show_parser.add_argument( "--precision", From 773c29a52fc16e4f0de5f5d747dfa4c355316248 Mon Sep 17 00:00:00 2001 From: David de la Iglesia Castro Date: Tue, 19 Oct 2021 22:40:00 +0200 Subject: [PATCH 10/11] Apply suggestions from code review Co-authored-by: Saugat Pachhai --- dvc/command/experiments.py | 2 +- tests/unit/command/test_compat_flag.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/dvc/command/experiments.py b/dvc/command/experiments.py index 263185b8ba..d7042872ec 100644 --- a/dvc/command/experiments.py +++ b/dvc/command/experiments.py @@ -1002,7 +1002,7 @@ def add_parser(subparsers, parent_parser): action="store_true", default=False, dest="markdown", - help="Print output in Markdown table format.", + help="Show tabulated output in the Markdown format (GFM).", ) experiments_show_parser.add_argument( "--precision", diff --git a/tests/unit/command/test_compat_flag.py b/tests/unit/command/test_compat_flag.py index 6672275e8a..524eedce57 100644 --- a/tests/unit/command/test_compat_flag.py +++ b/tests/unit/command/test_compat_flag.py @@ -21,7 +21,7 @@ def _id_gen(val) -> str: (["experiments", "show", "--show-json"], "json"), (["experiments", "show", "--show-csv"], "csv"), (["experiments", "show", "--show-md"], "markdown"), - (["experiments", "show", "--md"], "markdown"), + (["experiments", "show", "--show-md"], "markdown"), (["ls", "--show-json", "."], "json"), (["metrics", "diff", "--show-json"], "json"), (["metrics", "diff", "--show-md"], "markdown"), @@ -37,5 +37,4 @@ def test_backward_compat_flags(args, key): """Test support for --show-csv/--show-json/--show-md flags.""" cli_args = parse_args(args) d = vars(cli_args) - print(d) assert d[key] is True From 63a350ae998ee0501d9d1a935acb8d0d584f5cc6 Mon Sep 17 00:00:00 2001 From: Saugat Pachhai Date: Wed, 20 Oct 2021 09:50:45 +0545 Subject: [PATCH 11/11] Update tests/unit/command/test_compat_flag.py --- tests/unit/command/test_compat_flag.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/command/test_compat_flag.py b/tests/unit/command/test_compat_flag.py index 524eedce57..e01469078e 100644 --- a/tests/unit/command/test_compat_flag.py +++ b/tests/unit/command/test_compat_flag.py @@ -21,7 +21,6 @@ def _id_gen(val) -> str: (["experiments", "show", "--show-json"], "json"), (["experiments", "show", "--show-csv"], "csv"), (["experiments", "show", "--show-md"], "markdown"), - (["experiments", "show", "--show-md"], "markdown"), (["ls", "--show-json", "."], "json"), (["metrics", "diff", "--show-json"], "json"), (["metrics", "diff", "--show-md"], "markdown"),