Skip to content

Commit 4494676

Browse files
committed
api: Add exp_show.
Closes #8775
1 parent b814531 commit 4494676

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

dvc/api/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
from .data import open # pylint: disable=redefined-builtin
44
from .data import get_url, read
5-
from .experiments import exp_save, make_checkpoint
5+
from .experiments import exp_save, exp_show, make_checkpoint
66
from .show import metrics_show, params_show
77

88
__all__ = [
99
"exp_save",
10+
"exp_show",
1011
"get_url",
1112
"make_checkpoint",
1213
"open",

dvc/api/experiments.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
from time import sleep
44
from typing import List, Optional
55

6+
from rich.text import Text
7+
68
from dvc.env import DVC_CHECKPOINT, DVC_ROOT
79
from dvc.repo import Repo
10+
from dvc.repo.experiments.show import tabulate
811
from dvc.stage.monitor import CheckpointTask
912

1013

@@ -69,3 +72,48 @@ def exp_save(
6972
return repo.experiments.save(
7073
name=name, force=force, include_untracked=include_untracked
7174
)
75+
76+
77+
def _postprocess(exp_rows):
78+
for exp_row in exp_rows.items():
79+
for k, v in exp_row.items():
80+
if isinstance(v, Text):
81+
v_str = str(v)
82+
try:
83+
exp_row[k] = float(v_str)
84+
except ValueError:
85+
exp_row[k] = v_str
86+
return exp_rows
87+
88+
89+
def exp_show( # noqa: PLR0913
90+
repo: Optional[str] = None,
91+
all_branches: bool = False,
92+
all_tags: bool = False,
93+
all_commits: bool = False,
94+
hide_queued: bool = False,
95+
hide_failed: bool = False,
96+
rev: Optional[str] = None,
97+
num: int = 1,
98+
sha: bool = False,
99+
param_deps: bool = False,
100+
fetch_running: bool = False,
101+
force: bool = False,
102+
):
103+
with Repo.open(repo) as _repo:
104+
experiments = _repo.experiments.show(
105+
all_branches=all_branches,
106+
all_tags=all_tags,
107+
all_commits=all_commits,
108+
hide_queued=hide_queued,
109+
hide_failed=hide_failed,
110+
revs=rev,
111+
num=num,
112+
sha_only=sha,
113+
param_deps=param_deps,
114+
fetch_running=fetch_running,
115+
force=force,
116+
)
117+
td, _ = tabulate(experiments, fill_value=None)
118+
119+
return _postprocess(td.as_dict())

dvc/repo/experiments/show.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def show(
6262

6363
def tabulate(
6464
baseline_states: Iterable["ExpState"],
65-
fill_value: str = "-",
65+
fill_value: Optional[str] = "-",
6666
error_value: str = "!",
6767
**kwargs,
6868
) -> Tuple["TabularData", Dict[str, Iterable[str]]]:

0 commit comments

Comments
 (0)