Skip to content

Commit 66ab1f9

Browse files
committed
add helper function
Signed-off-by: Nitish Bharambe <nitish.bharambe@alliander.com>
1 parent e31e05c commit 66ab1f9

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/power_grid_model/_core/power_grid_meta.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
_str_to_datatype,
2222
)
2323
from power_grid_model._core.power_grid_core import AttributePtr, ComponentPtr, DatasetPtr, power_grid_core as pgc
24-
from power_grid_model.data_types import DenseBatchArray, SingleArray
24+
from power_grid_model.data_types import AttributeType, DenseBatchArray, SingleArray
2525

2626

2727
# constant enum for ctype
@@ -205,3 +205,41 @@ def initialize_array(
205205
dtype=power_grid_meta_data[data_type][component_type].dtype,
206206
order="C",
207207
)
208+
209+
210+
def attribute_dtype(
211+
data_type: DatasetTypeLike, component_type: ComponentTypeLike, attribute: AttributeType
212+
) -> np.dtype:
213+
"""Gives out dtype of the attribute to be used in a columnar data format
214+
215+
Args:
216+
data_type (DatasetTypeLike): The type of dataset (input, update, sym_output, or asym_output)
217+
component_type (ComponentTypeLike): The type of component (e.g., node)
218+
attribute (AttributeType): The attribute whose dtype is required
219+
220+
Returns:
221+
np.dtype: The dtype of the specified attribute
222+
"""
223+
data_type = _str_to_datatype(data_type)
224+
component_type = _str_to_component_type(component_type)
225+
return power_grid_meta_data[data_type][component_type].dtype[attribute]
226+
227+
228+
def attribute_empty_value(
229+
data_type: DatasetTypeLike, component_type: ComponentTypeLike, attribute: AttributeType
230+
) -> np.ndarray:
231+
"""
232+
Returns the empty value for a specific attribute in the Power Grid Model.
233+
234+
235+
Args:
236+
data_type (DatasetTypeLike): The type of dataset (input, update, sym_output, or asym_output)
237+
component_type (ComponentTypeLike): The type of component (e.g., node)
238+
attribute (AttributeType): The attribute whose empty value is required
239+
240+
Returns:
241+
np.ndarray: The empty value for the specified attribute
242+
"""
243+
data_type = _str_to_datatype(data_type)
244+
component_type = _str_to_component_type(component_type)
245+
return power_grid_meta_data[data_type][component_type].nan_scalar[attribute]

0 commit comments

Comments
 (0)