Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show audit info in runs.tabulate() #128

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading