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/Improve batch columnar validation #751

Closed
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 5 additions & 10 deletions src/power_grid_model/validation/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,17 @@ def validate_batch_data(

input_errors: list[ValidationError] = list(validate_unique_ids_across_components(input_data))

# Convert to row based if in columnar format
# TODO(figueroa1395): transform to columnar per single batch scenario once the columnar dataset python extension
# is finished
row_update_data = compatibility_convert_row_columnar_dataset(update_data, None, DatasetType.update)

# Splitting update_data_into_batches may raise TypeErrors and ValueErrors
batch_data = convert_batch_dataset_to_batch_list(row_update_data)
batch_data = convert_batch_dataset_to_batch_list(update_data)

errors = {}
for batch, batch_update_data in enumerate(batch_data):
assert_valid_data_structure(batch_update_data, DatasetType.update)
id_errors: list[ValidationError] = list(validate_ids_exist(batch_update_data, input_data))
row_update_data = compatibility_convert_row_columnar_dataset(batch_update_data, None, DatasetType.update)
assert_valid_data_structure(row_update_data, DatasetType.update)
id_errors: list[ValidationError] = list(validate_ids_exist(row_update_data, input_data))

batch_errors = input_errors + id_errors
if not id_errors:
merged_data = update_input_data(input_data, batch_update_data)
merged_data = update_input_data(input_data, row_update_data)
batch_errors += validate_required_values(merged_data, calculation_type, symmetric)
batch_errors += validate_values(merged_data, calculation_type)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/validation/test_batch_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_validate_batch_data_input_error(input_data, batch_data):


def test_validate_batch_data_update_error(input_data, batch_data):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a validation case with columnar input and columnar update dataset?

batch_data["line"]["from_status"] = [[12, 34], [0, -128], [56, 78]]
batch_data["line"]["from_status"] = np.array([[12, 34], [0, -128], [56, 78]])
errors = validate_batch_data(input_data, batch_data)
assert len(errors) == 2
assert [NotBooleanError("line", "from_status", [5, 6])] == errors[0]
Expand Down