Skip to content

Commit 9bccafe

Browse files
Merge branch 'main' into pgm/save-visualizer-html
2 parents 2e2a704 + 5c4d7ef commit 9bccafe

26 files changed

Lines changed: 74 additions & 57 deletions

File tree

docs/demos/connecting_new_consumer.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"outputs": [],
2121
"source": [
2222
"from dataclasses import dataclass\n",
23+
"from typing import ClassVar\n",
2324
"\n",
2425
"import numpy as np\n",
2526
"from numpy.typing import NDArray\n",
@@ -31,7 +32,7 @@
3132
"class ExtendedNodeArray(NodeArray):\n",
3233
" \"\"\"Extends the node array with the simulated voltage and coordinates\"\"\"\n",
3334
"\n",
34-
" _defaults = {\"u\": 0}\n",
35+
" _defaults: ClassVar = {\"u\": 0}\n",
3536
"\n",
3637
" u: NDArray[np.float64]\n",
3738
" x_coor: NDArray[np.float64]\n",
@@ -45,7 +46,7 @@
4546
"class ExtendedLineArray(LineArray):\n",
4647
" \"\"\"Extends the line array with current output\"\"\"\n",
4748
"\n",
48-
" _defaults = {\"i_from\": 0}\n",
49+
" _defaults: ClassVar = {\"i_from\": 0}\n",
4950
"\n",
5051
" i_from: NDArray[np.float64]\n",
5152
"\n",

docs/examples/model/array_examples.ipynb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"metadata": {},
2222
"outputs": [],
2323
"source": [
24+
"from typing import ClassVar\n",
25+
"\n",
2426
"import numpy as np\n",
2527
"from numpy.typing import NDArray\n",
2628
"\n",
@@ -196,7 +198,7 @@
196198
"source": [
197199
"class CustomStrLengthArray(FancyArray):\n",
198200
" test_str: NDArray[np.str_]\n",
199-
" _str_lengths = {\"test_str\": 100}\n",
201+
" _str_lengths: ClassVar = {\"test_str\": 100}\n",
200202
"\n",
201203
"\n",
202204
"custom_array = CustomStrLengthArray(test_str=[\"a\" * 100])"

docs/examples/model/grid_extensions_examples.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"metadata": {},
2222
"outputs": [],
2323
"source": [
24+
"from typing import ClassVar\n",
25+
"\n",
2426
"import numpy as np\n",
2527
"from numpy.typing import NDArray\n",
2628
"\n",
@@ -30,15 +32,15 @@
3032
"class ExtendedNodeArray(NodeArray):\n",
3133
" \"\"\"Extends the node array with an output value\"\"\"\n",
3234
"\n",
33-
" _defaults = {\"u\": 0}\n",
35+
" _defaults: ClassVar = {\"u\": 0}\n",
3436
"\n",
3537
" u: NDArray[np.float64]\n",
3638
"\n",
3739
"\n",
3840
"class ExtendedLineArray(LineArray):\n",
3941
" \"\"\"Extends the line array with an output value\"\"\"\n",
4042
"\n",
41-
" _defaults = {\"i_from\": 0}\n",
43+
" _defaults: ClassVar = {\"i_from\": 0}\n",
4244
"\n",
4345
" i_from: NDArray[np.float64]"
4446
]

docs/examples/pgm/basic_pgm_examples.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"outputs": [],
6969
"source": [
7070
"from dataclasses import dataclass\n",
71+
"from typing import ClassVar\n",
7172
"\n",
7273
"import numpy as np\n",
7374
"from numpy.typing import NDArray\n",
@@ -79,15 +80,15 @@
7980
"class ExtendedNodeArray(NodeArray):\n",
8081
" \"\"\"Extends the node array with an output value\"\"\"\n",
8182
"\n",
82-
" _defaults = {\"u\": 0}\n",
83+
" _defaults: ClassVar = {\"u\": 0}\n",
8384
"\n",
8485
" u: NDArray[np.float64]\n",
8586
"\n",
8687
"\n",
8788
"class ExtendedLineArray(LineArray):\n",
8889
" \"\"\"Extends the line array with an output value\"\"\"\n",
8990
"\n",
90-
" _defaults = {\"i_from\": 0}\n",
91+
" _defaults: ClassVar = {\"i_from\": 0}\n",
9192
"\n",
9293
" i_from: NDArray[np.float64]\n",
9394
"\n",

docs/model_interface.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@
117117
"metadata": {},
118118
"outputs": [],
119119
"source": [
120+
"from typing import ClassVar\n",
121+
"\n",
120122
"import numpy as np\n",
121123
"from numpy.typing import NDArray\n",
122124
"\n",
@@ -143,7 +145,7 @@
143145
"outputs": [],
144146
"source": [
145147
"class MyDefaultedArray(MyArray):\n",
146-
" _defaults = {\"id\": -1, \"name\": \"default\", \"value\": 1.0}"
148+
" _defaults: ClassVar = {\"id\": -1, \"name\": \"default\", \"value\": 1.0}"
147149
]
148150
},
149151
{
@@ -181,7 +183,7 @@
181183
"source": [
182184
"class MyArray(FancyArray):\n",
183185
" name: NDArray[np.str_]\n",
184-
" _str_lengths = {\"name\": 100}"
186+
" _str_lengths: ClassVar = {\"name\": 100}"
185187
]
186188
},
187189
{

docs/quick_start.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"outputs": [],
2626
"source": [
2727
"from dataclasses import dataclass\n",
28+
"from typing import ClassVar\n",
2829
"\n",
2930
"import numpy as np\n",
3031
"from numpy.typing import NDArray\n",
@@ -36,15 +37,15 @@
3637
"class ExtendedNodeArray(NodeArray):\n",
3738
" \"\"\"Extends the node array with an output value\"\"\"\n",
3839
"\n",
39-
" _defaults = {\"u\": 0}\n",
40+
" _defaults: ClassVar = {\"u\": 0}\n",
4041
"\n",
4142
" u: NDArray[np.float64]\n",
4243
"\n",
4344
"\n",
4445
"class ExtendedLineArray(LineArray):\n",
4546
" \"\"\"Extends the line array with an output value\"\"\"\n",
4647
"\n",
47-
" _defaults = {\"i_from\": 0}\n",
48+
" _defaults: ClassVar = {\"i_from\": 0}\n",
4849
"\n",
4950
" i_from: NDArray[np.float64]\n",
5051
"\n",

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ select = [
110110
"E",
111111
# Pyflakes
112112
"F",
113-
# # pyupgrade
113+
# pyupgrade
114114
"UP",
115-
# # flake8-bugbear
115+
# flake8-bugbear
116116
"B",
117-
# # flake8-simplify
117+
# flake8-simplify
118118
"SIM",
119119
# isort
120120
"I",
@@ -152,7 +152,7 @@ select = [
152152
# raise
153153
"RSE",
154154
# ruff sepcific rules
155-
#"RUF",
155+
"RUF",
156156
# bandit
157157
"S",
158158
# boolean positional value in call

src/power_grid_model_ds/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from power_grid_model_ds._core.power_grid_model_interface import PowerGridModelInterface
88

99
__all__ = [
10-
"Grid",
10+
"FancyArray",
1111
"GraphContainer",
12+
"Grid",
1213
"PowerGridModelInterface",
13-
"FancyArray",
1414
]

src/power_grid_model_ds/_core/fancypy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def concatenate[T: FancyArray](fancy_array: T, *other_arrays: T | np.ndarray) ->
1818
"""Concatenate arrays."""
1919
np_arrays = [array if isinstance(array, np.ndarray) else array.data for array in other_arrays]
2020
try:
21-
concatenated = np.concatenate([fancy_array.data] + np_arrays)
21+
concatenated = np.concatenate([fancy_array.data, *np_arrays])
2222
except TypeError as error:
2323
raise TypeError("Cannot append arrays: mismatching dtypes.") from error
2424
return fancy_array.__class__(data=concatenated)

src/power_grid_model_ds/_core/model/arrays/base/array.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from collections.abc import Iterable
88
from copy import copy
99
from functools import lru_cache
10-
from typing import Any, Literal, TypeVar, overload
10+
from typing import Any, ClassVar, Literal, TypeVar, overload
1111

1212
import numpy as np
1313
from numpy.typing import ArrayLike, NDArray
@@ -58,8 +58,8 @@ class FancyArray(ABC): # noqa: B024
5858
"""
5959

6060
_data: NDArray = np.ndarray([])
61-
_defaults: dict[str, Any] = {}
62-
_str_lengths: dict[str, int] = {}
61+
_defaults: ClassVar[dict[str, Any]] = {}
62+
_str_lengths: ClassVar[dict[str, int]] = {}
6363

6464
def __init__(self, *args, data: NDArray | None = None, **kwargs):
6565
if data is None:

0 commit comments

Comments
 (0)