Skip to content

Conversation

@ryanseq-gyg
Copy link
Contributor

@ryanseq-gyg ryanseq-gyg commented Nov 8, 2025

Description

This PR refactors the expectation registration system to address the growing size of the DataFrameExpectationsSuite class (previously 800+ lines of boilerplate). The new architecture replaces manual method definitions with dynamic generation from a central registry, while maintaining full IDE type-ahead support through auto-generated stub files.

Key Changes:

  1. Dynamic Method Generation
  • Replaced 800+ lines of repetitive expect_* methods with a getattr-based approach
  • Methods are now generated dynamically from registry metadata
  • User-facing API remains unchanged—backward compatible
  1. IDE Support via Type Stubs
  • Auto-generated expectations_suite.pyi provides full IntelliSense/autocomplete support
  • Generated by generate_suite_stubs.py from registry metadata
  • Integrated with pre-commit hooks to ensure stubs stay in sync
  1. Improved Tooling
  • Updated documentation system to read from registry instead of runtime inspection
  • Sanity checks validate registry, stubs, tests, and suite methods
  • All tooling uses registry as single source of truth
  1. Updated register_expectation decorator
    All @register_expectation decorators now require complete metadata:
@register_expectation(
    expectation_name="ExpectationValueGreaterThan",
    category=ExpectationCategory.COLUMN,
    subcategory=ExpectationSubcategory.NUMERICAL,
    pydoc="Check if values in a column are greater than a specified value",
    params=["column_name", "value"],
    params_doc={
        "column_name": "The name of the column to check",
        "value": "The value to compare against"
    },
    param_types={"column_name": str, "value": Union[int, float]}
)

Checklist

  • Tests have been added in the prescribed format
  • Commit messages follow Conventional Commits format
  • Pre-commit hooks pass locally

@ryanseq-gyg ryanseq-gyg marked this pull request as ready for review November 8, 2025 16:54
@ryanseq-gyg ryanseq-gyg requested a review from a team as a code owner November 8, 2025 16:54
@ryanseq-gyg ryanseq-gyg requested a review from Copilot November 8, 2025 16:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the expectation registration system to use Pydantic for metadata validation and introduces automatic stub file generation for IDE autocomplete support. The main changes include:

  • Addition of Pydantic dependency for metadata validation
  • Dynamic method generation in DataFrameExpectationsSuite using __getattr__
  • Automatic .pyi stub file generation for IDE support
  • Enhanced expectation registry with metadata tracking using enums and Pydantic models

Reviewed Changes

Copilot reviewed 19 out of 20 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
uv.lock Adds pydantic 2.12.4 and dependencies (annotated-types, pydantic-core, typing-inspection)
pyproject.toml Adds pydantic>=2.12.4 dependency
dataframe_expectations/expectations/expectation_registry.py Adds ExpectationMetadata model, enums for categories, and metadata tracking
dataframe_expectations/expectations_suite.py Refactors to use dynamic method generation via getattr
scripts/generate_suite_stubs.py New script to generate .pyi stub files from registry metadata
dataframe_expectations/expectations_suite.pyi Auto-generated type stubs for IDE autocomplete
scripts/sanity_checks.py Updates to validate stub file and use registry for suite methods
tests/expectations_helper_classes/test_expectation_registry.py Updates test registrations with new required metadata parameters
docs/source/adding_expectations.rst Updated documentation for new registration API
.pre-commit-config.yaml Adds check for stub file freshness

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ryanseq-gyg ryanseq-gyg merged commit e0b8240 into main Nov 8, 2025
8 checks passed
@ryanseq-gyg ryanseq-gyg deleted the refactor-expectation-registration branch November 8, 2025 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants