Skip to content

Commit

Permalink
Merge pull request #11 from joocer/1.4.0
Browse files Browse the repository at this point in the history
1.4.0
  • Loading branch information
joocer committed Aug 12, 2023
2 parents 0726dd5 + 3d3ca92 commit 96ae19c
Show file tree
Hide file tree
Showing 24 changed files with 468 additions and 152 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Data Expectations is a Python library which takes a delarative approach to asser

Expectations can be used alongside, or in place of a schema validator, however Expectations is intended to perform validation of the data in a dataset, not just the structure of a table. Records should be a Python dictionary (or dictionary-like object) and can be processed one-by-one, or against an entire list of dictionaries.

[Data Expectations](https://github.com/joocer/data_expectations) was inspired by the great [Great Expectations](https://github.com/great-expectations/great_expectations) library, but I wanted something which was easier to quickly set up and run. Data Expectations can do less, but it does it with a fraction of the effort and has zero dependencies. Data Expectations was written to run as a step in data processing pipelines, testing the data before it is committed to the warehouse.
[Data Expectations](https://github.com/joocer/data_expectations) was inspired by the great [Great Expectations](https://github.com/great-expectations/great_expectations) library, but we wanted something lighter and easier to quickly set up and run. Data Expectations can do less, but it does it with a fraction of the effort and has zero dependencies. Data Expectations was written to run as a step in data processing pipelines, testing the data before it is committed to the warehouse.

## Provided Expectations

Expand Down
3 changes: 2 additions & 1 deletion data_expectations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .internals import Expectations
from .internals.expectations import Expectations

from .internals.evaluate import evaluate_list
from .internals.evaluate import evaluate_record
3 changes: 1 addition & 2 deletions data_expectations/internals/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from .evaluate import evaluate_record
from .expectations import Expectations

31 changes: 22 additions & 9 deletions data_expectations/internals/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,25 @@

import typing

from data_expectations import Expectations
from data_expectations.errors import ExpectationNotMetError
from data_expectations.errors import ExpectationNotUnderstoodError
from data_expectations.internals.expectations import all_expectations

ALL_EXPECTATIONS = all_expectations()
ALL_EXPECTATIONS = Expectations.all_expectations()


def evaluate_record(expectations, record: dict, suppress_errors: bool = False):
"""
Test 'record' against a defined set of 'expectations'.
Test a single record against a defined set of expectations.
Args:
expectations: The Expectations instance.
record: The dictionary record to be tested.
all_expectations: The dictionary of all available expectations.
suppress_errors: Whether to suppress expectation errors and return False instead.
Returns:
True if all expectations are met, False otherwise.
"""
for expectation_definition in expectations.set_of_expectations:
# get the name of the expectation
Expand All @@ -40,10 +49,14 @@ def evaluate_record(expectations, record: dict, suppress_errors: bool = False):

def evaluate_list(expectations, dictset: typing.Iterable[dict], suppress_errors: bool = False):
"""
Execute the expectation test against an iterable of dictionaries
Evaluate a set of records against a defined set of Expectations.
Args:
expectations: The Expectations instance.
dictset: The iterable set of dictionary records to be tested.
suppress_errors: Whether to suppress expectation errors and return False for the entire set.
Returns:
True if all records meet all Expectations, False otherwise.
"""
for record in dictset:
result = evaluate_record(expectations, record, suppress_errors)
if not result:
return False
return True
return all(evaluate_record(expectations, record, suppress_errors) for record in dictset)
Loading

0 comments on commit 96ae19c

Please sign in to comment.