Skip to content
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

Complete type annotations #399

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Next Next commit
feat: Add type annotations to test_linear_expression.py
  • Loading branch information
FabianHofmann committed Dec 27, 2024
commit 8479e4e0b16ddce52e88167c1504c20792c59b4f
21 changes: 12 additions & 9 deletions test/test_linear_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
@author: fabian
"""

from typing import Any, List, Union

import numpy as np
import pandas as pd
import polars as pl
import pytest
import xarray as xr
from numpy.typing import NDArray
from xarray.testing import assert_equal

from linopy import LinearExpression, Model, merge
Expand All @@ -18,7 +21,7 @@


@pytest.fixture
def m():
def m() -> Model:
m = Model()

m.add_variables(pd.Series([0, 0]), 1, name="x")
Expand All @@ -33,35 +36,35 @@ def m():


@pytest.fixture
def x(m):
def x(m: Model) -> LinearExpression:
return m.variables["x"]


@pytest.fixture
def y(m):
def y(m: Model) -> LinearExpression:
return m.variables["y"]


@pytest.fixture
def z(m):
def z(m: Model) -> LinearExpression:
return m.variables["z"]


@pytest.fixture
def v(m):
def v(m: Model) -> LinearExpression:
return m.variables["v"]


@pytest.fixture
def u(m):
def u(m: Model) -> LinearExpression:
return m.variables["u"]


def test_empty_linexpr(m):
def test_empty_linexpr(m: Model) -> None:
LinearExpression(None, m)


def test_linexpr_with_wrong_data(m):
def test_linexpr_with_wrong_data(m: Model) -> None:
with pytest.raises(ValueError):
LinearExpression(xr.Dataset({"a": [1]}), m)

Expand All @@ -79,7 +82,7 @@ def test_linexpr_with_wrong_data(m):
LinearExpression(data, None)


def test_linexpr_with_helper_dims_as_coords(m):
def test_linexpr_with_helper_dims_as_coords(m: Model) -> None:
coords = [pd.Index([0], name="a"), pd.Index([1, 2], name=TERM_DIM)]
coeffs = xr.DataArray(np.array([[1, 2]]), coords=coords)
vars = xr.DataArray(np.array([[1, 2]]), coords=coords)
Expand Down