Skip to content

Commit 509dcc3

Browse files
authored
Merge pull request #24 from getyourguide/cleanup-unit-tests
test: consolidated aggregation any value expectations tests
2 parents 7f23a38 + 707715c commit 509dcc3

File tree

80 files changed

+14303
-10472
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+14303
-10472
lines changed

.github/workflows/main.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: CI
22

33
on:
44
push:
5-
pull_request:
65
workflow_dispatch: # Allow manual triggering
76

87
permissions:

.github/workflows/publish.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
name: Publish to PyPI
22

33
on:
4-
push:
5-
tags:
6-
- 'v*'
4+
workflow_dispatch: # Allow manual triggering
75

86
permissions:
97
contents: read

dataframe_expectations/suite.pyi

Lines changed: 139 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,116 @@
22
# Auto-generated by scripts/generate_suite_stubs.py
33
# DO NOT EDIT - Regenerate with: python scripts/generate_suite_stubs.py
44

5-
from typing import List, Union
6-
from dataframe_expectations.expectations import DataFrameLike
7-
from dataframe_expectations.result_message import DataFrameExpectationFailureMessage
5+
from functools import wraps
6+
from typing import Union, Callable, List, Optional, cast
7+
from dataframe_expectations.core.types import DataFrameLike
8+
from dataframe_expectations.registry import DataFrameExpectationRegistry
9+
from dataframe_expectations.result_message import DataFrameExpectationFailureMessage, DataFrameExpectationSuccessMessage
810

911
class DataFrameExpectationsSuiteFailure(Exception):
10-
failures: List[DataFrameExpectationFailureMessage]
11-
total_expectations: int
12-
def __init__(
13-
self,
14-
total_expectations: int,
15-
failures: List[DataFrameExpectationFailureMessage],
16-
*args,
17-
) -> None: ...
12+
"""Raised when one or more expectations in the suite fail."""
13+
def __init__(self, total_expectations: int, failures: List[DataFrameExpectationFailureMessage], *args):
14+
...
15+
def __str__(self):
16+
...
17+
18+
class DataFrameExpectationsSuiteRunner:
19+
"""
20+
Immutable runner for executing a fixed set of expectations.
21+
22+
This class is created by DataFrameExpectationsSuite.build() and contains
23+
a snapshot of expectations that won't change during execution.
24+
"""
25+
def __init__(self, expectations: List):
26+
"""
27+
28+
Initialize the runner with a list of expectations.
29+
30+
:param expectations: List of expectation instances to run.
31+
32+
"""
33+
...
34+
@property
35+
def expectation_count(self) -> int:
36+
"""
37+
Return the number of expectations in this runner.
38+
"""
39+
...
40+
def list_expectations(self) -> List[str]:
41+
"""
42+
43+
Return a list of expectation descriptions in this runner.
44+
45+
:return: List of expectation descriptions as strings in the format:
46+
"ExpectationName (description)"
47+
48+
"""
49+
...
50+
def run(self, data_frame: DataFrameLike) -> None:
51+
"""
52+
53+
Run all expectations on the provided DataFrame with PySpark caching optimization.
54+
55+
:param data_frame: The DataFrame to validate.
56+
57+
"""
58+
...
59+
def validate(self, func: Optional[Callable]=None, *, allow_none: bool=False) -> Callable:
60+
"""
61+
62+
Decorator to validate the DataFrame returned by a function.
63+
64+
This decorator runs the expectations suite on the DataFrame returned
65+
by the decorated function. If validation fails, it raises
66+
DataFrameExpectationsSuiteFailure.
67+
68+
Example:
69+
runner = suite.build()
70+
71+
@runner.validate
72+
def load_data():
73+
return pd.read_csv("data.csv")
74+
75+
df = load_data() # Automatically validated
76+
77+
# Allow None returns
78+
@runner.validate(allow_none=True)
79+
def maybe_load_data():
80+
if condition:
81+
return pd.read_csv("data.csv")
82+
return None
83+
84+
:param func: Function that returns a DataFrame.
85+
:param allow_none: If True, allows the function to return None without validation.
86+
If False (default), None will raise a ValueError.
87+
:return: Wrapped function that validates the returned DataFrame.
88+
89+
"""
90+
...
1891

1992
class DataFrameExpectationsSuite:
20-
def __init__(self) -> None: ...
93+
"""
94+
A builder for creating expectation suites for validating DataFrames.
95+
96+
Use this class to add expectations, then call build() to create an
97+
immutable runner that can execute the expectations on DataFrames.
98+
99+
Example:
100+
suite = DataFrameExpectationsSuite()
101+
suite.expect_value_greater_than(column_name="age", value=18)
102+
suite.expect_value_less_than(column_name="salary", value=100000)
103+
104+
runner = suite.build()
105+
runner.run(df1)
106+
runner.run(df2) # Same expectations, different DataFrame
107+
"""
108+
def __init__(self):
109+
"""
110+
111+
Initialize the expectation suite builder.
112+
113+
"""
114+
...
21115

22116
def expect_column_max_between(
23117
self,
@@ -616,4 +710,36 @@ class DataFrameExpectationsSuite:
616710
"""
617711
...
618712

619-
def run(self, data_frame: DataFrameLike) -> None: ...
713+
def __getattr__(self, name: str):
714+
"""
715+
716+
Dynamically create expectation methods.
717+
718+
This is called when Python can't find an attribute through normal lookup.
719+
We use it to generate expect_* methods on-the-fly from the registry.
720+
721+
"""
722+
...
723+
def _create_expectation_method(self, suite_method_name: str):
724+
"""
725+
726+
Create a dynamic expectation method.
727+
728+
Returns a closure that captures the suite_method_name and self.
729+
730+
"""
731+
...
732+
def build(self) -> DataFrameExpectationsSuiteRunner:
733+
"""
734+
735+
Build an immutable runner from the current expectations.
736+
737+
The runner contains a snapshot of expectations at the time of building.
738+
You can continue to add more expectations to this suite and build
739+
new runners without affecting previously built runners.
740+
741+
:return: An immutable DataFrameExpectationsSuiteRunner instance.
742+
:raises ValueError: If no expectations have been added.
743+
744+
"""
745+
...

0 commit comments

Comments
 (0)