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

fix also support empty trafo list in validation #671

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions src/power_grid_model/validation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,16 @@ def get_indexer(source: np.ndarray, target: np.ndarray, default_value: Optional[
Raises:
IndexError: if default_value is None and there were values in target that were not in source
"""

permutation_sort = np.argsort(source) # complexity O(N_input * logN_input)
indices = np.searchsorted(source, target, sorter=permutation_sort) # complexity O(N_update * logN_input)

if default_value is None:
return permutation_sort[indices]

if len(source) == 0:
return np.full_like(target, fill_value=default_value)

clipped_indices = np.take(permutation_sort, indices, mode="clip")
return np.where(source[clipped_indices] == target, permutation_sort[clipped_indices], default_value)

Expand Down
3 changes: 2 additions & 1 deletion tests/unit/validation/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,14 +553,15 @@ def test_supported_tap_control_side():
valid = {
"foo": np.array([(0, 4)], dtype=[("id", "i4"), ("foofoo", "i1")]),
"bar": np.array([(1, 5)], dtype=[("id", "i4"), ("barbar", "i1")]),
"baz": np.array([], dtype=[("id", "i4"), ("bazbaz", "i1")]),
"regulator": np.array([(2, 0, 6), (3, 1, 7)], dtype=[("id", "i4"), ("regulated", "i4"), ("control", "i1")]),
}
errors = all_supported_tap_control_side(
valid,
"regulator",
"control",
"regulated",
[("foo", "foofoo"), ("bar", "barbar"), ("baz", "bazbaz")],
[("foo", "foofoo"), ("bar", "barbar"), ("baz", "bazbaz"), ("bla", "blabla")],
)
assert not errors

Expand Down