Expectation Suites bijwerken

Kennismaking met Datakwaliteit met Great Expectations

Davina Moossazadeh

Data Scientist

Expectations toevoegen

expectation = gx.expectations.ExpectTableColumnCountToEqual(
    value=10
)
suite = gx.ExpectationSuite(
    name="my_suite"
)
# Voeg Expectation toe aan Suite
suite.add_expectation(
    expectation=expectation
)
Kennismaking met Datakwaliteit met Great Expectations

Meerdere Expectation Suites

# Maak nog een Expectation Suite
another_suite = gx.ExpectationSuite(name="my_other_suite")
# Voeg dezelfde Expectation toe aan de nieuwe Suite
another_suite.add_expectation(expectation=expectation)

Expectations kunnen niet tegelijk in meerdere Suites zitten:

RuntimeError: Cannot add Expectation because it already belongs to an 
ExpectationSuite. If you want to update an existing Expectation, please call 
Expectation.save(). If you are copying this Expectation to a new ExpectationSuite, 
please copy it first (the core expectations and some others support 
copy(expectation)) and set `Expectation.id = None`.
Kennismaking met Datakwaliteit met Great Expectations

Expectations kopiëren

If you are copying this Expectation to a new ExpectationSuite, please copy it first 
(the core expectations and some others support copy(expectation)) and set 
`Expectation.id = None`.

Kopieer de Expectation, zet .id op None, en voeg ’m zonder errors toe aan de nieuwe Suite:

expectation_copy = expectation.copy()

expectation_copy.id = None
another_suite.add_expectation(
    expectation=expectation_copy
)
Kennismaking met Datakwaliteit met Great Expectations

Expectations controleren

print(
    expectation_copy in another_suite.expectations
)
True
Kennismaking met Datakwaliteit met Great Expectations

Expectations verwijderen

Toevoegen

.add_expectation()

suite.add_expectation(
    expectation=expectation
)

Verwijderen

.delete_expectation()

suite.delete_expectation(
    expectation=expectation
)
Kennismaking met Datakwaliteit met Great Expectations

Expectations aanpassen

Werk de .value-attribuut bij en sla op:

expectation = gx.expectations.ExpectTableColumnCountToEqual(
    value=10
)

expectation.value = 11
expectation.save()

Zorg dat de Expectation in een Suite zit, anders:

RuntimeError: Expectation must be added to ExpectationSuite before it can be saved.
Kennismaking met Datakwaliteit met Great Expectations

Een Expectation Suite updaten

suite = gx.ExpectationSuite(name="my_suite") 
validation_definition = gx.ValidationDefinition(
    data=batch_definition, suite=suite, name="my_validation_definition"
)
# Defineer Expectation
col_name_expectation = gx.expectations.ExpectColumnToExist(column="GHI")

# Voeg Expectation toe aan Suite suite.add_expectation(expectation=col_name_expectation)
# Run Validation Definition gekoppeld aan de Suite validation_results = validation_definition.run()
Kennismaking met Datakwaliteit met Great Expectations

Een Expectation Suite opslaan

Sla de Suite op vóór je de Validation Definition runt om errors te voorkomen:

validation_results = validation_definition.run()
ResourceFreshnessAggregateError: ExpectationSuite 'my_suite' has changed since it 
has last been saved. Please update with `<SUITE_OBJECT>.save()`, then try your 
action again.
Kennismaking met Datakwaliteit met Great Expectations

Een Expectation Suite opslaan

Gebruik .save() om de Suite op te slaan en de Validation Definition zonder fouten te runnen:

suite.save()

validation_results = validation_definition.run()
print(validation_results.success)
False
Kennismaking met Datakwaliteit met Great Expectations

Cheat sheet

Expectation kopiëren:

expectation_copy = expectation.copy()
expectation_copy.id = None

Check of de Expectation in de Suite zit:

expectation in suite.expectations

Expectation verwijderen:

suite.delete_expectation(expectation)

Expectation-waarde bijwerken:

expectation.value = new_value

Wijzigingen in Expectation opslaan:

expectation.save()

Wijzigingen in Expectation Suite opslaan:

suite.save()
Kennismaking met Datakwaliteit met Great Expectations

Laten we oefenen!

Kennismaking met Datakwaliteit met Great Expectations

Preparing Video For Download...