Kennismaking met Datakwaliteit met Great Expectations
Davina Moossazadeh
Data Scientist
expectation = gx.expectations.ExpectTableColumnCountToEqual(
value=10
)
suite = gx.ExpectationSuite(
name="my_suite"
)
# Voeg Expectation toe aan Suite
suite.add_expectation(
expectation=expectation
)
# 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`.
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
)
print(
expectation_copy in another_suite.expectations
)
True
Toevoegen
.add_expectation()
suite.add_expectation(
expectation=expectation
)
Verwijderen
.delete_expectation()
suite.delete_expectation(
expectation=expectation
)
Werk de .value-attribuut bij en sla op:
expectation = gx.expectations.ExpectTableColumnCountToEqual( value=10 )expectation.value = 11expectation.save()
Zorg dat de Expectation in een Suite zit, anders:
RuntimeError: Expectation must be added to ExpectationSuite before it can be saved.
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()
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.
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
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