From bc61725eecb26a77f2b69176c0f3032853ba012c Mon Sep 17 00:00:00 2001 From: Fridolin Glatter Date: Wed, 27 Nov 2024 11:58:10 +0100 Subject: [PATCH] Remove pointless indexsets.tabulate parameter --- ixmp4/core/optimization/indexset.py | 6 ++-- ixmp4/data/abstract/optimization/indexset.py | 7 +--- ixmp4/data/api/optimization/indexset.py | 6 ++-- ixmp4/data/db/base.py | 2 -- .../db/optimization/indexset/repository.py | 17 ++-------- ixmp4/server/rest/optimization/indexset.py | 2 -- tests/core/test_optimization_indexset.py | 32 ++++++------------- tests/data/test_optimization_indexset.py | 32 ++++++------------- 8 files changed, 25 insertions(+), 79 deletions(-) diff --git a/ixmp4/core/optimization/indexset.py b/ixmp4/core/optimization/indexset.py index cd901150..36a3fc5f 100644 --- a/ixmp4/core/optimization/indexset.py +++ b/ixmp4/core/optimization/indexset.py @@ -113,9 +113,7 @@ def list(self, name: str | None = None) -> list[IndexSet]: for i in indexsets ] - def tabulate( - self, name: str | None = None, include_data: bool = False - ) -> pd.DataFrame: + def tabulate(self, name: str | None = None) -> pd.DataFrame: return self.backend.optimization.indexsets.tabulate( - run_id=self._run.id, name=name, include_data=include_data + run_id=self._run.id, name=name ) diff --git a/ixmp4/data/abstract/optimization/indexset.py b/ixmp4/data/abstract/optimization/indexset.py index 82feea2d..cfacc96b 100644 --- a/ixmp4/data/abstract/optimization/indexset.py +++ b/ixmp4/data/abstract/optimization/indexset.py @@ -105,16 +105,11 @@ def list(self, **kwargs: Unpack["EnumerateKwargs"]) -> list[IndexSet]: """ ... - def tabulate( - self, *, include_data: bool = False, **kwargs: Unpack["EnumerateKwargs"] - ) -> pd.DataFrame: + def tabulate(self, **kwargs: Unpack["EnumerateKwargs"]) -> pd.DataFrame: r"""Tabulate IndexSets by specified criteria. Parameters ---------- - include_data : bool, optional - Whether to load all IndexSet data, which reduces loading speed. Defaults to - `False`. \*\*kwargs: any Any filter parameters as specified in `ixmp4.data.db.optimization.indexset.filter.OptimizationIndexSetFilter`. diff --git a/ixmp4/data/api/optimization/indexset.py b/ixmp4/data/api/optimization/indexset.py index 7e3b4a8c..0feb91c9 100644 --- a/ixmp4/data/api/optimization/indexset.py +++ b/ixmp4/data/api/optimization/indexset.py @@ -66,12 +66,10 @@ def list( return super()._list(json=json) def tabulate( - self, - include_data: bool = False, - **kwargs: Unpack[abstract.optimization.EnumerateKwargs], + self, **kwargs: Unpack[abstract.optimization.EnumerateKwargs] ) -> pd.DataFrame: json = cast(abstract.annotations.OptimizationFilterAlias, kwargs) - return super()._tabulate(json=json, params={"include_data": include_data}) + return super()._tabulate(json=json) def add_data( self, diff --git a/ixmp4/data/db/base.py b/ixmp4/data/db/base.py index 491c8323..8d26079a 100644 --- a/ixmp4/data/db/base.py +++ b/ixmp4/data/db/base.py @@ -299,7 +299,6 @@ def tabulate(self, *args: Any, _raw: bool = False, **kwargs: Any) -> pd.DataFram class PaginateKwargs(TypedDict): _filter: filters.BaseFilter - include_data: NotRequired[bool] join_parameters: NotRequired[bool | None] join_runs: NotRequired[bool | None] join_run_index: NotRequired[bool | None] @@ -308,7 +307,6 @@ class PaginateKwargs(TypedDict): class EnumerateKwargs(TypedDict): _filter: filters.BaseFilter - include_data: NotRequired[bool] join_parameters: NotRequired[bool | None] join_runs: NotRequired[bool | None] join_run_index: NotRequired[bool | None] diff --git a/ixmp4/data/db/optimization/indexset/repository.py b/ixmp4/data/db/optimization/indexset/repository.py index 32455dd1..c559ce23 100644 --- a/ixmp4/data/db/optimization/indexset/repository.py +++ b/ixmp4/data/db/optimization/indexset/repository.py @@ -66,21 +66,8 @@ def list(self, **kwargs: Unpack["base.EnumerateKwargs"]) -> list[IndexSet]: return super().list(**kwargs) @guard("view") - def tabulate( - self, *, include_data: bool = False, **kwargs: Unpack["base.EnumerateKwargs"] - ) -> pd.DataFrame: - if not include_data: - return ( - super().tabulate(**kwargs).rename(columns={"_data_type": "data_type"}) - ) - else: - result = super().tabulate(**kwargs).drop(labels="_data_type", axis=1) - result.insert( - loc=0, - column="data", - value=[indexset.data for indexset in self.list(**kwargs)], - ) - return result + def tabulate(self, **kwargs: Unpack["base.EnumerateKwargs"]) -> pd.DataFrame: + return super().tabulate(**kwargs).rename(columns={"_data_type": "data_type"}) @guard("edit") def add_data( diff --git a/ixmp4/server/rest/optimization/indexset.py b/ixmp4/server/rest/optimization/indexset.py index 97cda612..91d92956 100644 --- a/ixmp4/server/rest/optimization/indexset.py +++ b/ixmp4/server/rest/optimization/indexset.py @@ -29,7 +29,6 @@ class DataInput(BaseModel): def query( filter: OptimizationIndexSetFilter = Body(OptimizationIndexSetFilter()), table: bool = Query(False), - include_data: bool = Query(False), pagination: Pagination = Depends(), backend: Backend = Depends(deps.get_backend), ) -> EnumerationOutput[IndexSet]: @@ -39,7 +38,6 @@ def query( limit=pagination.limit, offset=pagination.offset, table=bool(table), - include_data=bool(include_data), ), total=backend.optimization.indexsets.count(_filter=filter), pagination=pagination, diff --git a/tests/core/test_optimization_indexset.py b/tests/core/test_optimization_indexset.py index a3a80a35..c6b949b5 100644 --- a/tests/core/test_optimization_indexset.py +++ b/tests/core/test_optimization_indexset.py @@ -9,7 +9,7 @@ from ..utils import create_indexsets_for_run -def df_from_list(indexsets: list[IndexSet], include_data: bool = False) -> pd.DataFrame: +def df_from_list(indexsets: list[IndexSet]) -> pd.DataFrame: result = pd.DataFrame( # Order is important here to avoid utils.assert_unordered_equality, # which doesn't like lists @@ -31,19 +31,14 @@ def df_from_list(indexsets: list[IndexSet], include_data: bool = False) -> pd.Da "created_by", ], ) - if include_data: - result.insert( - loc=0, column="data", value=[indexset.data for indexset in indexsets] - ) - else: - result.insert( - loc=0, - column="data_type", - value=[ - type(indexset.data[0]).__name__ if indexset.data != [] else None - for indexset in indexsets - ], - ) + result.insert( + loc=0, + column="data_type", + value=[ + type(indexset.data[0]).__name__ if indexset.data != [] else None + for indexset in indexsets + ], + ) return result @@ -143,15 +138,6 @@ def test_tabulate_indexsets(self, platform: ixmp4.Platform) -> None: result = run.optimization.indexsets.tabulate(name="Indexset 2") pdt.assert_frame_equal(expected, result) - # Test tabulating including the data - expected = df_from_list(indexsets=[indexset_2], include_data=True) - pdt.assert_frame_equal( - expected, - run.optimization.indexsets.tabulate( - name=indexset_2.name, include_data=True - ), - ) - def test_indexset_docs(self, platform: ixmp4.Platform) -> None: run = platform.runs.create("Model", "Scenario") (indexset_1,) = tuple( diff --git a/tests/data/test_optimization_indexset.py b/tests/data/test_optimization_indexset.py index 89e6f4d1..20e39311 100644 --- a/tests/data/test_optimization_indexset.py +++ b/tests/data/test_optimization_indexset.py @@ -9,7 +9,7 @@ from ..utils import create_indexsets_for_run -def df_from_list(indexsets: list[IndexSet], include_data: bool = False) -> pd.DataFrame: +def df_from_list(indexsets: list[IndexSet]) -> pd.DataFrame: result = pd.DataFrame( # Order is important here to avoid utils.assert_unordered_equality, # which doesn't like lists @@ -31,19 +31,14 @@ def df_from_list(indexsets: list[IndexSet], include_data: bool = False) -> pd.Da "created_by", ], ) - if include_data: - result.insert( - loc=0, column="data", value=[indexset.data for indexset in indexsets] - ) - else: - result.insert( - loc=0, - column="data_type", - value=[ - type(indexset.data[0]).__name__ if indexset.data != [] else None - for indexset in indexsets - ], - ) + result.insert( + loc=0, + column="data_type", + value=[ + type(indexset.data[0]).__name__ if indexset.data != [] else None + for indexset in indexsets + ], + ) return result @@ -138,15 +133,6 @@ def test_tabulate_indexsets(self, platform: ixmp4.Platform) -> None: expected, platform.backend.optimization.indexsets.tabulate(run_id=run_2.id) ) - # Test tabulating including the data - expected = df_from_list(indexsets=[indexset_2], include_data=True) - pdt.assert_frame_equal( - expected, - platform.backend.optimization.indexsets.tabulate( - name=indexset_2.name, include_data=True - ), - ) - def test_add_data(self, platform: ixmp4.Platform) -> None: test_data = ["foo", "bar"] run = platform.backend.runs.create("Model", "Scenario")