Skip to content
Merged
1 change: 0 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: CI

on:
push:
pull_request:
workflow_dispatch: # Allow manual triggering

permissions:
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: Publish to PyPI

on:
push:
tags:
- 'v*'
workflow_dispatch: # Allow manual triggering

permissions:
contents: read
Expand Down
152 changes: 139 additions & 13 deletions dataframe_expectations/suite.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,116 @@
# Auto-generated by scripts/generate_suite_stubs.py
# DO NOT EDIT - Regenerate with: python scripts/generate_suite_stubs.py

from typing import List, Union
from dataframe_expectations.expectations import DataFrameLike
from dataframe_expectations.result_message import DataFrameExpectationFailureMessage
from functools import wraps
from typing import Union, Callable, List, Optional, cast
from dataframe_expectations.core.types import DataFrameLike
from dataframe_expectations.registry import DataFrameExpectationRegistry
from dataframe_expectations.result_message import DataFrameExpectationFailureMessage, DataFrameExpectationSuccessMessage

class DataFrameExpectationsSuiteFailure(Exception):
failures: List[DataFrameExpectationFailureMessage]
total_expectations: int
def __init__(
self,
total_expectations: int,
failures: List[DataFrameExpectationFailureMessage],
*args,
) -> None: ...
"""Raised when one or more expectations in the suite fail."""
def __init__(self, total_expectations: int, failures: List[DataFrameExpectationFailureMessage], *args):
...
def __str__(self):
...

class DataFrameExpectationsSuiteRunner:
"""
Immutable runner for executing a fixed set of expectations.

This class is created by DataFrameExpectationsSuite.build() and contains
a snapshot of expectations that won't change during execution.
"""
def __init__(self, expectations: List):
"""

Initialize the runner with a list of expectations.

:param expectations: List of expectation instances to run.

"""
...
@property
def expectation_count(self) -> int:
"""
Return the number of expectations in this runner.
"""
...
def list_expectations(self) -> List[str]:
"""

Return a list of expectation descriptions in this runner.

:return: List of expectation descriptions as strings in the format:
"ExpectationName (description)"

"""
...
def run(self, data_frame: DataFrameLike) -> None:
"""

Run all expectations on the provided DataFrame with PySpark caching optimization.

:param data_frame: The DataFrame to validate.

"""
...
def validate(self, func: Optional[Callable]=None, *, allow_none: bool=False) -> Callable:
"""

Decorator to validate the DataFrame returned by a function.

This decorator runs the expectations suite on the DataFrame returned
by the decorated function. If validation fails, it raises
DataFrameExpectationsSuiteFailure.

Example:
runner = suite.build()

@runner.validate
def load_data():
return pd.read_csv("data.csv")

df = load_data() # Automatically validated

# Allow None returns
@runner.validate(allow_none=True)
def maybe_load_data():
if condition:
return pd.read_csv("data.csv")
return None

:param func: Function that returns a DataFrame.
:param allow_none: If True, allows the function to return None without validation.
If False (default), None will raise a ValueError.
:return: Wrapped function that validates the returned DataFrame.

"""
...

class DataFrameExpectationsSuite:
def __init__(self) -> None: ...
"""
A builder for creating expectation suites for validating DataFrames.

Use this class to add expectations, then call build() to create an
immutable runner that can execute the expectations on DataFrames.

Example:
suite = DataFrameExpectationsSuite()
suite.expect_value_greater_than(column_name="age", value=18)
suite.expect_value_less_than(column_name="salary", value=100000)

runner = suite.build()
runner.run(df1)
runner.run(df2) # Same expectations, different DataFrame
"""
def __init__(self):
"""

Initialize the expectation suite builder.

"""
...

def expect_column_max_between(
self,
Expand Down Expand Up @@ -616,4 +710,36 @@ class DataFrameExpectationsSuite:
"""
...

def run(self, data_frame: DataFrameLike) -> None: ...
def __getattr__(self, name: str):
"""

Dynamically create expectation methods.

This is called when Python can't find an attribute through normal lookup.
We use it to generate expect_* methods on-the-fly from the registry.

"""
...
def _create_expectation_method(self, suite_method_name: str):
"""

Create a dynamic expectation method.

Returns a closure that captures the suite_method_name and self.

"""
...
def build(self) -> DataFrameExpectationsSuiteRunner:
"""

Build an immutable runner from the current expectations.

The runner contains a snapshot of expectations at the time of building.
You can continue to add more expectations to this suite and build
new runners without affecting previously built runners.

:return: An immutable DataFrameExpectationsSuiteRunner instance.
:raises ValueError: If no expectations have been added.

"""
...
Loading
Loading