diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3485e94..08d8f16 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,7 @@ repos: - id: mixed-line-ending - id: check-case-conflict - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.4.5 # must match requirements-tests.txt + rev: v0.4.9 # must match requirements-tests.txt hooks: - id: ruff - id: ruff-format diff --git a/requirements-tests.txt b/requirements-tests.txt index ca65637..07226d4 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -1,9 +1,10 @@ # Tools # ----- -ruff==0.4.5 # must match .pre-commit-config.yaml +ruff==0.4.9 # must match .pre-commit-config.yaml pytest>=8.0 +rich-argparse>=1.5.2 mypy==1.10.0 -pyright==1.1.364 +pyright==1.1.367 # Runtime dependencies # -------------------- @@ -12,8 +13,8 @@ geopandas>=0.14.4,<1.0 # Transient dependencies # ---------------------- # geopandas -types-shapely>=2.0.0.20240527 -pandas-stubs>=2.2.2.240514 +types-shapely>=2.0.0.20240613 +pandas-stubs>=2.2.2.240603 matplotlib>=3.8.0 folium>=0.16.0 rtree>=1.2.0 diff --git a/run.py b/run.py index e2168a3..d1bea70 100755 --- a/run.py +++ b/run.py @@ -5,15 +5,10 @@ import os import subprocess import sys +from subprocess import list2cmdline as l2c -try: - from rich.text import Text # pyright: ignore[reportAssignmentType] - from rich_argparse import RawDescriptionRichHelpFormatter as RawDescriptionHelpFormatter -except ModuleNotFoundError: - RawDescriptionHelpFormatter = argparse.RawDescriptionHelpFormatter - - class Text(str): ... - +from rich.markdown import Markdown +from rich_argparse import RawDescriptionRichHelpFormatter default_args = { "ruff-check": ["tests", "stubs"], @@ -24,20 +19,18 @@ class Text(str): ... "pytest": [], } -description = """\ +_newl = "\n" +description = f"""\ Run project development tools with proper environment setup. The following commands are available: -┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ -┃ Command ┃ Default invocation ┃ -""" -for tool, default in default_args.items(): - description += "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n" - description += f"┃ {tool:<11s} ┃ {subprocess.list2cmdline((*tool.split('-'), *default)):<63s}┃\n" -description += """\ -┗━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + +Command | Default invocation | +------- | ------------------ | +{_newl.join(f"{tool} | {l2c((*tool.split('-'), *default))}" for tool, default in default_args.items())} You can override the default invocation by passing extra args after the command: + E.g: `python run.py mypy tests` invokes `mypy tests` instead. Run `python -m pip install -r requirements-tests.txt` to install dependencies. @@ -45,7 +38,11 @@ class Text(str): ... def main() -> int: - parser = argparse.ArgumentParser(description=Text(description), formatter_class=RawDescriptionHelpFormatter, add_help=False) + parser = argparse.ArgumentParser( + description=Markdown(description), # pyright: ignore[reportArgumentType] + formatter_class=RawDescriptionRichHelpFormatter, + add_help=False, + ) parser.add_argument( "tool", nargs="?", @@ -84,7 +81,7 @@ def main() -> int: ret = 0 for tool in tools: cmd = [*tool.split("-"), *(rest or default_args[tool])] - print("Running:", subprocess.list2cmdline(cmd), file=sys.stderr) + print("Running:", l2c(cmd), file=sys.stderr) ret |= subprocess.call(cmd, env={**os.environ, "PYTHONPATH": "stubs"}, text=True) print(file=sys.stderr) return ret diff --git a/stubs/geopandas-stubs/array.pyi b/stubs/geopandas-stubs/array.pyi index 08446f6..a879233 100644 --- a/stubs/geopandas-stubs/array.pyi +++ b/stubs/geopandas-stubs/array.pyi @@ -83,9 +83,9 @@ class GeometryArray(ExtensionArray): @property def geom_type(self) -> NDArray[np.int_]: ... @property - def area(self) -> NDArray[np.float_]: ... + def area(self) -> NDArray[np.float64]: ... @property - def length(self) -> NDArray[np.float_]: ... + def length(self) -> NDArray[np.float64]: ... @property def boundary(self) -> GeometryArray: ... @property @@ -112,7 +112,7 @@ class GeometryArray(ExtensionArray): def remove_repeated_points(self, tolerance: float | ArrayLike = 0.0) -> GeometryArray: ... def representative_point(self) -> GeometryArray: ... def minimum_bounding_circle(self) -> GeometryArray: ... - def minimum_bounding_radius(self) -> NDArray[np.float_]: ... + def minimum_bounding_radius(self) -> NDArray[np.float64]: ... def normalize(self) -> GeometryArray: ... def make_valid(self) -> GeometryArray: ... def reverse(self) -> GeometryArray: ... @@ -136,9 +136,9 @@ class GeometryArray(ExtensionArray): def symmetric_difference(self, other: _ArrayOrGeom) -> GeometryArray: ... def union(self, other: _ArrayOrGeom) -> GeometryArray: ... def shortest_line(self, other: _ArrayOrGeom) -> GeometryArray: ... - def distance(self, other: _ArrayOrGeom) -> NDArray[np.float_]: ... - def hausdorff_distance(self, other: _ArrayOrGeom, **kwargs: Any) -> NDArray[np.float_]: ... - def frechet_distance(self, other: _ArrayOrGeom, **kwargs) -> NDArray[np.float_]: ... + def distance(self, other: _ArrayOrGeom) -> NDArray[np.float64]: ... + def hausdorff_distance(self, other: _ArrayOrGeom, **kwargs: Any) -> NDArray[np.float64]: ... + def frechet_distance(self, other: _ArrayOrGeom, **kwargs) -> NDArray[np.float64]: ... def buffer(self, distance: float | ArrayLike, resolution: int = 16, **kwargs) -> GeometryArray: ... def interpolate(self, distance, normalized: bool = False) -> GeometryArray: ... def simplify(self, tolerance: float | ArrayLike, preserve_topology: bool = True) -> GeometryArray: ... @@ -153,15 +153,15 @@ class GeometryArray(ExtensionArray): def to_crs(self, crs: _ConvertibleToCRS | None = None, epsg: int | None = None) -> GeometryArray: ... def estimate_utm_crs(self, datum_name: str = "WGS 84") -> CRS: ... @property - def x(self) -> NDArray[np.float_]: ... + def x(self) -> NDArray[np.float64]: ... @property - def y(self) -> NDArray[np.float_]: ... + def y(self) -> NDArray[np.float64]: ... @property - def z(self) -> NDArray[np.float_]: ... + def z(self) -> NDArray[np.float64]: ... @property - def bounds(self) -> NDArray[np.float_]: ... + def bounds(self) -> NDArray[np.float64]: ... @property - def total_bounds(self) -> NDArray[np.float_]: ... + def total_bounds(self) -> NDArray[np.float64]: ... @property def size(self) -> int: ... @property diff --git a/stubs/geopandas-stubs/base.pyi b/stubs/geopandas-stubs/base.pyi index e823927..6bbac21 100644 --- a/stubs/geopandas-stubs/base.pyi +++ b/stubs/geopandas-stubs/base.pyi @@ -113,7 +113,7 @@ class GeoPandasBase: @property def bounds(self) -> pd.DataFrame: ... @property - def total_bounds(self) -> NDArray[np.float_]: ... + def total_bounds(self) -> NDArray[np.float64]: ... @property def sindex(self) -> BaseSpatialIndex: ... @property diff --git a/stubs/geopandas-stubs/geoseries.pyi b/stubs/geopandas-stubs/geoseries.pyi index 99dc445..416a15a 100644 --- a/stubs/geopandas-stubs/geoseries.pyi +++ b/stubs/geopandas-stubs/geoseries.pyi @@ -135,7 +135,7 @@ class GeoSeries(GeoPandasBase, pd.Series[BaseGeometry]): # type: ignore[type-va # def __getitem__(self, key): ... # *** `sort_index` is annotated with `-> Self` in pandas-stubs; no need to override it *** # def sort_index(self, *args, **kwargs): ... - def take(self, indices: ArrayLike, axis: AxisIndex = 0, **kwargs: Unused) -> GeoSeries: ... # type: ignore[override] + def take(self, indices: ArrayLike, axis: AxisIndex = 0, **kwargs: Unused) -> GeoSeries: ... @deprecated("Method `Series.select()` has been removed in pandas version '0.25'.") def select(self, *args: Any, **kwargs: Any) -> Any: ... # *** `apply` annotation in pandas-stubs is compatible except for deprecated `convert_dtype` argument *** diff --git a/stubs/geopandas-stubs/sindex.pyi b/stubs/geopandas-stubs/sindex.pyi index 8dd3ee6..b06a703 100644 --- a/stubs/geopandas-stubs/sindex.pyi +++ b/stubs/geopandas-stubs/sindex.pyi @@ -19,7 +19,7 @@ class BaseSpatialIndex: max_distance: float | None = None, return_distance: bool = False, exclusive: bool = False, - ) -> NDArray[np.int_] | tuple[NDArray[np.int_], NDArray[np.float_]]: ... + ) -> NDArray[np.int_] | tuple[NDArray[np.int_], NDArray[np.float64]]: ... def intersection(self, coordinates) -> NDArray[np.int_]: ... @property def size(self) -> int: ... @@ -79,7 +79,7 @@ class PyGEOSSTRTreeIndex(BaseSpatialIndex): *, return_distance: Literal[True], exclusive: bool = False, - ) -> tuple[NDArray[np.int_], NDArray[np.float_]]: ... + ) -> tuple[NDArray[np.int_], NDArray[np.float64]]: ... @overload def nearest( self, @@ -88,7 +88,7 @@ class PyGEOSSTRTreeIndex(BaseSpatialIndex): max_distance: float | None = None, return_distance: bool = False, exclusive: bool = False, - ) -> NDArray[np.int_] | tuple[NDArray[np.int_], NDArray[np.float_]]: ... + ) -> NDArray[np.int_] | tuple[NDArray[np.int_], NDArray[np.float64]]: ... def intersection(self, coordinates) -> NDArray[np.int_]: ... @property def size(self) -> int: ... diff --git a/stubs/pandapower-stubs/auxiliary.pyi b/stubs/pandapower-stubs/auxiliary.pyi index cf72a07..0d3e255 100644 --- a/stubs/pandapower-stubs/auxiliary.pyi +++ b/stubs/pandapower-stubs/auxiliary.pyi @@ -114,27 +114,27 @@ def set_elements_oos(ti: Sized, tis: Incomplete, bis: Incomplete, lis: MutableSe def set_isolated_buses_oos( bus_in_service: MutableSequence[bool], ppc_bus_isolated: Incomplete, bus_lookup: Incomplete ) -> None: ... -def X012_to_X0(X012: ArrayLike) -> NDArray[np.complex_]: ... -def X012_to_X1(X012: ArrayLike) -> NDArray[np.complex_]: ... -def X012_to_X2(X012: ArrayLike) -> NDArray[np.complex_]: ... -def combine_X012(X0: ArrayLike, X1: ArrayLike, X2: ArrayLike) -> NDArray[np.complex_]: ... +def X012_to_X0(X012: ArrayLike) -> NDArray[np.complex128]: ... +def X012_to_X1(X012: ArrayLike) -> NDArray[np.complex128]: ... +def X012_to_X2(X012: ArrayLike) -> NDArray[np.complex128]: ... +def combine_X012(X0: ArrayLike, X1: ArrayLike, X2: ArrayLike) -> NDArray[np.complex128]: ... def phase_shift_unit_operator(angle_deg: float) -> float: ... a: float asq: float -Tabc: NDArray[np.float_] -T012: NDArray[np.float_] +Tabc: NDArray[np.float64] +T012: NDArray[np.float64] -def sequence_to_phase(X012: ArrayLike) -> NDArray[np.float_]: ... -def phase_to_sequence(Xabc: ArrayLike) -> NDArray[np.float_]: ... -def I0_from_V012(V012: ArrayLike, Y: ArrayLike) -> NDArray[np.complex_]: ... -def I1_from_V012(V012: ArrayLike, Y: ArrayLike) -> NDArray[np.complex_]: ... -def I2_from_V012(V012: ArrayLike, Y: ArrayLike) -> NDArray[np.complex_]: ... -def V1_from_ppc(ppc: Mapping[str, ArrayLike]) -> NDArray[np.complex_]: ... -def V_from_I(Y: ArrayLike, I: ArrayLike) -> NDArray[np.complex_]: ... -def I_from_V(Y: ArrayLike, V: ArrayLike) -> NDArray[np.complex_]: ... -def S_from_VI_elementwise(V: ArrayLike, I: ArrayLike) -> NDArray[np.complex_]: ... -def I_from_SV_elementwise(S: ArrayLike, V: ArrayLike) -> NDArray[np.complex_]: ... +def sequence_to_phase(X012: ArrayLike) -> NDArray[np.float64]: ... +def phase_to_sequence(Xabc: ArrayLike) -> NDArray[np.float64]: ... +def I0_from_V012(V012: ArrayLike, Y: ArrayLike) -> NDArray[np.complex128]: ... +def I1_from_V012(V012: ArrayLike, Y: ArrayLike) -> NDArray[np.complex128]: ... +def I2_from_V012(V012: ArrayLike, Y: ArrayLike) -> NDArray[np.complex128]: ... +def V1_from_ppc(ppc: Mapping[str, ArrayLike]) -> NDArray[np.complex128]: ... +def V_from_I(Y: ArrayLike, I: ArrayLike) -> NDArray[np.complex128]: ... +def I_from_V(Y: ArrayLike, V: ArrayLike) -> NDArray[np.complex128]: ... +def S_from_VI_elementwise(V: ArrayLike, I: ArrayLike) -> NDArray[np.complex128]: ... +def I_from_SV_elementwise(S: ArrayLike, V: ArrayLike) -> NDArray[np.complex128]: ... def SVabc_from_SV012( S012: ArrayLike, V012: ArrayLike, n_res: int | None = None, idx: int | ArrayLike | None = None -) -> tuple[NDArray[np.complex_], NDArray[np.complex_]]: ... +) -> tuple[NDArray[np.complex128], NDArray[np.complex128]]: ... diff --git a/stubs/pandapower-stubs/plotting/collections.pyi b/stubs/pandapower-stubs/plotting/collections.pyi index 73d58fc..ca36202 100644 --- a/stubs/pandapower-stubs/plotting/collections.pyi +++ b/stubs/pandapower-stubs/plotting/collections.pyi @@ -24,7 +24,7 @@ class CustomTextPath(TextPath): prop: FontProperties def __init__( self, - xy: tuple[float, float] | NDArray[np.float_], + xy: tuple[float, float] | NDArray[np.float64], s: str, size: float | None = None, prop: FontProperties | None = None, diff --git a/stubs/pandapower-stubs/plotting/plotting_toolbox.pyi b/stubs/pandapower-stubs/plotting/plotting_toolbox.pyi index c8b93ee..579b6e4 100644 --- a/stubs/pandapower-stubs/plotting/plotting_toolbox.pyi +++ b/stubs/pandapower-stubs/plotting/plotting_toolbox.pyi @@ -49,4 +49,4 @@ def coords_from_node_geodata( def set_line_geodata_from_bus_geodata( net: pandapowerNet, line_index: Iterable[int] | None = None, overwrite: bool = False ) -> None: ... -def position_on_busbar(net: pandapowerNet, bus: int, busbar_coords: NDArray[np.float_]) -> NDArray[np.float_] | None: ... +def position_on_busbar(net: pandapowerNet, bus: int, busbar_coords: NDArray[np.float64]) -> NDArray[np.float64] | None: ... diff --git a/stubs/pandapower-stubs/results_bus.pyi b/stubs/pandapower-stubs/results_bus.pyi index 23a51e0..96a88f8 100644 --- a/stubs/pandapower-stubs/results_bus.pyi +++ b/stubs/pandapower-stubs/results_bus.pyi @@ -6,8 +6,8 @@ from numpy.typing import ArrayLike, NDArray from pandapower.auxiliary import pandapowerNet -_PType: TypeAlias = NDArray[np.float_] -_QType: TypeAlias = NDArray[np.float_] +_PType: TypeAlias = NDArray[np.float64] +_QType: TypeAlias = NDArray[np.float64] _BType: TypeAlias = NDArray[np.int_] def write_voltage_dependend_load_results( diff --git a/stubs/pandapower-stubs/shortcircuit/toolbox.pyi b/stubs/pandapower-stubs/shortcircuit/toolbox.pyi index 0ff7139..6b94f0c 100644 --- a/stubs/pandapower-stubs/shortcircuit/toolbox.pyi +++ b/stubs/pandapower-stubs/shortcircuit/toolbox.pyi @@ -12,4 +12,4 @@ def calc_sc_on_line( net: pandapowerNet, line_ix: SupportsIndex, distance_to_bus0: float, **kwargs ) -> tuple[pandapowerNet, int]: ... def adjust_V0_for_trafo_tap(ppci, V0, bus_idx) -> None: ... -def adjacency(ppci) -> NDArray[np.float_]: ... +def adjacency(ppci) -> NDArray[np.float64]: ... diff --git a/stubs/pandapower-stubs/toolbox.pyi b/stubs/pandapower-stubs/toolbox.pyi index e8e9800..cc21457 100644 --- a/stubs/pandapower-stubs/toolbox.pyi +++ b/stubs/pandapower-stubs/toolbox.pyi @@ -34,40 +34,42 @@ def pq_from_cosphi(s: float, cosphi: float, qmode: _QMode, pmode: _PMode) -> tup @overload def pq_from_cosphi( s: Iterable[float], cosphi: float | Iterable[float], qmode: _QMode | Iterable[_QMode], pmode: _PMode | Iterable[_PMode] -) -> tuple[NDArray[np.float_], NDArray[np.float_]]: ... +) -> tuple[NDArray[np.float64], NDArray[np.float64]]: ... @overload def pq_from_cosphi( s: float | Iterable[float], cosphi: Iterable[float], qmode: _QMode | Iterable[_QMode], pmode: _PMode | Iterable[_PMode] -) -> tuple[NDArray[np.float_], NDArray[np.float_]]: ... +) -> tuple[NDArray[np.float64], NDArray[np.float64]]: ... @overload def pq_from_cosphi( s: float | Iterable[float], cosphi: float | Iterable[float], qmode: Iterable[_QMode], pmode: _PMode | Iterable[_PMode] -) -> tuple[NDArray[np.float_], NDArray[np.float_]]: ... +) -> tuple[NDArray[np.float64], NDArray[np.float64]]: ... @overload def pq_from_cosphi( s: float | Iterable[float], cosphi: float | Iterable[float], qmode: _QMode | Iterable[_QMode], pmode: Iterable[_PMode] -) -> tuple[NDArray[np.float_], NDArray[np.float_]]: ... +) -> tuple[NDArray[np.float64], NDArray[np.float64]]: ... @overload def pq_from_cosphi( s: float | Iterable[float], cosphi: float | Iterable[float], qmode: _QMode | Iterable[_QMode], pmode: _PMode | Iterable[_PMode], -) -> tuple[float, float] | tuple[NDArray[np.float_], NDArray[np.float_]]: ... +) -> tuple[float, float] | tuple[NDArray[np.float64], NDArray[np.float64]]: ... @overload def cosphi_from_pq(p: float, q: float) -> tuple[float, float, _PMode, _QMode]: ... @overload def cosphi_from_pq( p: Iterable[float], q: float | Iterable[float] -) -> tuple[NDArray[np.float_], NDArray[np.float_], NDArray[np.str_], NDArray[np.str_]]: ... +) -> tuple[NDArray[np.float64], NDArray[np.float64], NDArray[np.str_], NDArray[np.str_]]: ... @overload def cosphi_from_pq( p: float | Iterable[float], q: Iterable[float] -) -> tuple[NDArray[np.float_], NDArray[np.float_], NDArray[np.str_], NDArray[np.str_]]: ... +) -> tuple[NDArray[np.float64], NDArray[np.float64], NDArray[np.str_], NDArray[np.str_]]: ... @overload def cosphi_from_pq( p: float | Iterable[float], q: float | Iterable[float] -) -> tuple[float, float, _PMode, _QMode] | tuple[NDArray[np.float_], NDArray[np.float_], NDArray[np.str_], NDArray[np.str_]]: ... +) -> ( + tuple[float, float, _PMode, _QMode] | tuple[NDArray[np.float64], NDArray[np.float64], NDArray[np.str_], NDArray[np.str_]] +): ... def dataframes_equal(df1: pd.DataFrame, df2: pd.DataFrame, ignore_index_order: bool = True, **kwargs: Incomplete) -> bool: ... def compare_arrays(x: NDArray[Any], y: NDArray[Any]) -> NDArray[np.bool_]: ... def log_to_level(msg: object, passed_logger: Logger, level: str) -> None: ...