-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable remaining parameter tests (#86)
* Enable remaining parameter tests * Include optimization parameter api layer (#89) * Bump several dependency versions * Let api/column handle both tables and parameters * Make api-layer tests pass * Include optimization parameter core layer (#90) * Enable parameter core layer and test it * Fix things after rebase * Ensure all intended changes survive the rebase * Adapt data validation function for parameters * Allow tests to pass again
- Loading branch information
1 parent
efd1160
commit e9df9ee
Showing
19 changed files
with
926 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
Deleter, | ||
Enumerator, | ||
Lister, | ||
NameMixin, | ||
Retriever, | ||
Selecter, | ||
Tabulator, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,37 @@ | ||
import copy | ||
from typing import Any, ClassVar | ||
|
||
import pandas as pd | ||
from sqlalchemy.orm import validates | ||
|
||
from ixmp4 import db | ||
from ixmp4.data import types | ||
from ixmp4.data.abstract import optimization as abstract | ||
|
||
from .. import Column, base | ||
from .. import Column, base, utils | ||
|
||
|
||
class Parameter(base.BaseModel, base.OptimizationDataMixin, base.UniqueNameRunIDMixin): | ||
class Parameter(base.BaseModel): | ||
# NOTE: These might be mixin-able, but would require some abstraction | ||
NotFound: ClassVar = abstract.Parameter.NotFound | ||
NotUnique: ClassVar = abstract.Parameter.NotUnique | ||
DeletionPrevented: ClassVar = abstract.Parameter.DeletionPrevented | ||
|
||
# constrained_to_indexsets: ClassVar[list[str] | None] = None | ||
|
||
# TODO Same as in table/model.py | ||
columns: types.Mapped[list["Column"]] = db.relationship() # type: ignore | ||
run__id: types.RunId | ||
columns: types.Mapped[list["Column"]] = db.relationship() | ||
data: types.JsonDict = db.Column(db.JsonType, nullable=False, default={}) | ||
|
||
@validates("data") | ||
def validate_data(self, key, data: dict[str, Any]): | ||
data_frame: pd.DataFrame = pd.DataFrame.from_dict(data) | ||
data_frame_to_validate = data_frame.drop(columns=["values", "units"]) | ||
|
||
self._validate_data(data_frame=data_frame_to_validate, data=data) | ||
return data_frame.to_dict(orient="list") | ||
data_to_validate = copy.deepcopy(data) | ||
del data_to_validate["values"] | ||
del data_to_validate["units"] | ||
_ = utils.validate_data( | ||
key=key, | ||
data=data_to_validate, | ||
columns=self.columns, | ||
) | ||
return data | ||
|
||
__table_args__ = (db.UniqueConstraint("name", "run__id"),) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.