Why 90% of the catalog "changed": finding real differences between two data runs

A client re-imports a supplier's vehicle fitment data into their online store: for each part, the list of vehicles it fits. A full import covers tens of thousands of parts and takes a long time. The obvious improvement is to import only the parts whose fitment is new or different since last time.

Before building that, I tested the idea against two real deliveries. The comparison worked. The answer it gave was that nearly everything had changed. Both of those turned out to be useful.

What "changed" has to mean

Each part has a table of fitment rows with five columns: year range, make, model, position and notes. Comparing two deliveries byte for byte is hopeless, because plenty differs that does not matter:

So the definition I settled on: a part's fitment is the set of its rows, after cleaning each cell. It changed if that set is different.

The method

  1. Gather every file in a run into one lookup keyed by part number. Never compare file to file.
  2. For each part, pull out the data rows and skip headers and boilerplate.
  3. Clean each cell: decode HTML entities, collapse runs of whitespace, trim.
  4. Sort the rows and compare.

In Python, the core is a few lines. Hashing the sorted rows gives one short value per part that can be stored and compared later:

import hashlib, html, re

def fitment_hash(rows):
    cleaned = sorted(
        tuple(re.sub(r"\s+", " ", html.unescape(cell)).strip() for cell in row)
        for row in rows
    )
    return hashlib.sha256(repr(cleaned).encode()).hexdigest()

The result

The two deliveries were about 22 months apart.

PartsCount
In both runs46,352
Only in the new run11,248
Only in the old run16,054
In both, with different fitment41,813 (90.2%)

A filter that passes 90% of its input is not much of a filter. My first suspicion was my own code: surely formatting noise was leaking through.

Checking the checker

The test I used: take vehicles that appear for the same part in both runs, and compare their remaining columns. If the cleaning step were leaving noise behind, those would disagree often. Across thousands of shared rows they disagreed zero times.

So the differences were real. The new run had about 36% more fitment rows overall, for two reasons. Two more model years had been added. And the older run had under-captured parts with very long fitment lists: one part went from 346 rows to 8,839, and the larger number matched the source.

The baseline matters more than the diff

The comparison was correct and still not worth shipping as a one-off, because the baseline was too old and partly incomplete. Comparing against it would have meant re-importing almost the whole catalog anyway.

Change detection pays off between two recent, complete runs. That shifts the work from "write a comparison script" to "make every run leave a baseline behind":

Parts that have disappeared from the supplier keep their old rows and are never stamped, so they stay out of the import without special handling.

Takeaways

Re-importing an entire catalog every time something small changes? Tell me about it.