C.W.K.
Stream
Lesson 02 of 06 · published

Great Expectations — Cross-Team Data Tests

~12 min · validation, great-expectations, data-contracts

Level 0Curious Reader
0 XP0/47 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

The heavier-weight cousin of Pandera

Great Expectations (GX) is a more elaborate validation framework than Pandera. Where Pandera is a Python library you use inline, GX is a project: it has a CLI, a config directory, expectation suites stored as JSON, a docs renderer, and integrations with Airflow/dbt/Dagster. The shape is heavier; the payoff is that the expectations become a first-class, version-controlled, human-readable artifact that non-engineers can review.

When to pick GX over Pandera

  • You need data contracts that non-engineers (analysts, product, business stakeholders) can read and review.
  • You want the auto-generated data docs — a static site that shows expected schemas, recent run results, and drift over time.
  • You're already running Airflow/Dagster and want validation as a first-class operator/asset.
  • You want to validate data at rest — running expectations against a Snowflake table on a schedule, not just inline against a DataFrame.

When Pandera is enough

If your pipeline lives in Python, your validation stays inline, and your team is the only audience — Pandera is the lighter answer. The decision tree: Pandera by default; GX when expectations need to leave the codebase.

Code

Minimal Great Expectations validation in code·python
import great_expectations as gx

context = gx.get_context()

# Create a Pandas data source on the fly
ds = context.sources.add_or_update_pandas('orders_ds')
asset = ds.add_dataframe_asset('orders', dataframe=raw_df)

# Build a few expectations
validator = context.get_validator(
    batch_request=asset.build_batch_request(),
    expectation_suite_name='orders.suite',
)

validator.expect_column_values_to_not_be_null('order_id')
validator.expect_column_values_to_be_unique('order_id')
validator.expect_column_values_to_match_regex('order_id', r'^O\d{6}$')
validator.expect_column_values_to_be_between('amount_usd', min_value=0, max_value=1_000_000)
validator.expect_column_values_to_be_in_set('status', ['pending', 'completed', 'cancelled'])

validator.save_expectation_suite()
result = validator.validate()
if not result['success']:
    raise RuntimeError('orders failed expectations')

External links

Exercise

If you have time and motivation: install Great Expectations in a fresh project, run great_expectations init, and follow the quickstart with a small DataFrame. Generate the data docs site and open it in a browser. The point of the exercise is to feel the weight difference vs Pandera so you can pick on purpose.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.