Skip to content

Commit

Permalink
Fix a bug in that caused custom validations to always report anomalies
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 671804127
  • Loading branch information
tfx-copybara committed Sep 6, 2024
1 parent 358631a commit 3a64d24
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

## Bug Fixes and Other Changes

* Fix bug in implementation of custom validations.
* Depends on `tensorflow>=2.15,<2.16`.

## Known Issues
Expand Down
18 changes: 10 additions & 8 deletions tensorflow_data_validation/anomalies/custom_validation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ absl::Status GetFeatureStatistics(
}

absl::Status MergeAnomalyInfos(const AnomalyInfo& anomaly_info,
const std::string& key,
AnomalyInfo* existing_anomaly_info) {
const std::string& key,
AnomalyInfo* existing_anomaly_info) {
if (Path(anomaly_info.path()).Compare(Path(existing_anomaly_info->path())) !=
0) {
return absl::AlreadyExistsError(
Expand Down Expand Up @@ -242,13 +242,15 @@ absl::Status CustomValidateStatistics(
"Attempt to run query: ", validation.sql_expression(),
" failed with the following error: ",
query_result.status().ToString()));
} else if (!query_result.value()) {
// If the sql_expression evaluates to False, there is an anomaly.
TFDV_RETURN_IF_ERROR(UpdateAnomalyResults(
feature_pair_validation.feature_test_path(),
feature_pair_validation.dataset_name(),
feature_pair_validation.base_dataset_name(),
feature_pair_validation.feature_base_path(), validation,
result));
}
// If the sql_expression evaluates to False, there is an anomaly.
TFDV_RETURN_IF_ERROR(UpdateAnomalyResults(
feature_pair_validation.feature_test_path(),
feature_pair_validation.dataset_name(),
feature_pair_validation.base_dataset_name(),
feature_pair_validation.feature_base_path(), validation, result));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ TEST(CustomValidationTest, TestPairValidation) {
severity: ERROR
description: 'Test feature has too many zeros.'
}
validations {
sql_expression: 'feature_test.num_stats.num_zeros > feature_base.num_stats.num_zeros'
severity: ERROR
description: 'Base feature has too few zeros.'
}
})pb");
metadata::v0::Anomalies expected_anomalies = ParseTextProtoOrDie<
metadata::v0::Anomalies>(
Expand Down

0 comments on commit 3a64d24

Please sign in to comment.