Skip to content

Commit

Permalink
Fix numpy 2.0 compatibility (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamdanal authored Jun 15, 2024
1 parent de7f185 commit ab28f7b
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 5 additions & 4 deletions requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -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
# --------------------
Expand All @@ -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
Expand Down
35 changes: 16 additions & 19 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -24,28 +19,30 @@ 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.
"""


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="?",
Expand Down Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions stubs/geopandas-stubs/array.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: ...
Expand All @@ -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: ...
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion stubs/geopandas-stubs/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion stubs/geopandas-stubs/geoseries.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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 ***
Expand Down
6 changes: 3 additions & 3 deletions stubs/geopandas-stubs/sindex.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down Expand Up @@ -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,
Expand All @@ -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: ...
Expand Down
34 changes: 17 additions & 17 deletions stubs/pandapower-stubs/auxiliary.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]]: ...
2 changes: 1 addition & 1 deletion stubs/pandapower-stubs/plotting/collections.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion stubs/pandapower-stubs/plotting/plotting_toolbox.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
4 changes: 2 additions & 2 deletions stubs/pandapower-stubs/results_bus.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion stubs/pandapower-stubs/shortcircuit/toolbox.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]: ...
18 changes: 10 additions & 8 deletions stubs/pandapower-stubs/toolbox.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down

0 comments on commit ab28f7b

Please sign in to comment.