Audit eval coverage with an outer merge and the indicator column
Why it matters Coverage checks between expected and produced items stop silent gaps in eval runs and data pipelines.
After an eval job, some expected items have no result (crashes) and some results have ids that were never expected (a stale config). An outer merge with indicator=True finds both in one step.
Write coverage_audit(expected, results) where expected has a column item_id (unique ints) and results has columns item_id and score, at most one row per item_id.
Return a dict {'missing': [...], 'extra': [...], 'matched': k} where missing lists item_ids in expected but not in results, extra lists item_ids in results but not in expected (both sorted ascending, as plain ints), and matched is how many item_ids are in both.
def coverage_audit(expected, results)Example
expected [1, 2, 3], results ids [2, 3, 9] give {'missing': [1], 'extra': [9], 'matched': 2}.
Understand the idea
A merge joins two tables on a key. how='outer' keeps every key from both sides, filling the other side with NaN when there is no partner. indicator=True adds a _merge column that says 'left_only', 'right_only' or 'both' for every row.
Worked example: expected ids [1, 2, 3] and result ids [2, 3, 9]. The outer merge has rows 1 (left_only), 2 (both), 3 (both), 9 (right_only). So missing = [1], extra = [9], matched = 2.
Rule: left_only = in A not B, right_only = in B not A, both = in A and B. It is a set difference and intersection in one call.
Eval harnesses, data reconciliation between two systems and checks that every document got an embedding all use this pattern.