Download tests/test_release.py from milkyroad/bench: direct link, hf CLI and curl.
- Browser
- Download file 1.75 kB
-
https://huggingface.co/datasets/milkyroad/bench/resolve/main/tests/test_release.py
- Command line
-
hf download hf://datasets/milkyroad/bench/tests/test_release.py
-
curl -L -o test_release.py https://huggingface.co/datasets/milkyroad/bench/resolve/main/tests/test_release.py
1.75 kB
| """Release invariants: integrity, anonymisation, and shape.""" | |
| from __future__ import annotations | |
| import re | |
| import polars as pl | |
| import pytest | |
| from cystobench.audit import audit | |
| from cystobench.baselines import still_predictions | |
| from cystobench.harness import score | |
| from cystobench.loader import load_clips, load_stills | |
| ID_PATTERNS = {"sample_id": r"^s\d{6}$", "patient_id": r"^p\d{3}$"} | |
| def stills(): | |
| return load_stills() | |
| def test_release_passes_audit(): | |
| assert audit(check_media=False) == [] | |
| def test_identifiers_are_anonymised(stills): | |
| for column, pattern in ID_PATTERNS.items(): | |
| assert all(re.match(pattern, v) for v in stills[column].unique().to_list()), column | |
| def test_oracle_scores_one(): | |
| assert score(level="stills", axis="2c", preds=still_predictions("oracle", load_stills()))["f1"] == 1.0 | |
| def test_majority_class_floor(): | |
| result = score( | |
| level="stills", axis="2c", preds=still_predictions("always_non_roi", load_stills()) | |
| ) | |
| assert result["f1"] == pytest.approx(0.2851, abs=5e-4) | |
| def test_stills_shape(stills): | |
| assert stills.height == 5807 | |
| assert stills["patient_id"].n_unique() == 113 | |
| assert set(stills["class_label"].unique().to_list()) == { | |
| "malignant_tumor", | |
| "non_malignant_lesion", | |
| "non_roi", | |
| } | |
| def test_clip_shape(): | |
| clips = load_clips() | |
| assert clips.height == 161 | |
| assert clips["patient_id"].n_unique() == 27 | |
| def test_stills_and_clips_share_no_patient(stills): | |
| assert not set(stills["patient_id"].to_list()) & set(load_clips()["patient_id"].to_list()) | |
| def test_no_split_column_remains(stills): | |
| assert "split" not in stills.columns | |
| assert "split" not in load_clips().columns | |