Skip to content

Commit

Permalink
Show audit info in runs.tabulate() (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhuppmann authored Oct 24, 2024
1 parent 2785183 commit b982f47
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
9 changes: 7 additions & 2 deletions ixmp4/core/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,16 @@ def list(self, default_only: bool = True, **kwargs) -> list[Run]:
for r in self.backend.runs.list(default_only=default_only, **kwargs)
]

def tabulate(self, default_only: bool = True, **kwargs) -> pd.DataFrame:
def tabulate(
self, default_only: bool = True, audit_info: bool = False, **kwargs
) -> pd.DataFrame:
runs = self.backend.runs.tabulate(default_only=default_only, **kwargs)
runs["model"] = runs["model__id"].map(self.backend.models.map())
runs["scenario"] = runs["scenario__id"].map(self.backend.scenarios.map())
return runs[["id", "model", "scenario", "version", "is_default"]]
columns = ["model", "scenario", "version", "is_default"]
if audit_info:
columns += ["updated_at", "updated_by", "created_at", "created_by", "id"]
return runs[columns]


class RunMetaFacade(BaseFacade, UserDict):
Expand Down
12 changes: 8 additions & 4 deletions tests/core/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ def _expected_runs_table(*row_default):
rows = []
for i, default in enumerate(row_default, start=1):
if default is not None:
rows.append([i, "Model", "Scenario", i] + [default])
rows.append(["Model", "Scenario", i] + [default])

return pd.DataFrame(
rows, columns=["id", "model", "scenario", "version", "is_default"]
)
return pd.DataFrame(rows, columns=["model", "scenario", "version", "is_default"])


class TestCoreRun:
Expand Down Expand Up @@ -68,6 +66,12 @@ def test_run_versions(self, platform: ixmp4.Platform):
pd.DataFrame(_expected_runs_table(True, False)),
)

# using audit_info=True shows additional columns
audit_info = platform.runs.tabulate(default_only=False, audit_info=True)
for column in ["updated_at", "updated_by", "created_at", "created_by", "id"]:
assert column in audit_info.columns
pdt.assert_series_equal(audit_info.id, pd.Series([run1.id, run2.id], name="id"))

# default version can be retrieved directly
run = platform.runs.get("Model", "Scenario")
assert run1.id == run.id
Expand Down

0 comments on commit b982f47

Please sign in to comment.