FAILURE MAP
← Case archive

FA-48611 / Delimited text / Open access

Union binding maps cell values to column names · case 01

A structured table violates the declared record or column contract.

Verified by executionVariant 1 · 7 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

Union binding maps cell values to column names.

VERIFIED REPAIR

Preserve the named invariant at the faulty decision: mapping=dict(zip(table['header'],row))

Unsuccessful approach: The alternate implementation still violates the same declared invariant: union binding maps cell values to column names.

Case contract

Combine a list of tables, each {header:[names], rows:[[cells]]}. Output header is the first-seen union of names, preserving first-seen order. Duplicate names within one input header and row-width mismatches reject. Missing columns in a table become null; explicit empty values remain empty. Return {header,rows}.

Why this case matters

Delimited interchange needs explicit framing, schema and field semantics at ingestion and emission boundaries.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
def _vary(value):
    if value == '@END': return 3 + 4*N
    if isinstance(value, str): return value.replace('@', 'cell' * N)
    if isinstance(value, list): return [_vary(x) for x in value]
    if isinstance(value, dict): return {_vary(k): _vary(v) for k,v in value.items()}
    return value
N = 1
observations = []
def solve(data):
    header=[]
    for table in data:
        if len(set(table['header']))!=len(table['header']): return None
        for name in table['header']:
            if name not in header: header.append(name)
    out=[]
    for table in data:
        for row in table['rows']:
            if len(row)!=len(table['header']): return None
            mapping=dict(zip(row,table['header']))
            out.append([mapping.get(name) for name in header])
    return {'header':header,'rows':out}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('union', solve(_vary([{'header': ['b', 'a'], 'rows': [['@', 'x']]}, {'header': ['a', 'c'], 'rows': [['y', 'z']]}])), _vary({'header': ['b', 'a', 'c'], 'rows': [['@', 'x', None], [None, 'y', 'z']]}))
check('reordered', solve(_vary([{'header': ['a', 'b'], 'rows': [['@', 'x']]}, {'header': ['b', 'a'], 'rows': [['z', 'y']]}])), _vary({'header': ['a', 'b'], 'rows': [['@', 'x'], ['y', 'z']]}))
check('duplicate', solve(_vary([{'header': ['a', 'a'], 'rows': []}])), _vary(None))
check('ragged', solve(_vary([{'header': ['a', 'b'], 'rows': [['@']]}])), _vary(None))
check('explicit empty', solve(_vary([{'header': ['a'], 'rows': [['']]}, {'header': ['b'], 'rows': [['@']]}])), _vary({'header': ['a', 'b'], 'rows': [['', None], [None, '@']]}))
check('empty', solve(_vary([])), _vary({'header': [], 'rows': []}))
check('header only', solve(_vary([{'header': ['@'], 'rows': []}])), _vary({'header': ['@'], 'rows': []}))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
union{'header': ['b', 'a', 'c'], 'rows': [[None, None, None], [None, None, None]]}{'header': ['b', 'a', 'c'], 'rows': [['cell', 'x', None], [None, 'y', 'z']]}Failed
reordered{'header': ['a', 'b'], 'rows': [[None, None], [None, None]]}{'header': ['a', 'b'], 'rows': [['cell', 'x'], ['y', 'z']]}Failed
duplicateNoneNonePassed
raggedNoneNonePassed
explicit empty{'header': ['a', 'b'], 'rows': [[None, None], [None, None]]}{'header': ['a', 'b'], 'rows': [['', None], [None, 'cell']]}Failed
empty{'header': [], 'rows': []}{'header': [], 'rows': []}Passed
header only{'header': ['cell'], 'rows': []}{'header': ['cell'], 'rows': []}Passed

SHA-256 / 8dda37e4eb461b9613d30cb45b8afefc1a8292f193638e2990cbbf375a206620

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
def _vary(value):
    if value == '@END': return 3 + 4*N
    if isinstance(value, str): return value.replace('@', 'cell' * N)
    if isinstance(value, list): return [_vary(x) for x in value]
    if isinstance(value, dict): return {_vary(k): _vary(v) for k,v in value.items()}
    return value
N = 1
observations = []
def solve(data):
    header=[]
    for table in data:
        if len(set(table['header']))!=len(table['header']): return None
        for name in table['header']:
            if name not in header: header.append(name)
    out=[]
    for table in data:
        for row in table['rows']:
            if len(row)!=len(table['header']): return None
            mapping=dict(zip(sorted(table['header']),row))
            out.append([mapping.get(name) for name in header])
    return {'header':header,'rows':out}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('union', solve(_vary([{'header': ['b', 'a'], 'rows': [['@', 'x']]}, {'header': ['a', 'c'], 'rows': [['y', 'z']]}])), _vary({'header': ['b', 'a', 'c'], 'rows': [['@', 'x', None], [None, 'y', 'z']]}))
check('reordered', solve(_vary([{'header': ['a', 'b'], 'rows': [['@', 'x']]}, {'header': ['b', 'a'], 'rows': [['z', 'y']]}])), _vary({'header': ['a', 'b'], 'rows': [['@', 'x'], ['y', 'z']]}))
check('duplicate', solve(_vary([{'header': ['a', 'a'], 'rows': []}])), _vary(None))
check('ragged', solve(_vary([{'header': ['a', 'b'], 'rows': [['@']]}])), _vary(None))
check('explicit empty', solve(_vary([{'header': ['a'], 'rows': [['']]}, {'header': ['b'], 'rows': [['@']]}])), _vary({'header': ['a', 'b'], 'rows': [['', None], [None, '@']]}))
check('empty', solve(_vary([])), _vary({'header': [], 'rows': []}))
check('header only', solve(_vary([{'header': ['@'], 'rows': []}])), _vary({'header': ['@'], 'rows': []}))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
union{'header': ['b', 'a', 'c'], 'rows': [['x', 'cell', None], [None, 'y', 'z']]}{'header': ['b', 'a', 'c'], 'rows': [['cell', 'x', None], [None, 'y', 'z']]}Failed
reordered{'header': ['a', 'b'], 'rows': [['cell', 'x'], ['z', 'y']]}{'header': ['a', 'b'], 'rows': [['cell', 'x'], ['y', 'z']]}Failed
duplicateNoneNonePassed
raggedNoneNonePassed
explicit empty{'header': ['a', 'b'], 'rows': [['', None], [None, 'cell']]}{'header': ['a', 'b'], 'rows': [['', None], [None, 'cell']]}Passed
empty{'header': [], 'rows': []}{'header': [], 'rows': []}Passed
header only{'header': ['cell'], 'rows': []}{'header': ['cell'], 'rows': []}Passed

SHA-256 / de8842621a0de962b280cd4b8081fbbddb7ad5ed81e890dcc9a1f82c34b1fd51

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
def _vary(value):
    if value == '@END': return 3 + 4*N
    if isinstance(value, str): return value.replace('@', 'cell' * N)
    if isinstance(value, list): return [_vary(x) for x in value]
    if isinstance(value, dict): return {_vary(k): _vary(v) for k,v in value.items()}
    return value
N = 1
observations = []
def solve(data):
    header=[]
    for table in data:
        if len(set(table['header']))!=len(table['header']): return None
        for name in table['header']:
            if name not in header: header.append(name)
    out=[]
    for table in data:
        for row in table['rows']:
            if len(row)!=len(table['header']): return None
            mapping=dict(zip(table['header'],row))
            out.append([mapping.get(name) for name in header])
    return {'header':header,'rows':out}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('union', solve(_vary([{'header': ['b', 'a'], 'rows': [['@', 'x']]}, {'header': ['a', 'c'], 'rows': [['y', 'z']]}])), _vary({'header': ['b', 'a', 'c'], 'rows': [['@', 'x', None], [None, 'y', 'z']]}))
check('reordered', solve(_vary([{'header': ['a', 'b'], 'rows': [['@', 'x']]}, {'header': ['b', 'a'], 'rows': [['z', 'y']]}])), _vary({'header': ['a', 'b'], 'rows': [['@', 'x'], ['y', 'z']]}))
check('duplicate', solve(_vary([{'header': ['a', 'a'], 'rows': []}])), _vary(None))
check('ragged', solve(_vary([{'header': ['a', 'b'], 'rows': [['@']]}])), _vary(None))
check('explicit empty', solve(_vary([{'header': ['a'], 'rows': [['']]}, {'header': ['b'], 'rows': [['@']]}])), _vary({'header': ['a', 'b'], 'rows': [['', None], [None, '@']]}))
check('empty', solve(_vary([])), _vary({'header': [], 'rows': []}))
check('header only', solve(_vary([{'header': ['@'], 'rows': []}])), _vary({'header': ['@'], 'rows': []}))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
union{'header': ['b', 'a', 'c'], 'rows': [['cell', 'x', None], [None, 'y', 'z']]}{'header': ['b', 'a', 'c'], 'rows': [['cell', 'x', None], [None, 'y', 'z']]}Passed
reordered{'header': ['a', 'b'], 'rows': [['cell', 'x'], ['y', 'z']]}{'header': ['a', 'b'], 'rows': [['cell', 'x'], ['y', 'z']]}Passed
duplicateNoneNonePassed
raggedNoneNonePassed
explicit empty{'header': ['a', 'b'], 'rows': [['', None], [None, 'cell']]}{'header': ['a', 'b'], 'rows': [['', None], [None, 'cell']]}Passed
empty{'header': [], 'rows': []}{'header': [], 'rows': []}Passed
header only{'header': ['cell'], 'rows': []}{'header': ['cell'], 'rows': []}Passed

SHA-256 / e4872d3961c87210a1ee583e451be27d5b2d67f57f854db1139e988716afa70f

Verification & scope

Deterministic bounded in-memory model. No claim of complete CSV or external format conformance. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:44:52.393584+00:00.

Case digest / 03a5899f640ffda0593799e7177de2c20b9b4ef1cde7acc37056694b5d6304dd