Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature / Update Python validation to support optional id in update data #793

Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/power_grid_model/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,28 @@ def is_columnar(component_data: ComponentData) -> bool:
return not isinstance(component_data, np.ndarray)


def is_nan_or_equivalent(array):
def is_nan_or_default(x: np.ndarray) -> np.ndarray:
"""
Check if elements in the array are NaN or equal to the min of its dtype.

Args:
x: A NumPy array to check.

Returns:
A boolean NumPy array where each element is True if the corresponding element in x is NaN
or min of its dtype, and False otherwise.
"""
if x.dtype == np.float64:
return np.isnan(x)
if x.dtype in (np.int32, np.int8):
return x == np.iinfo(x.dtype).min
raise TypeError(f"Unsupported data type: {x.dtype}")


def is_nan_or_equivalent(array) -> bool:
"""
Check if the array contains only nan values or equivalent nan values for specific data types.
This is the aggregrated version of `is_nan_or_default` for the whole array.

Args:
array: The array to check.
Expand Down Expand Up @@ -751,25 +770,6 @@ def get_dataset_type(data: Dataset) -> DatasetType:
return next(iter(candidates))


def is_nan_or_default(x: np.ndarray) -> np.ndarray:
"""
Check if elements in the array are NaN or equal to the min of its dtype.

Args:
x: A NumPy array to check.

Returns:
A boolean NumPy array where each element is True if the corresponding element in x is NaN
or min of its dtype, and False otherwise.
"""
if x.dtype == np.float64:
return np.isnan(x)
elif x.dtype in (np.int32, np.int8):
return x == np.iinfo(x.dtype).min
else:
raise TypeError(f"Unsupported data type: {x.dtype}")


def get_comp_batch_size(comp_data: dict) -> int:
"""
Get the batch size of the component update data.
Expand Down
Loading