fix(compare): census-sourced FSM/EAL benchmarks; never fall back across measure definitions
The FSM chip anchored against disadvantaged_pct (a different measure, FSM6+CLA) whenever fsm_pct was null — which it always was, since the performance df has no fsm_pct. New fact_census_benchmarks mart supplies pupil-weighted FSM/EAL means per phase; the KS2-column medians that produced a bogus 50% 'secondary disadvantaged' anchor are gone. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0146VHeLAWjDVE2B5uU67jCB
This commit is contained in:
@@ -57,19 +57,40 @@ def test_weighted_disadvantaged_average():
|
||||
def test_medians_ignore_nan_and_older_years():
|
||||
b = compute_benchmarks(_df())
|
||||
assert b["year"] == LATEST
|
||||
# eal medians over [10,20,30,40,50] = 30
|
||||
assert b["primary"]["eal_pct"] == 30.0
|
||||
# fsm medians over [15,17,19,21,23] = 19
|
||||
assert b["primary"]["fsm_pct"] == 19.0
|
||||
# median pupils over [200,280,300,350,400] = 300
|
||||
assert b["primary"]["median_pupils"] == 300
|
||||
# sen medians over [10,14,18,20,22] = 18 — the only context measure still
|
||||
# sourced from the performance df (the rest come from the census mart).
|
||||
assert b["primary"]["sen_support_pct"] == 18.0
|
||||
# disadvantaged_pct medians over [20,24,30,40,44] = 30
|
||||
assert b["primary"]["disadvantaged_pct"] == 30.0
|
||||
|
||||
|
||||
def test_benchmarks_use_census_mart_for_context():
|
||||
census = {
|
||||
"primary": {"year": LATEST, "fsm_pct": 25.3, "eal_pct": 21.8, "median_pupils": 240},
|
||||
"secondary": {"year": LATEST, "fsm_pct": 24.1, "eal_pct": 18.9, "median_pupils": 980},
|
||||
}
|
||||
b = compute_benchmarks(_df(), census_benchmarks=census)
|
||||
assert b["primary"]["fsm_pct"] == 25.3
|
||||
assert b["primary"]["eal_pct"] == 21.8
|
||||
assert b["secondary"]["eal_pct"] == 18.9
|
||||
assert b["secondary"]["median_pupils"] == 980
|
||||
|
||||
|
||||
def test_benchmarks_context_none_when_mart_missing():
|
||||
# The performance df has no fsm_pct and its eal/disadvantaged columns are
|
||||
# KS2-only — never silently fall back to medianing them for context.
|
||||
b = compute_benchmarks(_df(), census_benchmarks=None)
|
||||
assert b["primary"]["fsm_pct"] is None
|
||||
assert b["primary"]["eal_pct"] is None
|
||||
assert b["primary"]["median_pupils"] is None
|
||||
|
||||
|
||||
def test_secondary_block_has_no_disadvantaged_rwm():
|
||||
b = compute_benchmarks(_df())
|
||||
assert "disadvantaged_rwm_expected_pct" not in b["secondary"]
|
||||
assert b["secondary"]["fsm_pct"] == 13.0
|
||||
assert b["secondary"]["median_pupils"] == 1100
|
||||
# KS2-only columns must not produce a fake secondary disadvantaged anchor
|
||||
# (the old median over all-through schools' KS2 rows produced 50%).
|
||||
assert b["secondary"]["disadvantaged_pct"] is None
|
||||
|
||||
|
||||
def test_provenance_string():
|
||||
|
||||
Reference in New Issue
Block a user