Repository navigation
Conversation
The not_null_proportion audit failed whenever the share of non-NULL values was less than or equal to the threshold, so a column that met the threshold exactly was reported as failing and `threshold := 1` could never pass, even for a column without a single NULL. Compare with `<` so the threshold is the minimum accepted proportion of non-NULL values. The docs described the threshold the other way around, as the maximum proportion of NULL values, so the documented example asserted the opposite of what the audit checks. Describe the threshold as the minimum proportion of non-NULL values, matching the implementation. Signed-off-by: Dhruv Gupta <todhruvg@gmail.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Description
Fixes #6250
The built-in
not_null_proportionaudit had two problems:count(column) <= count(*) * threshold. So a column whose non-NULL proportion equalled the threshold was reported as failing, andthreshold := 1could never pass, even for a column without a single NULL.docs/concepts/audits.mdsays the audit "ensures that the specified column's proportion ofNULLvalues is no greater than a threshold", and thatthreshold := 0.8allows up to 80% NULLs. The implementation has always treatedthresholdas the minimum proportion of non-NULL values, so the documented example checks the opposite of what it says (a column that is 50% NULL fails it).Changes:
sqlmesh/core/audit/builtin.py: compare with<instead of<=, sothresholdis the inclusive minimum proportion of non-NULL values.docs/concepts/audits.md: describethresholdas the minimum proportion of non-NULL values and reword thezipexample to match ("at least 80% notNULL, i.e. no more than 20%NULL").I chose to fix the docs rather than flip the implementation. The audit's name and the usage comment in
builtin.py(threshold=0.9) both point to the non-NULL reading, and flipping the direction would quietly change what every existingnot_null_proportionaudit checks.A side effect of using
<: an empty table, or aconditionthat matches no rows, now passes (0 < 0is false). That matchesnot_nulland the other per-row audits, which also pass on an empty table. Previously it failed for any threshold, including0.Test Plan
test_not_null_proportion_auditintests/core/test_audit.py, which runs the rendered audit against DuckDB for six cases: no NULLs withthreshold 1, one NULL withthreshold 1, exactly at the threshold, below the threshold, an all-NULL column withthreshold 0, and an empty table.main:4 failed, 2 passed(the no-NULLs-at-threshold-1, exactly-at-threshold, threshold-0 and empty-table cases fail).6 passed.pytest tests/core/test_audit.py tests/core/test_model.py tests/core/test_context.py -n 4:519 passed.pre-commit run --fileson the changed files: ruff, ruff-format, mypy all pass.Checklist
make styleand fixed any issuesmake fast-test)git commit -s) per the DCOSummary by CodeRabbit
not_null_proportionaudit so a result passes when the proportion of non-NULLvalues exactly meets the configured threshold.NULLvalues. For example, a threshold of0.8allows up to 20%NULLvalues.NULLvalues.