Skip to main content

A tiny, code-first data quality expectations library for pandas DataFrames.

Project description

mini_expectations

A tiny, code-first data quality library for pandas DataFrames.

It aims to provide a small, readable alternative to Great Expectations with:

  • Pandas-only focus
  • Code-first API (no YAML, no configs)
  • Fail-fast behavior via a single ExpectationFailed exception
  • Simple chaining from DataFrame → column → expectation

Installation

Install from your local checkout:

pip install -e .

You will also need pandas in your environment.

Basic usage

import pandas as pd
from mini_expectations import expect, ExpectationFailed

df = pd.DataFrame(
    {
        "id": [1, 2, 3],
        "amount": [10.0, 20.5, 0.1],
        "email": ["a@example.com", "b@example.com", "c@example.com"],
        "status": ["active", "active", "inactive"],
    }
)

# DataFrame-level checks
expect(df).to_have_columns(["id", "amount", "email"])
expect(df).to_have_no_nulls()
expect(df).to_have_unique_column("id")

# Column-level checks
expect(df).column("amount").to_be_positive()
expect(df).column("amount").to_be_between(0, 100)
expect(df).column("email").to_match_regex(r".+@.+")
expect(df).column("status").to_be_in_set(["active", "inactive"])
expect(df).column("id").to_have_no_nulls()

# Row count checks
expect(df).row_count().to_be_between(1, 1_000_000)

All expectations return self so you can chain them:

expect(df) \
    .to_have_columns(["id", "amount", "email"]) \
    .to_have_no_nulls() \
    .to_have_unique_column("id")

When an expectation fails, ExpectationFailed is raised with a human-readable message that describes what was expected and what was actually observed.

API overview

All entry points live under a single function:

  • expect(df) → returns a DataFrameExpectations object.

DataFrame-level expectations:

  • to_have_columns(columns): assert that all listed columns exist.
  • to_have_no_nulls(subset=None): assert that there are no nulls in the DataFrame (or in a subset of columns).
  • to_have_unique_column(column): assert that a column exists, has no nulls, and contains only unique values.
  • row_count(): returns a RowCountExpectation wrapper for the number of rows.

Column navigation and expectations:

  • column(name): navigate to a ColumnExpectations object.
  • to_be_positive(strictly=True): assert that numeric values are > 0 (or >= 0 when strictly=False).
  • to_match_regex(pattern): assert that all non-null stringified values match a regex pattern.
  • to_be_unique(): assert that non-null values are unique.
  • to_be_between(min_value, max_value, inclusive=True): assert that non-null numeric values lie in a given range.
  • to_be_in_set(allowed_values): assert that non-null values come from a fixed set.
  • to_have_no_nulls(): assert that a column has no null values.

Row count expectations:

  • RowCountExpectation.to_be_between(min_value, max_value): assert that the number of rows lies between two bounds (inclusive).

Error handling

All failed expectations raise:

  • ExpectationFailed: a subclass of AssertionError with clear, descriptive messages.

You can choose to let expectations fail fast, or catch the exception to aggregate or log errors:

try:
    expect(df).column("amount").to_be_positive()
except ExpectationFailed as exc:
    print("Data quality issue:", exc)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mini_expectations-0.1.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mini_expectations-0.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file mini_expectations-0.1.0.tar.gz.

File metadata

  • Download URL: mini_expectations-0.1.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for mini_expectations-0.1.0.tar.gz
Algorithm Hash digest
SHA256 88b075fab714234bd043c913d54d879ab07c3bd223e88159dce69d91922faa94
MD5 ec8e132f970d9a2594b97b7ebc37e312
BLAKE2b-256 000050575febe331f532e8401a0db79016e0b3346001facdedd748d83eef7b7a

See more details on using hashes here.

File details

Details for the file mini_expectations-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mini_expectations-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 76c4358dc5220cb88b20928193b41c4aaaee4d7400a88c5e154871a11120121e
MD5 d838041b5a7544836ccc86d47425f14c
BLAKE2b-256 8c01c94bd0adb5bf5b2abdaed4b0c7c5699be7754f9955a668903415fc92ff13

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page