Complete worked example
python
import pandas as pd
def inspect_example(batches):
frames = []
for batch in batches:
if any(set(r) != {"id", "score"} for r in batch):
raise ValueError("batch schema drift")
frames.append(pd.DataFrame(batch, columns=["id", "score"]).astype({"id": "string", "score": "Float64"}))
result = pd.concat(frames, ignore_index=True) if frames else pd.DataFrame({"id": pd.Series(dtype="string"), "score": pd.Series(dtype="Float64")})
if result["id"].isna().any() or result["id"].duplicated().any():
raise ValueError("duplicate or missing role ID")
return result- Reasoning
- Construct each batch with the same declared columns and nullable dtypes. Reject records with missing or extra fields before construction. Pass the list of frames to one pd.concat call with ignore_index=True, avoiding repeated incremental concatenation. If there are no batches, construct the same typed empty schema explicitly. Reject missing or repeated IDs in the combined frame. Trace batch one containing a and batch two containing b. Their local row indexes may both start at zero; the combined presentation index becomes zero and one. Their business IDs remain a and b. A repeated a in the second batch is an identity conflict even though the new row index is unique.