Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ This project is licensed under the MIT License.
</th>
<th>Incomplete</th>
<th>Yes</th>
<th>No</th>
<th>Yes</th>
</tr>
</table>

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ tests = [
# pandapower
"networkx>=3.2.1",
"geopandas>=1.0.0",
"pandapower>=3.1.2",
]
dev = [
"ruff>=0.9.2",
Expand Down
2 changes: 1 addition & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"ruff-format": ["tests", "stubs"],
"mypy": ["tests", "stubs"],
"pyright": ["tests", "stubs"],
# "stubtest": ["--allowlist=stubtest_allowlist.txt"],
"stubtest": ["--allowlist=stubtest_allowlist.txt", "pandapower"],
"pytest": [],
}

Expand Down
39 changes: 39 additions & 0 deletions stubs/pandapower-stubs/_typing.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from collections.abc import Collection, Iterable, Mapping, MutableMapping
from typing import Any, Protocol, SupportsFloat, SupportsIndex, TypedDict, TypeVar, type_check_only
from typing_extensions import TypeAlias

import numpy as np

_T = TypeVar("_T", bound=Any)

# Wide primitives for input types
Bool: TypeAlias = bool | np.bool
Int: TypeAlias = SupportsIndex
Float: TypeAlias = SupportsFloat | Int

# Vector-related
ScalarOrVector: TypeAlias = _T | Collection[_T]
Array1D: TypeAlias = np.ndarray[tuple[int], np.dtype[_T]]
Array2D: TypeAlias = np.ndarray[tuple[int, int], np.dtype[_T]]

# File I/O related
@type_check_only
class FromJsonKwds(TypedDict, total=False): # keep inline with pandapower.file_io functions
convert: bool
encryption_key: str | None
elements_to_deserialize: Iterable[str] | None
keep_serialized_elements: bool
add_basic_std_types: bool
replace_elements: Mapping[str, str] | None
empty_dict_like_object: MutableMapping[str, Any] | None

@type_check_only
class SupportsToWkt(Protocol):
def to_wkt(self) -> str: ...

@type_check_only
class SupportsGeoInterface(Protocol):
@property
def __geo_interface__(self) -> dict[str, Any]: ... # values are arbitrary

ConvertibleToCRS: TypeAlias = str | int | tuple[str, str] | list[str] | dict[str, Any] | SupportsToWkt
23 changes: 19 additions & 4 deletions stubs/pandapower-stubs/auxiliary.pyi
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
import logging
from collections.abc import Iterable, Mapping, MutableMapping
from typing import Any, Final, Literal, NoReturn, SupportsFloat as Float, SupportsIndex as Int, TypeVar, overload
from typing_extensions import Self
from typing import Any, Final, Literal, NoReturn, TypeVar, overload
from typing_extensions import Self, deprecated

import geopandas as gpd
import numpy as np
import pandas as pd
from numpy.typing import ArrayLike, NDArray
from numpy.typing import ArrayLike, DTypeLike, NDArray
from shapely.geometry.base import BaseGeometry

from pandapower._typing import Float, Int
from pandapower.std_types import _StdTypes

_T = TypeVar("_T")
_KT = TypeVar("_KT")
_VT = TypeVar("_VT")

def log_to_level(msg: str, passed_logger: logging.Logger, level: str) -> None: ...
def version_check(package_name: str, level="UserWarning", ignore_not_installed: bool = False) -> None: ...
def soft_dependency_error(fct_name: str, required_packages: str | Iterable[str]) -> NoReturn: ...
def warn_and_fix_parameter_renaming(
old_parameter_name: str, new_parameter_name: str, new_parameter: _T, default_value: _T, category: Warning = ..., **kwargs: Any
old_parameter_name: str,
new_parameter_name: str,
new_parameter: _T,
default_value: _T,
category: type[Warning] = ...,
**kwargs: Any,
) -> _T: ...

class ADict(dict[_KT, _VT], MutableMapping[_KT, _VT]):
def __setattr__(self, key: str, value: _VT) -> None: ...
def __delattr__(self, key: _KT, force: bool = False) -> None: ... # type: ignore[override]
def __call__(self, key: _KT) -> _VT: ...
def __getattr__(self, name: str) -> _VT: ...
def __deepcopy__(self, memo: dict[int, Any] | None) -> Self: ...
Expand Down Expand Up @@ -116,10 +126,14 @@ class pandapowerNet(ADict[str, pd.DataFrame]):
res_ward: pd.DataFrame
res_xward: pd.DataFrame
res_protection: pd.DataFrame # Optional?
@deprecated("Use copy.deepcopy(net) instead of net.deepcopy()")
def deepcopy(self) -> Self: ...

class GeoAccessor:
def __init__(self, pandas_obj) -> None: ...
@property
def as_geo_obj(self): ...
@property
def type(self) -> str: ...
@property
def as_shapely_obj(self) -> pd.Series[BaseGeometry]: ... # type: ignore[type-var] # pyright: ignore[reportInvalidTypeArguments]
Expand All @@ -140,6 +154,7 @@ def element_types_to_ets(element_types: None = None) -> pd.Series[str]: ...
def element_types_to_ets(element_types: str) -> str: ...
@overload
def element_types_to_ets(element_types: list[str] | pd.Series[str] | pd.Index[str] | NDArray[np.str_]) -> list[str]: ...
def empty_defaults_per_dtype(dtype: DTypeLike) -> float | Literal[""] | None: ...
def get_free_id(df: pd.DataFrame) -> np.int64: ...

class ppException(Exception): ...
Expand Down
5 changes: 3 additions & 2 deletions stubs/pandapower-stubs/control/util/auxiliary.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from _typeshed import Incomplete
from typing import Any

MATPLOTLIB_INSTALLED: bool
from numpy.typing import DTypeLike, NDArray

def asarray(val, dtype=...): ...
def asarray(val: object, dtype: DTypeLike = ...) -> NDArray[Any]: ...
def get_controller_index_by_type(net, ctrl_type, idx=[]): ...
def get_controller_index_by_typename(net, typename, idx=[], case_sensitive: bool = False): ...
def get_controller_index(net, ctrl_type: Incomplete | None = None, parameters: Incomplete | None = None, idx=[]): ...
Expand Down
1 change: 1 addition & 0 deletions stubs/pandapower-stubs/convert_format.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ from pandapower.auxiliary import pandapowerNet

def convert_format(net: pandapowerNet, elements_to_deserialize: Container[str] | None = None) -> pandapowerNet: ...
def correct_dtypes(net: pandapowerNet, error: bool) -> None: ...
def convert_trafo_pst_logic(net: pandapowerNet) -> None: ...
13 changes: 5 additions & 8 deletions stubs/pandapower-stubs/converter/pypower/from_ppc.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from _typeshed import Incomplete
from pandapower.auxiliary import pandapowerNet

from pandapower.pypower.idx_brch import ANGMAX as ANGMAX, ANGMIN as ANGMIN, RATE_B as RATE_B, RATE_C as RATE_C
from pandapower.pypower.idx_bus import BUS_AREA as BUS_AREA, VM as VM
ppc_elms: list[str]

ppc_elms: Incomplete

def from_ppc(ppc, f_hz: int = 50, validate_conversion: bool = False, **kwargs): ...
def from_ppc(ppc, f_hz: float = 50, validate_conversion: bool = False, **kwargs) -> pandapowerNet: ...
def validate_from_ppc(
ppc,
net,
net: pandapowerNet,
max_diff_values={
"bus_vm_pu": 1e-06,
"bus_va_degree": 1e-05,
Expand All @@ -17,4 +14,4 @@ def validate_from_ppc(
"gen_p_mw": 1e-06,
"gen_q_mvar": 1e-06,
},
): ...
) -> bool: ...
Loading