Skip to content

Data quality failures

Source: R/errors-quality.R ยท Help: ?data_quality_errors

Errors about the data itself rather than the code handling it: a file in the wrong format, a schema that does not match, drift from a reference distribution, leakage between training and test data, classes too imbalanced to learn from, and outlier detection that could not run. All inherit from dataexcept_data_science_error.

Usage

data_format_error(expected_formats, found_format, parent = NULL, call = NULL)

schema_mismatch_error(expected, found, parent = NULL, call = NULL)

data_drift_error(
  feature,
  drift_score,
  message = NULL,
  parent = NULL,
  call = NULL
)

data_leakage_error(feature, stage, message = NULL, parent = NULL, call = NULL)

data_imbalance_error(
  ratio,
  threshold,
  message = NULL,
  parent = NULL,
  call = NULL
)

outlier_detection_error(method, details = NULL, parent = NULL, call = NULL)

Arguments

expected_formats
Character vector of the formats accepted, such as c("csv", "parquet").
found_format
The format found.
parent
The condition that caused this one, or NULL.
call
The call to report, or NULL.
expected, found
Descriptions of the schema expected and the schema found, each a single string.
feature
Name of the feature concerned.
drift_score
The drift statistic, written to four decimal places in the default message.
message
A message to use instead of the default.
stage
The stage at which the leak was found, such as "cross-validation".
ratio
The ratio of the smallest class to the largest.
threshold
The smallest ratio accepted.
method
The name of the detection method.
details
Optional detail, appended to the message.

Value

A condition inheriting from dataexcept_data_science_error.

Details

Their failure metadata is "unknown" by default: the same data would fail again, but whether the data will change is for the caller to say.

Examples

check_balance <- function(y, threshold = 0.2) {
  counts <- table(y)
  ratio <- min(counts) / max(counts)
  if (ratio < threshold) stop(data_imbalance_error(ratio, threshold))
  invisible(y)
}
tryCatch(
  check_balance(c(rep("no", 95), rep("yes", 5))),
  dataexcept_data_imbalance_error = function(e) conditionMessage(e)
)

err <- data_drift_error("income", drift_score = 0.4172)
err$drift_score

schema_mismatch_error(
  expected = "id: integer, amount: numeric",
  found = "id: integer, amount: character"
)

See also

Other dataexcept errors: data_engineering_errors, data_frame_errors, file_errors, job_errors, model_quality_errors, modelling_errors, pipeline_errors, service_errors, validation_error()