Standard-library sampling engine, sample sizes, and deviation limits !3

merged merged by cmc on 2026-10-29 21:02 UTC · audit-labs/audit-tools:sampling-engine into main

Discussion

cmc
  • sampling/sampling_tool/engine.py (standard library only): select_random, select_systematic, select_stratified, each seeded from audit-sample:<seed>[:<stratum>], so a seed selects the same rows on every install, with or without pandas. ENGINE_VERSION = "2" is written to sample manifests.
  • attribute_sample_size(risk, tolerable, expected) and upper_deviation_limit(n, deviations, risk) from the binomial distribution; limits are rounded up to one decimal. evaluate_attribute_sample; FREQUENCY_PRESETS.
  • random_sample and stratified_sample (pandas) select through the engine; audit-sample --method systematic.
  • Selections differ from version 1 for the same seed (they used DataFrame.sample); version 1 runs stay verifiable from their outputs.
  • Tests: every cell of the 5% and 10% risk AICPA evaluation tables reproduced for n = 20, 25, 50, 100, 200, 500 (never below the table, at most 0.1 above where the table rounds to nearest; for example n = 200 with 6 deviations is 5.83%, shown as 5.8); 15 AICPA sample sizes; pinned selections. 64 passed (tui/tests/test_app.py needs textual).