Complete worked example
python
import pandas as pd
def inspect_example(rows):
if any(type(r.get("company")) is not str or type(r.get("job_id")) is not str for r in rows):
raise ValueError("string keys required")
frame = pd.DataFrame(rows, columns=["company", "job_id"]).astype("string")
frame["company"] = frame["company"].str.strip().str.lower()
frame["job_id"] = frame["job_id"].str.strip()
if frame.eq("").any().any() or frame.duplicated(["company", "job_id"]).any():
raise ValueError("blank or duplicate key")
return frame- Reasoning
- Validate the original field types before converting to nullable string columns. Otherwise an integer identifier might be silently converted after leading zeros were already lost. Strip company and job_id separately, normalize only company, then detect empty values and duplicated composite keys. Return the normalized pair in input order. Selecting the explicit two-column schema also works for an empty batch. Trace company Acme with job ABC and company acme with job abc. These are two distinct jobs because the opaque ID preserves case. Company Acme with ABC repeated under different company capitalization is a duplicate under this declared namespace.