|
7 | 7 | """ |
8 | 8 |
|
9 | 9 | from dataclasses import dataclass |
10 | | -from typing import cast |
| 10 | +from typing import cast, overload |
11 | 11 |
|
12 | 12 | import numpy as np |
13 | 13 |
|
14 | 14 | from power_grid_model._core.data_types import ( |
15 | 15 | AttributeType, |
16 | 16 | ComponentData, |
| 17 | + DenseBatchArray, |
| 18 | + DenseBatchColumnarData, |
17 | 19 | DenseBatchData, |
18 | 20 | IndexPointer, |
| 21 | + SingleArray, |
| 22 | + SingleColumnarData, |
19 | 23 | SingleComponentData, |
20 | 24 | SparseBatchArray, |
21 | 25 | SparseBatchData, |
@@ -88,6 +92,10 @@ def _get_raw_data_view(data: np.ndarray, dtype: np.dtype) -> VoidPtr: |
88 | 92 | return np.ascontiguousarray(data, dtype=dtype).ctypes.data_as(VoidPtr) |
89 | 93 |
|
90 | 94 |
|
| 95 | +@overload |
| 96 | +def _get_raw_component_data_view(data: np.ndarray, schema: ComponentMetaData) -> VoidPtr: ... |
| 97 | +@overload |
| 98 | +def _get_raw_component_data_view(data: dict[AttributeType, np.ndarray], schema: ComponentMetaData) -> None: ... |
91 | 99 | def _get_raw_component_data_view( |
92 | 100 | data: np.ndarray | dict[AttributeType, np.ndarray], schema: ComponentMetaData |
93 | 101 | ) -> VoidPtr | None: |
@@ -486,7 +494,13 @@ def _create_sparse_buffer(properties: BufferProperties, schema: ComponentMetaDat |
486 | 494 | return cast(SparseBatchData, {"data": data, "indptr": indptr}) |
487 | 495 |
|
488 | 496 |
|
489 | | -def _create_contents_buffer(shape, dtype, columns: list[AttributeType] | None) -> SingleComponentData | DenseBatchData: |
| 497 | +@overload |
| 498 | +def _create_contents_buffer(shape, dtype, columns: None) -> SingleArray | DenseBatchArray: ... |
| 499 | +@overload |
| 500 | +def _create_contents_buffer( |
| 501 | + shape, dtype, columns: list[AttributeType] |
| 502 | +) -> SingleColumnarData | DenseBatchColumnarData: ... |
| 503 | +def _create_contents_buffer(shape, dtype, columns): |
490 | 504 | if columns is None: |
491 | 505 | return np.empty(shape=shape, dtype=dtype) |
492 | 506 |
|
|
0 commit comments