Introduction to Data Quality with Great Expectations
Davina Moossazadeh
Data Scientist
Conditional Expectations - Expectations for a subset of the data
Why? Because some variables are dependent on the values of other variables
For example:
star_rating
must be 0
for all rows with a value of 0
for review_count
Dataset Expectations can be converted into Conditional Expectations with two additional arguments:
row_condition
condition_parser
row_condition
When implementing Conditional Expectations with pandas, this argument must be set to "pandas"
expectation = gx.Expect...(
**kwargs,
condition_parser="pandas",
row_condition=...
)
df["foo"] == 'Two Two'
df["foo"].notNull()
df["foo"] <= datetime.date(2023, 3, 13)
(df["foo"] < 5) & (df["foo"] >= 3.14)
df["foo"].str.startswith("bar")
row_condition
'foo == "Two Two"'
'foo.notNull()'
'foo <= datetime.date(2023, 3, 13)'
'(foo > 5) & (foo <= 3.14)'
'foo > 5 and foo <= 3.14'
'foo.str.startswith("bar")'
Don't use single quotes inside
row_condition="foo=='Two Two'"
row_condition='foo=="Two Two"'
Don't use line breaks inside
row_condition="""
foo=="Two Two"
"""
row_condition='foo=="Two Two"'
expectation = gx.expectations.\
ExpectColumnValuesToBeBetween(
column="price_usd",
max_value=10,
)
validation_results = batch.validate(
expect=expectation
)
print(validation_results.success)
False
expectation = gx.expectations.\
ExpectColumnValuesToBeBetween(
column="price_usd",
max_value=10,
condition_parser='pandas',
row_condition='mark_price_usd < 10',
)
validation_results = batch.validate(
expect=expectation
)
print(validation_results.success)
True
Introduction to Data Quality with Great Expectations