Skip to content

Commit

Permalink
Clean up various small things
Browse files Browse the repository at this point in the history
  • Loading branch information
glatterf42 committed Nov 22, 2024
1 parent 13753e5 commit a8ae436
Show file tree
Hide file tree
Showing 35 changed files with 68 additions and 221 deletions.
13 changes: 2 additions & 11 deletions ixmp4/data/abstract/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ class Docs(base.BaseModel, Protocol):
# )


class DocsRepository(
base.Retriever,
base.Deleter,
base.Enumerator,
Protocol,
):
class DocsRepository(base.Retriever, base.Deleter, base.Enumerator, Protocol):
def get(self, dimension_id: int) -> Docs:
"""Retrieve the documentation of an object of any dimension.
Expand Down Expand Up @@ -84,11 +79,7 @@ def delete(self, dimension_id: int) -> None:
"""
...

def list(
self,
*,
dimension_id: int | None = None,
) -> list[Docs]:
def list(self, *, dimension_id: int | None = None) -> list[Docs]:
"""Lists documentations.
Parameters
Expand Down
8 changes: 2 additions & 6 deletions ixmp4/data/abstract/iamc/measurand.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ def get_or_create(self, variable_name: str, unit__id: int) -> Measurand:
except Measurand.NotFound:
return self.create(variable_name, unit__id)

def list(
self,
) -> list[Measurand]: ...
def list(self) -> list[Measurand]: ...

def tabulate(
self,
) -> pd.DataFrame: ...
def tabulate(self) -> pd.DataFrame: ...
15 changes: 3 additions & 12 deletions ixmp4/data/abstract/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,7 @@ class RunMetaEntryRepository(
base.BulkDeleter,
Protocol,
):
def create(
self,
run__id: int,
key: str,
value: MetaValue,
) -> RunMetaEntry:
def create(self, run__id: int, key: str, value: MetaValue) -> RunMetaEntry:
"""Creates a meta indicator entry for a run.
Parameters
Expand Down Expand Up @@ -165,9 +160,7 @@ def delete(self, id: int) -> None:
...

def list(
self,
join_run_index: bool = False,
**kwargs: Unpack[EnumerateKwargs],
self, join_run_index: bool = False, **kwargs: Unpack[EnumerateKwargs]
) -> list[RunMetaEntry]:
r"""Lists run's meta indicator entries by specified criteria.
Expand All @@ -187,9 +180,7 @@ def list(
...

def tabulate(
self,
join_run_index: bool = False,
**kwargs: Unpack[EnumerateKwargs],
self, join_run_index: bool = False, **kwargs: Unpack[EnumerateKwargs]
) -> pd.DataFrame:
r"""Tabulates run's meta indicator entries by specified criteria.
Expand Down
16 changes: 3 additions & 13 deletions ixmp4/data/abstract/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,7 @@ def get(self, name: str) -> Region:
"""
...

def get_or_create(
self,
name: str,
hierarchy: str | None = None,
) -> Region:
def get_or_create(self, name: str, hierarchy: str | None = None) -> Region:
try:
region = self.get(name)
except Region.NotFound:
Expand All @@ -127,10 +123,7 @@ def get_or_create(
else:
return region

def list(
self,
**kwargs: Unpack[EnumerateKwargs],
) -> list[Region]:
def list(self, **kwargs: Unpack[EnumerateKwargs]) -> list[Region]:
r"""Lists regions by specified criteria.
Parameters
Expand All @@ -146,10 +139,7 @@ def list(
"""
...

def tabulate(
self,
**kwargs: Unpack[EnumerateKwargs],
) -> pd.DataFrame:
def tabulate(self, **kwargs: Unpack[EnumerateKwargs]) -> pd.DataFrame:
r"""Tabulate regions by specified criteria.
Parameters
Expand Down
35 changes: 6 additions & 29 deletions ixmp4/data/abstract/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ class RunRepository(
base.Enumerator,
Protocol,
):
def create(
self,
model_name: str,
scenario_name: str,
) -> Run:
def create(self, model_name: str, scenario_name: str) -> Run:
"""Creates a run with an incremented version number or version=1 if no versions
exist. Will automatically create the models and scenarios if they don't exist
yet.
Expand All @@ -74,12 +70,7 @@ def create(
"""
...

def get(
self,
model_name: str,
scenario_name: str,
version: int,
) -> Run:
def get(self, model_name: str, scenario_name: str, version: int) -> Run:
"""Retrieves a run.
Parameters
Expand All @@ -103,11 +94,7 @@ def get(
"""
...

def get_or_create(
self,
model_name: str,
scenario_name: str,
) -> Run:
def get_or_create(self, model_name: str, scenario_name: str) -> Run:
"""Tries to retrieve a run's default version
and creates it if it was not found.
Expand All @@ -128,11 +115,7 @@ def get_or_create(
except Run.NoDefaultVersion:
return self.create(model_name, scenario_name)

def get_default_version(
self,
model_name: str,
scenario_name: str,
) -> Run:
def get_default_version(self, model_name: str, scenario_name: str) -> Run:
"""Retrieves a run's default version.
Parameters
Expand All @@ -154,10 +137,7 @@ def get_default_version(
"""
...

def list(
self,
**kwargs: Unpack[EnumerateKwargs],
) -> list[Run]:
def list(self, **kwargs: Unpack[EnumerateKwargs]) -> list[Run]:
r"""Lists runs by specified criteria.
Parameters
Expand All @@ -173,10 +153,7 @@ def list(
"""
...

def tabulate(
self,
**kwargs: Unpack[EnumerateKwargs],
) -> pd.DataFrame:
def tabulate(self, **kwargs: Unpack[EnumerateKwargs]) -> pd.DataFrame:
r"""Tabulate runs by specified criteria.
Parameters
Expand Down
10 changes: 2 additions & 8 deletions ixmp4/data/abstract/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ def delete(self, id: int) -> None:
"""
...

def list(
self,
**kwargs: Unpack[EnumerateKwargs],
) -> list[Unit]:
def list(self, **kwargs: Unpack[EnumerateKwargs]) -> list[Unit]:
r"""Lists units by specified criteria.
Parameters
Expand All @@ -141,10 +138,7 @@ def list(
"""
...

def tabulate(
self,
**kwargs: Unpack[EnumerateKwargs],
) -> pd.DataFrame:
def tabulate(self, **kwargs: Unpack[EnumerateKwargs]) -> pd.DataFrame:
r"""Tabulate units by specified criteria.
Parameters
Expand Down
10 changes: 6 additions & 4 deletions ixmp4/data/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ class DataFrameDict(TypedDict):
abstract.annotations.PrimitiveTypes
| datetime
| dict[str, Any]
# TODO should be able to remove this once PR#122 is merged
| list[float | int | str]
| list[float]
| list[int]
| list[str]
| None
]
]
Expand Down Expand Up @@ -110,8 +111,9 @@ class DataFrame(PydanticBaseModel):
| float
| str
| dict[str, Any]
# TODO should be able to remove this once PR#122 is merged
| list[float | int | str]
| list[float]
| list[int]
| list[str]
| None
]
]
Expand Down
7 changes: 1 addition & 6 deletions ixmp4/data/api/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ class RunMetaEntryRepository(
model_class = RunMetaEntry
prefix = "meta/"

def create(
self,
run__id: int,
key: str,
value: abstract.MetaValue,
) -> RunMetaEntry:
def create(self, run__id: int, key: str, value: abstract.MetaValue) -> RunMetaEntry:
return super().create(run__id=run__id, key=key, value=value)

def get(self, run__id: int, key: str) -> RunMetaEntry:
Expand Down
5 changes: 1 addition & 4 deletions ixmp4/data/api/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ def __init__(self, *args: Unpack[tuple["RestBackend"]]) -> None:
super().__init__(*args)
self.docs = ModelDocsRepository(self.backend)

def create(
self,
name: str,
) -> Model:
def create(self, name: str) -> Model:
return super().create(name=name)

def get(self, name: str) -> Model:
Expand Down
6 changes: 2 additions & 4 deletions ixmp4/data/api/optimization/equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,13 @@ def get_by_id(self, id: int) -> Equation:
return Equation(**res)

def list(
self,
**kwargs: Unpack[abstract.optimization.EnumerateKwargs],
self, **kwargs: Unpack[abstract.optimization.EnumerateKwargs]
) -> Iterable[Equation]:
json = cast(abstract.annotations.OptimizationFilterAlias, kwargs)
return super()._list(json=json)

def tabulate(
self,
**kwargs: Unpack[abstract.optimization.EnumerateKwargs],
self, **kwargs: Unpack[abstract.optimization.EnumerateKwargs]
) -> pd.DataFrame:
json = cast(abstract.annotations.OptimizationFilterAlias, kwargs)
return super()._tabulate(json=json)
Expand Down
11 changes: 3 additions & 8 deletions ixmp4/data/api/optimization/indexset.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class IndexSet(base.BaseModel):

id: int
name: str
data: float | int | str | list[int | float | str] | None
data: float | int | str | list[int] | list[float] | list[str] | None
run__id: int

created_at: datetime | None
Expand All @@ -48,11 +48,7 @@ def __init__(self, *args: Unpack[tuple["RestBackend"]]) -> None:
super().__init__(*args)
self.docs = IndexSetDocsRepository(self.backend)

def create(
self,
run_id: int,
name: str,
) -> IndexSet:
def create(self, run_id: int, name: str) -> IndexSet:
return super().create(run_id=run_id, name=name)

def get(self, run_id: int, name: str) -> IndexSet:
Expand All @@ -64,8 +60,7 @@ def enumerate(
return super().enumerate(**kwargs)

def list(
self,
**kwargs: Unpack[abstract.optimization.EnumerateKwargs],
self, **kwargs: Unpack[abstract.optimization.EnumerateKwargs]
) -> list[IndexSet]:
json = cast(abstract.annotations.OptimizationFilterAlias, kwargs)
return super()._list(json=json)
Expand Down
6 changes: 2 additions & 4 deletions ixmp4/data/api/optimization/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,13 @@ def get_by_id(self, id: int) -> Parameter:
return Parameter(**res)

def list(
self,
**kwargs: Unpack[abstract.optimization.EnumerateKwargs],
self, **kwargs: Unpack[abstract.optimization.EnumerateKwargs]
) -> Iterable[Parameter]:
json = cast(abstract.annotations.OptimizationFilterAlias, kwargs)
return super()._list(json=json)

def tabulate(
self,
**kwargs: Unpack[abstract.optimization.EnumerateKwargs],
self, **kwargs: Unpack[abstract.optimization.EnumerateKwargs]
) -> pd.DataFrame:
json = cast(abstract.annotations.OptimizationFilterAlias, kwargs)
return super()._tabulate(json=json)
Expand Down
8 changes: 1 addition & 7 deletions ixmp4/data/api/optimization/scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,7 @@ def __init__(self, *args: Unpack[tuple["RestBackend"]]) -> None:
super().__init__(*args)
self.docs = ScalarDocsRepository(self.backend)

def create(
self,
name: str,
value: float,
unit_name: str,
run_id: int,
) -> Scalar:
def create(self, name: str, value: float, unit_name: str, run_id: int) -> Scalar:
return super().create(
name=name, value=value, unit_name=unit_name, run_id=run_id
)
Expand Down
14 changes: 3 additions & 11 deletions ixmp4/data/api/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ def __init__(self, *args: Unpack[tuple["RestBackend"]]) -> None:
super().__init__(*args)
self.docs = RegionDocsRepository(self.backend)

def create(
self,
name: str,
hierarchy: str,
) -> Region:
def create(self, name: str, hierarchy: str) -> Region:
return super().create(name=name, hierarchy=hierarchy)

def delete(self, id: int) -> None:
Expand All @@ -72,16 +68,12 @@ def enumerate(
) -> list[Region] | pd.DataFrame:
return super().enumerate(**kwargs)

def list(
self,
**kwargs: Unpack[abstract.region.EnumerateKwargs],
) -> list[Region]:
def list(self, **kwargs: Unpack[abstract.region.EnumerateKwargs]) -> list[Region]:
json = cast(abstract.annotations.IamcObjectFilterAlias, kwargs)
return super()._list(json=json)

def tabulate(
self,
**kwargs: Unpack[abstract.region.EnumerateKwargs],
self, **kwargs: Unpack[abstract.region.EnumerateKwargs]
) -> pd.DataFrame:
json = cast(abstract.annotations.IamcObjectFilterAlias, kwargs)
return super()._tabulate(json=json)
10 changes: 2 additions & 8 deletions ixmp4/data/api/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,11 @@ def enumerate(
) -> list[Run] | pd.DataFrame:
return super().enumerate(**kwargs)

def list(
self,
**kwargs: Unpack[abstract.run.EnumerateKwargs],
) -> list[Run]:
def list(self, **kwargs: Unpack[abstract.run.EnumerateKwargs]) -> list[Run]:
json = cast(JsonType, kwargs)
return super()._list(json=json)

def tabulate(
self,
**kwargs: Unpack[abstract.run.EnumerateKwargs],
) -> pd.DataFrame:
def tabulate(self, **kwargs: Unpack[abstract.run.EnumerateKwargs]) -> pd.DataFrame:
json = cast(JsonType, kwargs)
return super()._tabulate(json=json)

Expand Down
Loading

0 comments on commit a8ae436

Please sign in to comment.