From b982f47610145b402b09af39529e9a19e0e93f41 Mon Sep 17 00:00:00 2001 From: Daniel Huppmann Date: Thu, 24 Oct 2024 16:13:09 +0200 Subject: [PATCH] Show audit info in `runs.tabulate()` (#128) --- ixmp4/core/run.py | 9 +++++++-- tests/core/test_run.py | 12 ++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/ixmp4/core/run.py b/ixmp4/core/run.py index 447deb81..bdd8ec93 100644 --- a/ixmp4/core/run.py +++ b/ixmp4/core/run.py @@ -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): diff --git a/tests/core/test_run.py b/tests/core/test_run.py index 24886bf0..b7cf0f3c 100644 --- a/tests/core/test_run.py +++ b/tests/core/test_run.py @@ -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: @@ -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