A warehouse has 60 shipment rows and a carrier price list that should contain one row per service_code. A repeated code in the price list can give one shipment two prices and push the invoice total up. Check the cardinality at the join, where you can still see which table needs attention.

priced = shipments.merge(
    rates, on="service_code", how="left",
    validate="many_to_one", indicator=True
)

Put two copies of NEXT_DAY in the rates fixture and run the merge. It should raise a merge error. Restore one rate, then add a shipment with a made-up code such as SATURDAY. The left join should keep the shipment and mark it left_only in _merge. Decide who resolves that row before producing a total payable amount.

Check blanks before joining

pandas can match null join keys on the two sides. If a missing service code means the shipment needs a manual lookup, send those rows to a separate review table first. Check the clean result against the number of eligible shipments, and account for every excluded row. A join can satisfy the expected row count and still be missing prices, so keep the match indicator until you finish that check.

Reconcile the counts and the payable subtotal

Use three sample shipments with distinct shipment IDs. Give two NEXT_DAY and one SATURDAY. With one next-day rate of 12 and no Saturday rate, the merge should produce all three IDs. Two rows should be marked both and one left_only. The matched charges sum to 24, with the Saturday shipment still unresolved.

Print unmatched service codes with their shipment IDs so someone can fix either the export or the price list. One final check should confirm that every eligible shipment ID appears once and that any missing rate is resolved before treating the subtotal as payable.

Sources