Skip to content

Commit 79b2c14

Browse files
committed
Remove pointless indexsets.tabulate parameter
1 parent c18ed42 commit 79b2c14

File tree

8 files changed

+25
-79
lines changed

8 files changed

+25
-79
lines changed

ixmp4/core/optimization/indexset.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ def list(self, name: str | None = None) -> list[IndexSet]:
113113
for i in indexsets
114114
]
115115

116-
def tabulate(
117-
self, name: str | None = None, include_data: bool = False
118-
) -> pd.DataFrame:
116+
def tabulate(self, name: str | None = None) -> pd.DataFrame:
119117
return self.backend.optimization.indexsets.tabulate(
120-
run_id=self._run.id, name=name, include_data=include_data
118+
run_id=self._run.id, name=name
121119
)

ixmp4/data/abstract/optimization/indexset.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,11 @@ def list(self, **kwargs: Unpack["EnumerateKwargs"]) -> list[IndexSet]:
105105
"""
106106
...
107107

108-
def tabulate(
109-
self, *, include_data: bool = False, **kwargs: Unpack["EnumerateKwargs"]
110-
) -> pd.DataFrame:
108+
def tabulate(self, **kwargs: Unpack["EnumerateKwargs"]) -> pd.DataFrame:
111109
r"""Tabulate IndexSets by specified criteria.
112110
113111
Parameters
114112
----------
115-
include_data : bool, optional
116-
Whether to load all IndexSet data, which reduces loading speed. Defaults to
117-
`False`.
118113
\*\*kwargs: any
119114
Any filter parameters as specified in
120115
`ixmp4.data.db.optimization.indexset.filter.OptimizationIndexSetFilter`.

ixmp4/data/api/optimization/indexset.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,10 @@ def list(
6666
return super()._list(json=json)
6767

6868
def tabulate(
69-
self,
70-
include_data: bool = False,
71-
**kwargs: Unpack[abstract.optimization.EnumerateKwargs],
69+
self, **kwargs: Unpack[abstract.optimization.EnumerateKwargs]
7270
) -> pd.DataFrame:
7371
json = cast(abstract.annotations.OptimizationFilterAlias, kwargs)
74-
return super()._tabulate(json=json, params={"include_data": include_data})
72+
return super()._tabulate(json=json)
7573

7674
def add_data(
7775
self,

ixmp4/data/db/base.py

-2
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ def tabulate(self, *args: Any, _raw: bool = False, **kwargs: Any) -> pd.DataFram
290290

291291
class PaginateKwargs(TypedDict):
292292
_filter: filters.BaseFilter
293-
include_data: NotRequired[bool]
294293
join_parameters: NotRequired[bool | None]
295294
join_runs: NotRequired[bool | None]
296295
join_run_index: NotRequired[bool | None]
@@ -299,7 +298,6 @@ class PaginateKwargs(TypedDict):
299298

300299
class EnumerateKwargs(TypedDict):
301300
_filter: filters.BaseFilter
302-
include_data: NotRequired[bool]
303301
join_parameters: NotRequired[bool | None]
304302
join_runs: NotRequired[bool | None]
305303
join_run_index: NotRequired[bool | None]

ixmp4/data/db/optimization/indexset/repository.py

+2-15
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,8 @@ def list(self, **kwargs: Unpack["base.EnumerateKwargs"]) -> list[IndexSet]:
6666
return super().list(**kwargs)
6767

6868
@guard("view")
69-
def tabulate(
70-
self, *, include_data: bool = False, **kwargs: Unpack["base.EnumerateKwargs"]
71-
) -> pd.DataFrame:
72-
if not include_data:
73-
return (
74-
super().tabulate(**kwargs).rename(columns={"_data_type": "data_type"})
75-
)
76-
else:
77-
result = super().tabulate(**kwargs).drop(labels="_data_type", axis=1)
78-
result.insert(
79-
loc=0,
80-
column="data",
81-
value=[indexset.data for indexset in self.list(**kwargs)],
82-
)
83-
return result
69+
def tabulate(self, **kwargs: Unpack["base.EnumerateKwargs"]) -> pd.DataFrame:
70+
return super().tabulate(**kwargs).rename(columns={"_data_type": "data_type"})
8471

8572
@guard("edit")
8673
def add_data(

ixmp4/server/rest/optimization/indexset.py

-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class DataInput(BaseModel):
2929
def query(
3030
filter: OptimizationIndexSetFilter = Body(OptimizationIndexSetFilter()),
3131
table: bool = Query(False),
32-
include_data: bool = Query(False),
3332
pagination: Pagination = Depends(),
3433
backend: Backend = Depends(deps.get_backend),
3534
) -> EnumerationOutput[IndexSet]:
@@ -39,7 +38,6 @@ def query(
3938
limit=pagination.limit,
4039
offset=pagination.offset,
4140
table=bool(table),
42-
include_data=bool(include_data),
4341
),
4442
total=backend.optimization.indexsets.count(_filter=filter),
4543
pagination=pagination,

tests/core/test_optimization_indexset.py

+9-23
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from ..utils import create_indexsets_for_run
1010

1111

12-
def df_from_list(indexsets: list[IndexSet], include_data: bool = False) -> pd.DataFrame:
12+
def df_from_list(indexsets: list[IndexSet]) -> pd.DataFrame:
1313
result = pd.DataFrame(
1414
# Order is important here to avoid utils.assert_unordered_equality,
1515
# which doesn't like lists
@@ -31,19 +31,14 @@ def df_from_list(indexsets: list[IndexSet], include_data: bool = False) -> pd.Da
3131
"created_by",
3232
],
3333
)
34-
if include_data:
35-
result.insert(
36-
loc=0, column="data", value=[indexset.data for indexset in indexsets]
37-
)
38-
else:
39-
result.insert(
40-
loc=0,
41-
column="data_type",
42-
value=[
43-
type(indexset.data[0]).__name__ if indexset.data != [] else None
44-
for indexset in indexsets
45-
],
46-
)
34+
result.insert(
35+
loc=0,
36+
column="data_type",
37+
value=[
38+
type(indexset.data[0]).__name__ if indexset.data != [] else None
39+
for indexset in indexsets
40+
],
41+
)
4742
return result
4843

4944

@@ -143,15 +138,6 @@ def test_tabulate_indexsets(self, platform: ixmp4.Platform) -> None:
143138
result = run.optimization.indexsets.tabulate(name="Indexset 2")
144139
pdt.assert_frame_equal(expected, result)
145140

146-
# Test tabulating including the data
147-
expected = df_from_list(indexsets=[indexset_2], include_data=True)
148-
pdt.assert_frame_equal(
149-
expected,
150-
run.optimization.indexsets.tabulate(
151-
name=indexset_2.name, include_data=True
152-
),
153-
)
154-
155141
def test_indexset_docs(self, platform: ixmp4.Platform) -> None:
156142
run = platform.runs.create("Model", "Scenario")
157143
(indexset_1,) = tuple(

tests/data/test_optimization_indexset.py

+9-23
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from ..utils import create_indexsets_for_run
1010

1111

12-
def df_from_list(indexsets: list[IndexSet], include_data: bool = False) -> pd.DataFrame:
12+
def df_from_list(indexsets: list[IndexSet]) -> pd.DataFrame:
1313
result = pd.DataFrame(
1414
# Order is important here to avoid utils.assert_unordered_equality,
1515
# which doesn't like lists
@@ -31,19 +31,14 @@ def df_from_list(indexsets: list[IndexSet], include_data: bool = False) -> pd.Da
3131
"created_by",
3232
],
3333
)
34-
if include_data:
35-
result.insert(
36-
loc=0, column="data", value=[indexset.data for indexset in indexsets]
37-
)
38-
else:
39-
result.insert(
40-
loc=0,
41-
column="data_type",
42-
value=[
43-
type(indexset.data[0]).__name__ if indexset.data != [] else None
44-
for indexset in indexsets
45-
],
46-
)
34+
result.insert(
35+
loc=0,
36+
column="data_type",
37+
value=[
38+
type(indexset.data[0]).__name__ if indexset.data != [] else None
39+
for indexset in indexsets
40+
],
41+
)
4742
return result
4843

4944

@@ -138,15 +133,6 @@ def test_tabulate_indexsets(self, platform: ixmp4.Platform) -> None:
138133
expected, platform.backend.optimization.indexsets.tabulate(run_id=run_2.id)
139134
)
140135

141-
# Test tabulating including the data
142-
expected = df_from_list(indexsets=[indexset_2], include_data=True)
143-
pdt.assert_frame_equal(
144-
expected,
145-
platform.backend.optimization.indexsets.tabulate(
146-
name=indexset_2.name, include_data=True
147-
),
148-
)
149-
150136
def test_add_data(self, platform: ixmp4.Platform) -> None:
151137
test_data = ["foo", "bar"]
152138
run = platform.backend.runs.create("Model", "Scenario")

0 commit comments

Comments
 (0)