tlf-hypothesis-testing
Country-agnostic statistical hypothesis testing — part of TLF ("The Living Facts").
Runs seven hypothesis tests over any pandas DataFrame — two-sample, paired, multi-group, and categorical-association tests — and returns each result as a plain dict with the test statistic, p-value, and the sample-size info behind it.
Unlike tlf-census-stats, this package has no dependency on a specific
country schema — it works on any DataFrame with the right column shape
for the test you choose.
Install
pip install tlf-hypothesis-testing
Or from source, inside the TLF-Data-Analysis monorepo:
cd tlf-hypothesis-testing
pip install -e ".[dev]"
Usage
import pandas as pd
from tlf_hypothesis_testing import HypothesisTestEngine
df = pd.read_csv("census_data.csv")
# Two-sample: compare literacy rate between exactly 2 groups
engine = HypothesisTestEngine(df, test="t_test") # or "welch_t_test" / "mann_whitney"
engine.run(value_col="literacy_rate", group_col="area_type")
# Paired: compare two matched/before-after numeric columns
engine = HypothesisTestEngine(df, test="paired_t_test")
engine.run(col1="literacy_rate_2011", col2="literacy_rate_2021")
# Multi-group: compare literacy rate across 2+ groups
engine = HypothesisTestEngine(df, test="anova") # or "kruskal_wallis"
engine.run(value_col="literacy_rate", group_col="province")
# Categorical association between two columns
engine = HypothesisTestEngine(df, test="chi_square")
engine.run(col1="province", col2="area_type")
Tests
| Test | Column shape | Use for |
|---|---|---|
t_test |
value_col + group_col (exactly 2 groups) |
Independent samples, assumes equal variance |
welch_t_test |
value_col + group_col (exactly 2 groups) |
Independent samples, does not assume equal variance |
paired_t_test |
col1 + col2 |
Matched/before-after samples, same length |
mann_whitney |
value_col + group_col (exactly 2 groups) |
Non-parametric alternative to the t-test |
anova |
value_col + group_col (2+ groups) |
Compare means across 3+ groups |
kruskal_wallis |
value_col + group_col (2+ groups) |
Non-parametric alternative to ANOVA |
chi_square |
col1 + col2 (both categorical) |
Association between two categorical columns |
A group with fewer than 2 non-null observations is dropped automatically
before anova/kruskal_wallis run; t_test/welch_t_test/mann_whitney
require group_col to split the data into exactly 2 groups, or they
raise InvalidGroupCountError.
CLI
tlf-hypothesis-testing --data census.csv --test anova --value-col literacy_rate --group-col province
Run with no flags at all for a fully interactive walkthrough (file path
→ sheet selection → test → columns → export format). Column prompts are
dtype-aware: numeric columns are listed first when picking a value
column, and categorical/low-cardinality columns are listed first when
picking a group column — each annotated with its type and unique-value
count (e.g. Province (categorical, 3 unique)) so it's clear which
columns actually make sense for the role, though every column stays
selectable either way:
tlf-hypothesis-testing
For unattended/scripted runs, --yes disables all prompting and fails
loudly (rather than silently guessing) if something required — like
--data — is missing:
tlf-hypothesis-testing --data census.csv --yes --test chi_square --col1 province --col2 area_type
CLI flags
| Flag | Description |
|---|---|
--data |
Path to a CSV, Excel, or JSON file |
--sheet |
Excel sheet name (default: first sheet) |
--test |
t_test | welch_t_test | paired_t_test | mann_whitney | anova | kruskal_wallis | chi_square |
--value-col |
Value column (two-sample / multi-group tests) |
--group-col |
Group column (two-sample / multi-group tests) |
--col1 |
First column (paired_t_test / chi_square) |
--col2 |
Second column (paired_t_test / chi_square) |
--export |
csv | json |
--export-path |
Export file path. If it doesn't already end in .csv/.json (matching --export), the right extension is appended automatically. |
--yes |
Non-interactive mode: never prompt, error on missing required values |
Errors
InvalidTestError— unsupportedtestvalueInsufficientDataError— a sample/group has too few non-null observations for the testInvalidGroupCountError—group_coldoesn't split the data into exactly 2 groups for a two-sample testColumnNotFoundError— a required column isn't present in the DataFrame
License
MIT — see LICENSE.
Metadata
Release files for tlf-hypothesis-testing 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tlf_hypothesis_testing-0.1.0.tar.gz | 18.1 kB | Without provenance | Details for tlf_hypothesis_testing-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tlf_hypothesis_testing-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for tlf_hypothesis_testing-0.1.0-py3-none-any.whl |
Total release size: 33.8 kB
Release files / tlf_hypothesis_testing-0.1.0.tar.gz
| Download URL | tlf_hypothesis_testing-0.1.0.tar.gz |
|---|---|
| Size | 18.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f4f76c7a143537a441fe4a8063cfe3e95eddb6a84c3c9da455136ac47fa3e56f
|
|
BLAKE2b-256 checksum How to use checksums |
5d982ab63c0b6ef7cf09e87fbc1e42fafcd45549fe895bb254f634e8d5fb6905
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / tlf_hypothesis_testing-0.1.0-py3-none-any.whl
| Download URL | tlf_hypothesis_testing-0.1.0-py3-none-any.whl |
|---|---|
| Size | 15.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b363355186594a4859a7c42ec37c0604ba971c8549ba89d117a6bcaa8bf41fd4
|
|
BLAKE2b-256 checksum How to use checksums |
21fe6894b3d4da4f7c320fa877ef0d221ab48e87e59bc2f30c11426fb2039b07
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for tlf-hypothesis-testing 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.