Skip to content

Commit 9cde647

Browse files
committed
Fix docs data_types, errors, typing
Signed-off-by: Emanuele Brentegani <emabr90@gmail.com>
1 parent 135f0e6 commit 9cde647

File tree

5 files changed

+317
-241
lines changed

5 files changed

+317
-241
lines changed

docs/api_reference/python-api-reference.md

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ are internal implementations.
3232
```{eval-rst}
3333
.. automodule:: power_grid_model.enum
3434
:undoc-members:
35+
:imported-members:
36+
:exclude-members: IntEnum
3537
:show-inheritance:
3638
```
3739

@@ -40,6 +42,7 @@ are internal implementations.
4042
```{eval-rst}
4143
.. automodule:: power_grid_model.data_types
4244
:undoc-members:
45+
:imported-members: +SparseBatchColumnarData, SparseBatchArray
4346
:show-inheritance:
4447
:exclude-members: BatchList,NominalValue,RealValue,AsymValue,AttributeValue,Component,ComponentList,SinglePythonDataset,BatchPythonDataset,PythonDataset
4548
```
@@ -48,6 +51,7 @@ are internal implementations.
4851

4952
```{eval-rst}
5053
.. automodule:: power_grid_model.errors
54+
:imported-members:
5155
```
5256

5357
## typing

src/power_grid_model/_core/data_types.py

-193
Original file line numberDiff line numberDiff line change
@@ -16,99 +16,28 @@
1616
from power_grid_model._core.dataset_definitions import ComponentTypeVar
1717

1818
SingleArray: TypeAlias = np.ndarray
19-
"""
20-
A single array is a one-dimensional structured numpy array containing a list of components of the same type.
21-
22-
- Examples:
23-
24-
- structure: <1d-array>
25-
- concrete: array([(0, 10500.0), (0, 10500.0)], dtype=power_grid_meta_data["input"]["node"].dtype)
26-
"""
2719

2820
AttributeType: TypeAlias = str
29-
"""
30-
An attribute type is a string reprenting the attribute type of a specific component.
31-
32-
- Examples:
33-
34-
- "id"
35-
- "u_rated"
36-
"""
3721

3822
SingleColumn: TypeAlias = np.ndarray
39-
"""
40-
A single column is a one-dimensional structured numpy array containing a list of the same attribute of
41-
multiple components of the same type.
42-
43-
- Examples:
44-
45-
- structure: <1d-array>
46-
- concrete:
47-
48-
- array([0, 1], dtype=power_grid_meta_data["input"]["node"].dtype.fields["id"][0])
49-
- array([10500.0, 10500.0], dtype=power_grid_meta_data["input"]["node"].dtype.fields["u_rated"][0])
50-
"""
5123

5224
DenseBatchArray: TypeAlias = np.ndarray
53-
"""
54-
A dense batch array is a two-dimensional structured numpy array containing a list of components of
55-
the same type for each scenario. Otherwise similar to :class:`SingleArray`.
56-
"""
5725

5826
SingleColumnarData = dict[AttributeType, SingleColumn]
59-
"""
60-
Single columnar data is a dictionary where the keys are the attribute types of the same component
61-
and the values are :class:`SingleColumn`.
62-
63-
- Example: {"id": :class:`AttributeType`, "u_rated": :class:`SingleColumn`}
64-
"""
6527

6628
_SingleComponentData = TypeVar("_SingleComponentData", SingleArray, SingleColumnarData) # deduction helper
6729
SingleComponentData = SingleArray | SingleColumnarData
68-
"""
69-
Single component data can be :class:`SingleArray` or :class:`SingleColumnarData`.
70-
"""
7130

7231

7332
SingleDataset = dict[ComponentTypeVar, _SingleComponentData]
74-
"""
75-
A single dataset is a dictionary where the keys are the component types and the values are
76-
:class:`ComponentData`
77-
78-
- Example: {"node": :class:`SingleArray`, "line": :class:`SingleColumnarData`}
79-
"""
8033

8134
BatchList = list[SingleDataset]
82-
"""
83-
A batch list is an alternative representation of a batch. It is a list of single datasets, where each single dataset
84-
is actually a batch. The batch list is intended as an intermediate data type, during conversions.
85-
86-
- Example: [:class:`SingleDataset`, {"node": :class:`SingleDataset`}]
87-
"""
8835

8936
BatchColumn: TypeAlias = np.ndarray
90-
"""
91-
A batch column is a two-dimensional structured numpy array containing a list of the same attribute of
92-
multiple components of the same type. Otherwise, similar to :class:`SingleColumn`.
93-
"""
9437

9538
DenseBatchColumnarData = dict[AttributeType, BatchColumn]
96-
"""
97-
Batch columnar data is a dictionary where the keys are the attribute types of the same component
98-
and the values are :class:`BatchColumn`.
99-
100-
- Example: {"id": :class:`AttributeType`, "from_status": :class:`BatchColumn`}
101-
"""
10239

10340
IndexPointer: TypeAlias = np.ndarray
104-
"""
105-
An index pointer is a one-dimensional numpy int64 array containing n+1 elements where n is the amount
106-
of scenarios, representing the start and end indices for each batch scenario as follows:
107-
108-
- The elements are the indices in the data that point to the first element of that scenario.
109-
- The last element is one after the data index of the last element of the last scenario.
110-
- The first element and last element will therefore be 0 and the size of the data, respectively.
111-
"""
11241

11342

11443
class SparseBatchColumnarData(TypedDict):
@@ -156,170 +85,48 @@ class SparseBatchArray(TypedDict):
15685

15786

15887
SparseBatchData = SparseBatchArray | SparseBatchColumnarData
159-
"""
160-
Sparse batch data can be a :class:`SparseBatchArray` or a :class:`SparseBatchColumnarData`.
161-
"""
16288

16389
SparseDataComponentType: TypeAlias = str
164-
"""
165-
A string representing the component type of sparse data structures.
166-
167-
Must be either "data" or "indptr".
168-
"""
16990

17091
BatchColumnarData = DenseBatchColumnarData | SparseBatchColumnarData
171-
"""
172-
Batch columnar data is either a :class:`DenseBatchColumnarData` or a :class:`SparseBatchColumnarData`.
173-
"""
17492

17593
ColumnarData = SingleColumnarData | BatchColumnarData
176-
"""
177-
Columnar data can be :class:`SingleColumnarData` or :class:`BatchColumnarData`.
178-
"""
17994
BatchArray = DenseBatchArray | SparseBatchArray
180-
"""
181-
A batch array is a either a :class:`DenseBatchArray` or a :class:`SparseBatchArray`.
182-
"""
18395

18496

18597
BatchComponentData = BatchArray | BatchColumnarData
186-
"""
187-
Batch component data can be :class:`BatchArray` or :class:`BatchColumnarData`.
188-
"""
18998

19099
_BatchComponentData = TypeVar("_BatchComponentData", BatchArray, BatchColumnarData) # deduction helper
191100

192101

193102
BatchDataset = dict[ComponentTypeVar, _BatchComponentData]
194-
"""
195-
A batch dataset is a dictionary where the keys are the component types and the values are :class:`BatchComponentData`
196-
197-
- Example: {"node": :class:`DenseBatchArray`, "line": :class:`SparseBatchArray`,
198-
"link": :class:`DenseBatchColumnarData`, "transformer": :class:`SparseBatchColumnarData`}
199-
"""
200103

201104

202105
DataArray = SingleArray | BatchArray
203-
"""
204-
A data array can be a :class:`SingleArray` or a :class:`BatchArray`.
205-
"""
206106

207107

208108
_ComponentData = TypeVar("_ComponentData", SingleComponentData, BatchComponentData) # deduction helper
209109
ComponentData = DataArray | ColumnarData
210-
"""
211-
Component data can be :class:`DataArray` or :class:`ColumnarData`.
212-
"""
213110

214111
Dataset = dict[ComponentTypeVar, _ComponentData]
215-
"""
216-
A general data set can be a :class:`SingleDataset` or a :class:`BatchDataset`.
217-
218-
- Examples:
219-
220-
- single: {"node": :class:`SingleArray`, "line": :class:`SingleColumnarData`}
221-
222-
- batch: {"node": :class:`DenseBatchArray`, "line": :class:`SparseBatchArray`,
223-
"link": :class:`DenseBatchColumnarData`, "transformer": :class:`SparseBatchColumnarData`}
224-
225-
"""
226112

227113

228114
DenseBatchData = DenseBatchArray | DenseBatchColumnarData
229-
"""
230-
Dense batch data can be a :class:`DenseBatchArray` or a :class:`DenseBatchColumnarData`.
231-
"""
232115

233116
NominalValue = int
234-
"""
235-
Nominal values can be IDs, booleans, enums, tap pos.
236-
237-
- Example: 123
238-
"""
239117

240118
RealValue = float
241-
"""
242-
Symmetrical values can be anything like cable properties, symmetric loads, etc.
243-
244-
- Example: 10500.0
245-
"""
246119

247120
AsymValue = tuple[RealValue, RealValue, RealValue]
248-
"""
249-
Asymmetrical values are three-phase values like p or u_measured.
250-
251-
- Example: (10400.0, 10500.0, 10600.0)
252-
"""
253121

254122
AttributeValue = RealValue | NominalValue | AsymValue
255-
"""
256-
When representing a grid as a native python structure, each attribute (u_rated etc) is either a nominal value,
257-
a real value, or a tuple of three real values.
258-
259-
- Examples:
260-
261-
- real: 10500.0
262-
- nominal: 123
263-
- asym: (10400.0, 10500.0, 10600.0)
264-
"""
265123

266124
Component = dict[AttributeType, AttributeValue | str]
267-
"""
268-
A component, when represented in native python format, is a dictionary, where the keys are the attributes and the values
269-
are the corresponding values. It is allowed to add extra fields, containing either an AttributeValue or a string.
270-
271-
- Example: {"id": 1, "u_rated": 10500.0, "original_id": "Busbar #1"}
272-
"""
273125

274126
ComponentList = list[Component]
275-
"""
276-
A component list is a list containing components. In essence it stores the same information as a np.ndarray,
277-
but in a native python format, without using numpy.
278-
279-
- Example: [{"id": 1, "u_rated": 10500.0}, {"id": 2, "u_rated": 10500.0}]
280-
"""
281127

282128
SinglePythonDataset = dict[ComponentTypeVar, ComponentList]
283-
"""
284-
A single dataset in native python representation is a dictionary, where the keys are the component names and the
285-
values are a list of all the instances of such a component. In essence it stores the same information as a
286-
SingleDataset, but in a native python format, without using numpy.
287-
288-
- Example:
289-
290-
{
291-
"node": [{"id": 1, "u_rated": 10500.0}, {"id": 2, "u_rated": 10500.0}],
292-
"line": [{"id": 3, "from_node": 1, "to_node": 2, ...}],
293-
}
294-
"""
295129

296130
BatchPythonDataset = list[SinglePythonDataset]
297-
"""
298-
A batch dataset in native python representation is a list of dictionaries, where the keys are the component names and
299-
the values are a list of all the instances of such a component. In essence it stores the same information as a
300-
BatchDataset, but in a native python format, without using numpy. Actually it looks more like the BatchList.
301-
302-
- Example:
303-
304-
[{"line": [{"id": 3, "from_status": 0, "to_status": 0, ...}],},
305-
{"line": [{"id": 3, "from_status": 1, "to_status": 1, ...}],}]
306-
"""
307131

308132
PythonDataset = SinglePythonDataset | BatchPythonDataset
309-
"""
310-
A general python data set can be a single or a batch python dataset.
311-
312-
- Examples:
313-
314-
- single:
315-
316-
{
317-
"node": [{"id": 1, "u_rated": 10500.0}, {"id": 2, "u_rated": 10500.0}],
318-
"line": [{"id": 3, "from_node": 1, "to_node": 2, ...}],
319-
}
320-
321-
- batch:
322-
323-
[{"line": [{"id": 3, "from_status": 0, "to_status": 0, ...}],},
324-
{"line": [{"id": 3, "from_status": 1, "to_status": 1, ...}],}]
325-
"""

src/power_grid_model/_core/typing.py

-16
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,3 @@
1818
| None
1919
| _ComponentAttributeMappingDict
2020
)
21-
"""
22-
Type hint for mapping component attributes.
23-
24-
`ComponentAttributeMapping` can be one of the following:
25-
26-
- A set of :class:`ComponentType` or `str`
27-
28-
- A list of :class:`ComponentType` or `str`
29-
30-
- A :class:`ComponentAttributeFilterOptions <power_grid_model.enum.ComponentAttributeFilterOptions>` value
31-
32-
- `None`
33-
34-
- A dictionary mapping :class:`ComponentType` to a set, list, `None` or
35-
:class:`ComponentAttributeFilterOptions <power_grid_model.enum.ComponentAttributeFilterOptions>`
36-
"""

0 commit comments

Comments
 (0)