Module 5 · Days 41–50 · Part II

Quality Assurance with Great Expectations

Contract-driven data engineering and anomaly detection.

Start Day 41
0/10 days completed
0/10 videos published

What you'll learn

  1. 1
    Days 41–43
    Data quality principles, initializing contexts, and connecting to DuckDB sources.

    By the end: Students can reason about data quality systematically (dimensions, contracts, severities, ownership). They write a **data quality plan** for the macro warehouse, set up a **Great Expectations (GX) project**, connect it to DuckDB tables at every layer (raw_dlt, staging, marts), and run first validations against real Canadian data, including a cross-source consistency check.

  2. 2
    Days 44–47
    Expectation suites, profiling datasets, and automated Data Docs.

    By the end: The data quality plan from Day 41 is fully **executable**. Expectation suites are generated from reviewed YAML specifications ("suites as code"), and profiling of the actual data proposes thresholds that economists confirm. Checkpoints separate **critical** from **warning** checks, and every run produces a browsable **Data Docs** website plus a validation **history** you can query and trend in DuckDB.

  3. 3
    Days 48–50
    Validating incoming StatCan data: unemployment rates within 0–100%, continuous dates.

    By the end: New StatCan releases (the full Labour Force Survey table, plus CPI and GDP) no longer flow straight into the warehouse. They're **written** to a holding area, **audited** by Great Expectations against a precise contract, and only then **published**, or **quarantined** with an alert. The contract encodes the curriculum's headline rules exactly: *unemployment rates remain between 0 and 100%* and *dates are continuous without gaps*. It adds accounting identities, cross-source checks and release-completeness checks. dbt builds provincial labour-market marts from published data only, and the warehouse records data quality as a KPI.

Tools

Great ExpectationsDuckDBData Docs

The ten days

Before you start: module setup and project structure

Audience: MSc Economics students who completed Modules 1–4 (Days 1–40) Environment: GitHub Codespaces · macro.duckdb in production (dbt cut-over, Day 40) · a new, separate .venv-gx Time per day: ~2.5 hours (including breaks and exercises) Goal by end of Day 43: Students can reason about data quality systematically (dimensions, contracts, severities, ownership). They write a data quality plan for the macro warehouse, set up a Great Expectations (GX) project, connect it to DuckDB tables at every layer (raw_dlt, staging, marts), and run first validations against real Canadian data, including a cross-source consistency check.


Why another quality tool? We already have tests…

You've built quality checks at every stage:

WhereToolWhat it checksDay
Ingestiondlt schema contracts, Pydanticshape and types of incoming records25
Ingestionresilience layerHTTP failures, bad payloads, StatCan FAILED items29
Warehousedbt testskeys, ranges, relationships, gaps, freshness36
Warehousedbt contractsmart column names and types40

These are rules you thought of, expressed in developer tools. Great Expectations adds:

  1. Expectations as a shared, readable contract: "unemployment rate between 0 and 100%" as a declarative statement that economists, not just engineers, can read and review.
  2. Rich validation results: not just pass/fail, but how many rows failed, which values, and what share.
  3. Data Docs: a human-readable website of expectations and validation history (Days 44–47).
  4. Validation at boundaries and on batches: checking each newly arrived month of StatCan data, independent of how it's transformed later (Days 48–50).
  5. Distributional checks: means, quantiles and z-scores, not just row-by-row rules.

GX doesn't replace dbt tests. dbt tests protect the transformation logic; GX protects the data contract with the outside world and with consumers. Many teams use both, and you will too.

The plan for Module 5

DaysFocus
41–43Principles, a quality plan, GX installation, data contexts, DuckDB connection, first validations
44–47Expectation suites, profiling datasets, checkpoints, automated Data Docs
48–50Validating incoming StatCan data (unemployment 0–100%, continuous dates), integration with the pipeline

Target structure (by end of Day 43)

macro-data-course/
├── .venv/                      ← dlt + dbt (Modules 3–4)
├── .venv-gx/                   ← NEW: Great Expectations environment
├── quality/                    ← NEW: the GX project
│   ├── DATA_QUALITY_PLAN.md
│   ├── requirements-gx.txt
│   ├── gx/                     ← created by GX (the Data Context)
│   │   ├── great_expectations.yml
│   │   ├── expectations/
│   │   ├── validation_definitions/
│   │   ├── checkpoints/
│   │   └── uncommitted/        ← local-only: config variables, Data Docs, results
│   ├── gx_helpers.py
│   ├── setup_gx.py
│   └── smoke_check.py