Skip to content

Fixed typing of arithmetic methods #454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ benchmark/notebooks/.ipynb_checkpoints
benchmark/scripts/__pycache__
benchmark/scripts/benchmarks-pypsa-eur/__pycache__
benchmark/scripts/leftovers/

# IDE
.idea/
1 change: 1 addition & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Upcoming Version
gap tolerance.
* Improve the mapping of termination conditions for the SCIP solver
* Treat GLPK's `integer undefined` status as not-OK
* Fixed variable/expression arithmetic methods so that they correctly handle types

Version 0.5.3
--------------
Expand Down
19 changes: 13 additions & 6 deletions linopy/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

if TYPE_CHECKING:
from linopy.constraints import Constraint
from linopy.expressions import LinearExpression
from linopy.expressions import LinearExpression, QuadraticExpression
from linopy.variables import Variable


Expand Down Expand Up @@ -994,13 +994,13 @@ def check_common_keys_values(list_of_dicts: list[dict[str, Any]]) -> bool:


def align(
*objects: LinearExpression | Variable | T_Alignable,
*objects: LinearExpression | QuadraticExpression | Variable | T_Alignable,
join: JoinOptions = "inner",
copy: bool = True,
indexes: Any = None,
exclude: str | Iterable[Hashable] = frozenset(),
fill_value: Any = dtypes.NA,
) -> tuple[LinearExpression | Variable | T_Alignable, ...]:
) -> tuple[LinearExpression | QuadraticExpression | Variable | T_Alignable, ...]:
"""
Given any number of Variables, Expressions, Dataset and/or DataArray objects,
returns new objects with aligned indexes and dimension sizes.
Expand Down Expand Up @@ -1055,13 +1055,13 @@ def align(


"""
from linopy.expressions import LinearExpression
from linopy.expressions import LinearExpression, QuadraticExpression
from linopy.variables import Variable

finisher: list[partial[Any] | Callable[[Any], Any]] = []
das: list[Any] = []
for obj in objects:
if isinstance(obj, LinearExpression):
if isinstance(obj, (LinearExpression, QuadraticExpression)):
finisher.append(partial(obj.__class__, model=obj.model))
das.append(obj.data)
elif isinstance(obj, Variable):
Expand Down Expand Up @@ -1090,7 +1090,14 @@ def align(
return tuple([f(da) for f, da in zip(finisher, aligned)])


LocT = TypeVar("LocT", "Dataset", "Variable", "LinearExpression", "Constraint")
LocT = TypeVar(
"LocT",
"Dataset",
"Variable",
"LinearExpression",
"QuadraticExpression",
"Constraint",
)


class LocIndexer(Generic[LocT]):
Expand Down
Loading
Loading