Incremental loads and idempotency
So far, every run built one day from scratch. Real pipelines run daily forever — and they fail, get retried, and get re-run by hand. Two rules keep that safe: process only what is new (incremental), and make re-running a window harmless (idempotent) — the same input must always produce the same output, never doubles.
The code
import pandas as pd
KEYS = ["station", "time"] # the grain: one row per station per time
old = pd.read_parquet("lake/silver/observations.parquet")
new = pd.read_parquet("lake/silver_staging/date=2026-11-19.parquet")
merged = (pd.concat([old, new])
.drop_duplicates(subset=KEYS, keep="last")
.sort_values(KEYS))
merged.to_parquet("lake/silver/observations.parquet")
print(len(old), "+", len(new), "->", len(merged))
In practice
The key is the contract. (station, time) is this dataset's grain — the combination that makes a row *the same row*. Warehouses call it a unique_key and load with a MERGE: matched keys update, new keys insert. Append without a key and every retry writes the day twice.
keep="last" makes corrections win. Sources re-send fixed values all the time. Because the new batch is concatenated after the old table, the corrected row survives dedupe and the stale one drops. With keep="first", corrections are silently discarded — the pipeline 'works' and the data stays wrong.
Overlap your windows. Track the latest time processed (a watermark) and start the next run a little *before* it, letting dedupe absorb the overlap. Late-arriving data is normal; a pipeline that cannot absorb it loses rows quietly. And the idempotency test is brutal and simple: run the job twice, and the row count must not change.
Python bridge: The engine here is plain pandas drop_duplicates. The pipeline idea is choosing the key that defines 'same row' — and never appending blind.
Further reading
dbt Incremental Models: unique_key, Merge, Late Data — DataLane (a production walkthrough of the same contract in dbt: the filter decides the read, the unique_key decides the write)
Try it
Practice question: The source re-sends yesterday's file with one temperature corrected. Using the code above: does the corrected value end up in silver? And what changes if you had used keep="first"?
Show answer
Result: Yes — with keep="last" the re-sent row carries the same (station, time) key, lands after the original in the concatenated frame, and wins the dedupe, so the correction replaces the stale value. With keep="first" the original row wins and the correction is dropped without a sound: the run succeeds, the counts look right, and the wrong temperature lives forever. Idempotency plus keep="last" is what lets updates propagate; get either half wrong and the pipeline lies politely.