Turn Two Catalog Snapshots Into an Explainable Row-Level Diff

A sanctioned export produced with a collector from 2scraper can contain thousands of rows, but a useful change report explains what happened to one product. This example builds a field-level difference from two fictional snapshots with the same documented scope. It reports newly observed, missing and changed items separately.
Prove that two snapshots can be compared
Give the files a shared source scope and a declared row grain before looking for changes. A different marketplace, currency or coverage window can alter the set of rows without establishing that the underlying catalog changed. Record both snapshot IDs and the overlap the resulting diff actually represents. A file that only contains a tested subset can support a comparison within that subset once it is named.
Decide how the reader should treat keys absent from the second snapshot. Missing observation is a useful neutral status. A product discontinued label requires evidence issued by the source or a separate validated rule. The fixture reports disappearance from the reviewed data as unobserved in the second export. That wording is specific to the evidence our code can see.
Describe a field change only under a reviewed mapping
Compare selected fields after normalizing them under a named rule. Operations might choose to track amount in minor units and a known currency while treating a change in display whitespace as incidental. Store the normalization rule beside the diff. A rule revision can change the recorded results for the same two snapshots, and the team should be able to reproduce the original interpretation.
An analyst asking why a subtotal moved may need the old and new accepted amount for one product. A public summary can carry counts and synthetic examples, while a restricted review packet contains the source row references. Give each diff entry an identity, the earlier value, the later value and the exact field compared. If a value is absent, record that state independently from a zero or empty string.
Run the synthetic fixture
Two dictionaries model already validated unique keys in explicitly comparable scopes. The function returns one row per key and the smallest reason for the disposition. All amounts are invented minor units and no external system is contacted.
def diff(before, after):
for key in sorted(before.keys() | after.keys()):
if key not in before:
yield key, "newly observed", None, after[key]
elif key not in after:
yield key, "unobserved later", before[key], None
elif before[key] != after[key]:
yield key, "amount changed", before[key], after[key]
else:
yield key, "unchanged", before[key], after[key]
earlier = {"A": 100, "B": 200, "C": 300}
later = {"B": 220, "C": 300, "D": 400}
rows = list(diff(earlier, later))
assert [r[1] for r in rows] == ["unobserved later", "amount changed", "unchanged", "newly observed"]
assert sum(r[1] == "amount changed" for r in rows) == 1
for row in rows:
print(row)
('A', 'unobserved later', 100, None)
('B', 'amount changed', 200, 220)
('C', 'unchanged', 300, 300)
('D', 'newly observed', None, 400)
A appears only in the earlier fixture and D only in the later one. The comparable amount for B changes from 200 to 220, while C is unchanged. The four dispositions cover the complete union of validated keys. They enrich the comparison without implying why an observation is missing.
Review the boundary cases
Historical offer absent. Remove one product from the later approved fixture. The expected result is unobserved later. An analyst can see what the export supports without declaring product deletion.
One new record. Add a distinct product to the later export. The expected result is newly observed. The classification refers to the observation window, which may differ from its creation date.
Currency context changed. Give the later amount a new currency. The expected result is a hold at the comparison boundary. A changed numeric value requires a shared definition.
Upstream delivery incomplete. Supply two comparable headers but a truncated body. The expected result is an incomplete view with exclusions named. An apparently large change can originate in delivery metadata.
Keep missingness meaningful across export editions
A truncated file can make every later product look removed. Validate delivery completeness before classifying a product disappearance. A baseline schema may also label an uncollected field differently from an unavailable value. Read both contracts and choose a comparable scope for the specific field. Give the reader a reason when you exclude an item or a field from the meaningful comparison.
Reject duplicate identifiers during normalization. Selecting the last row can make a report change when producer ordering changes. Store the conflicting row locations and let the data owner choose a rule when duplicates describe legitimate revisions. A versioned timestamp and durable revision ID can make that decision explicit once the consumer has documented what a snapshot should contain.
Use a small diff during deployment review
Make one test record present only in the earlier file, one only in the later file, one with a changed amount and one unchanged. Run the data through the same mapping used in a larger report. Sum the counts and confirm that the union of eligible keys is fully accounted for. Repeat after intentionally changing source order and ask the reporter which item remains uncertain.
In a staged rollout, keep the earlier valid report accessible until recipients can explain a changed total from its leaf records. A spike in missing observations deserves a separate event when a producer also changed its collection scope. Add the two coverage statements to the note. If coexistence is unavoidable, label reports by scope so their totals are interpreted in context.
Keep the evidence with the decision
I would make the review packet small enough that the catalog report maintainer can read it without the development environment. Start with two approved snapshot manifests and their validated row mappings. Put the rule and its version beside the inputs and name the comparison grain as one compatible source scope, product identity and field definition. The reader should be able to mark each item independently with one disposition before looking at what the program did. Ask them to point to the field and source behind at least one accepted item. If they can only infer the rule from a convenient example, the packet is still missing an explicit assumption.
For each outcome in separate new, missing, changed and unchanged classifications, keep a bounded reference to the original evidence and the reason it passed. Give a missing observation or an incompatible source contract a distinct disposition and a visible route for another review. That route should describe the missing information without implying that an unobserved event occurred. A report that silently drops unresolved rows can look unusually clean, and downstream counts can change after a reviewer supplies the missing evidence. Record which observations left the reviewed population and the rule that decides when they may re-enter it.
Use snapshot IDs, row references and mapping revision to confirm that an ordinary report can be reconstructed from a dated source. Keep a copy of the earlier rule when it is still used to interpret a previous report. A new decision should have its own effective date and evidence reference. Make an independent reviewer run the same small case, then ask them why the earlier and later outcomes differ. This will also show whether a changed summary was caused by a new input, an updated decision rule, or a change in formatting and labeling.
Decide where the data stops moving if a required part of two approved snapshot manifests and their validated row mappings is unavailable. If the usual reader can use a prior validated output, give it a timestamp and label that output as the last valid observation. Send reviewers a short reason that identifies a missing observation or an incompatible source contract within the scope of one compatible source scope, product identity and field definition. Avoid putting a raw private record or secret into the report to make support easier. The normal access controls can retain those details while the handoff preserves enough information to reproduce the classification.
Exercise the handoff before depending on it
Give two people comparable copies of the fixture. Ask one to explain which conclusions the output supports and one to identify the first place a bad result becomes visible. Both should have the same definitions of separate new, missing, changed and unchanged classifications. Then replace only one record with an unresolved variant. A clear workflow can tell the user the item is waiting on evidence without giving it the same status as an established failure. Capture the wording and the first place in the process where the decision changes.
Check cases where the export itself is valid but the context is wrong. Use one complete example outside one compatible source scope, product identity and field definition and see whether the routine workflow keeps it out of the result. Then change the input order and verify that the same report can still be reproduced. Where sequence is meaningful, record how it was established and add an explicit opposite-case test. An accidental dependence on an input file ordering can be difficult to notice when a successful run only shows final totals.
For the first real rollout, run the new check against one small approved sample and retain the earlier interpretation for comparison. Count the visible outcomes and sample one that changed and one that stayed the same. When the differences concern a missing observation or an incompatible source contract, confirm what a reader would do next and which owner has the evidence needed to act. Leave the previous release available until the catalog report maintainer can explain any material differences that affect ordinary decisions.
Record one success criterion and one reason to stop the rollout before the first real run. A useful criterion names separate new, missing, changed and unchanged classifications and says who will verify it. A stop decision should identify whether the failure affects the whole report or only a documented subset. Keep the recorded disposition separate from the decision to review a new release. This protects a prior evidence packet while allowing the team to correct a rule that only appeared to work on a convenient sample.
Try a four-row comparison before examining a trend
Select a documented export format at 2scraper. Make two small fictional snapshots that share the same scope and differ in exactly one amount. Check which observations your diff can explain, then deliberately make the output incomplete and confirm the report preserves that uncertainty.
Prepared with AI assistance. The code was run on local synthetic data. The example illustrates the reporting method. It makes no claim about measured service performance.
Further reading
Run a Versioned CSV Column Rename Without Breaking Existing Catalog Imports shows how a revised producer field can be mapped before a comparison.
Trace Catalog Row Loss Before an Inner Join Reaches the Dashboard offers a companion audit technique for explaining individual missing rows.
Comments
Join the discussionNo comments yet. Be the first to comment.





