From 40d0f2ba9ba33c034de3ca26d4a3eb62b6a44c8b Mon Sep 17 00:00:00 2001 From: Daniel Huppmann Date: Thu, 24 Oct 2024 13:27:36 +0200 Subject: [PATCH 1/3] Add audit-info option to tabulate runs --- ixmp4/core/run.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 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): From 223f23ee557d6b53ec1f5d0bf360d3d2e4a4025a Mon Sep 17 00:00:00 2001 From: Daniel Huppmann Date: Thu, 24 Oct 2024 13:51:11 +0200 Subject: [PATCH 2/3] Update existing test --- tests/core/test_run.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/core/test_run.py b/tests/core/test_run.py index 24886bf0..8a3b84f9 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: From a5132dbf6794919a81e945bbf830f6ae590b86ba Mon Sep 17 00:00:00 2001 From: Daniel Huppmann Date: Thu, 24 Oct 2024 13:51:31 +0200 Subject: [PATCH 3/3] Add test for audit info in runs.tabulate() --- tests/core/test_run.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/core/test_run.py b/tests/core/test_run.py index 8a3b84f9..b7cf0f3c 100644 --- a/tests/core/test_run.py +++ b/tests/core/test_run.py @@ -66,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