Skip to content

Commit

Permalink
exp show: Make --drop and --keep accept single arg
Browse files Browse the repository at this point in the history
Fix html-drop interaction
  • Loading branch information
daavoo committed Dec 27, 2021
1 parent 11c1e12 commit 0b00d17
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 34 deletions.
48 changes: 23 additions & 25 deletions dvc/command/experiments/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def show_experiments(
kwargs.get("iso"),
)
if keep:
td.protect(*keep)
td.protect(keep)

for col in ("State", "Executor"):
if td.is_empty(col):
Expand Down Expand Up @@ -382,10 +382,14 @@ def show_experiments(
if kwargs.get("only_changed", False) or html:
td.drop_duplicates("cols")

if html:
if drop is None:
drop = "Created"
else:
drop += "|Created"

if drop is not None:
if html:
drop.append("Created")
td.drop(*drop)
td.drop(drop)

html_args = {}
if html:
Expand All @@ -395,9 +399,7 @@ def show_experiments(
how="all",
subset=subset,
)
td.drop_duplicates(
"rows",
subset=subset)
td.drop_duplicates("rows", subset=subset)
td.column("Experiment")[:] = [
# remove tree characters
str(x).encode("ascii", "ignore").strip().decode()
Expand Down Expand Up @@ -537,18 +539,23 @@ def add_parser(experiments_subparsers, parent_parser):
help="Do not pipe output into a pager.",
)
experiments_show_parser.add_argument(
"--keep",
action="append",
default=[],
help="Always show the specified columns in output table.",
metavar="<column_list>",
"--only-changed",
action="store_true",
default=False,
help=(
"Only show metrics/params with values varying "
"across the selected experiments."
),
)
experiments_show_parser.add_argument(
"--drop",
action="append",
default=[],
help="Remove the specified columns from output table.",
metavar="<column_list>",
help="Remove the columns matching the specified regex pattern.",
metavar="<regex_pattern>",
)
experiments_show_parser.add_argument(
"--keep",
help="Preserve the columns matching the specified regex pattern.",
metavar="<regex_pattern>",
)
experiments_show_parser.add_argument(
"--param-deps",
Expand Down Expand Up @@ -607,15 +614,6 @@ def add_parser(experiments_subparsers, parent_parser):
),
metavar="<n>",
)
experiments_show_parser.add_argument(
"--only-changed",
action="store_true",
default=False,
help=(
"Only show metrics/params with values varying "
"across the selected experiments."
),
)
experiments_show_parser.add_argument(
"--html",
action="store_true",
Expand Down
27 changes: 18 additions & 9 deletions tests/func/experiments/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ def test_show_filter(
cap = capsys.readouterr()
assert "Created" not in cap.out

capsys.readouterr()
assert main(["exp", "show", "--drop=Created|Experiment"]) == 0
cap = capsys.readouterr()
assert "Created" not in cap.out
assert "Experiment" not in cap.out


def test_show_multiple_commits(tmp_dir, scm, dvc, exp_stage):
init_rev = scm.get_rev()
Expand Down Expand Up @@ -554,24 +560,22 @@ def test_show_parallel_coordinates(tmp_dir, dvc, scm, mocker):
kwargs = show_experiments.call_args[1]

html_text = (tmp_dir / "dvc_plots" / "index.html").read_text()
assert all(rev in html_text for rev in ["workspace", "master", "[exp-"])
assert all(rev in html_text for rev in ["workspace", "master"])
assert "[exp-" not in html_text

assert (
'{"label": "metrics.yaml:foo", "values": [2.0, 1.0, 2.0]}' in html_text
)
assert (
'{"label": "params.yaml:foo", "values": [2.0, 1.0, 2.0]}' in html_text
)
assert '"line": {"color": [2, 1, 0]' in html_text
assert '{"label": "metrics.yaml:foo", "values": [2.0, 1.0]}' in html_text
assert '{"label": "params.yaml:foo", "values": [2.0, 1.0]}' in html_text
assert '"line": {"color": [1, 0]' in html_text
assert '"label": "metrics.yaml:bar"' not in html_text
assert '"label": "Created"' not in html_text

assert (
main(["exp", "show", "--html", "--sort-by", "metrics.yaml:foo"]) == 0
)
kwargs = show_experiments.call_args[1]

html_text = (tmp_dir / "dvc_plots" / "index.html").read_text()
assert '"line": {"color": [2.0, 1.0, 2.0]' in html_text
assert '"line": {"color": [2.0, 1.0]' in html_text

assert main(["exp", "show", "--html", "--out", "experiments"]) == 0
kwargs = show_experiments.call_args[1]
Expand All @@ -588,3 +592,8 @@ def test_show_parallel_coordinates(tmp_dir, dvc, scm, mocker):
assert main(["exp", "show", "--html"]) == 0
html_text = (tmp_dir / "dvc_plots" / "index.html").read_text()
assert '{"label": "foobar", "values": [2.0, null, null]}' in html_text

assert main(["exp", "show", "--html", "--drop", "foobar"]) == 0
html_text = (tmp_dir / "dvc_plots" / "index.html").read_text()
assert '"label": "Created"' not in html_text
assert '"label": "foobar"' not in html_text

0 comments on commit 0b00d17

Please sign in to comment.