Introduction à la qualité des données avec Great Expectations
Davina Moossazadeh
Data Scientist
expectation = gx.expectations.ExpectTableColumnCountToEqual(
value=10
)
suite = gx.ExpectationSuite(
name="my_suite"
)
# Ajouter l’Expectation à la Suite
suite.add_expectation(
expectation=expectation
)
# Créer une autre Expectation Suite
another_suite = gx.ExpectationSuite(name="my_other_suite")
# Ajouter la même Expectation à la nouvelle Suite
another_suite.add_expectation(expectation=expectation)
Les Expectations ne peuvent pas appartenir à plusieurs Suites à la fois :
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`.
Copiez l’Expectation, définissez son .id à None, et ajoutez-la à la nouvelle Suite sans erreur :
expectation_copy = expectation.copy()expectation_copy.id = None
another_suite.add_expectation(
expectation=expectation_copy
)
print(
expectation_copy in another_suite.expectations
)
True
Ajouter
.add_expectation()
suite.add_expectation(
expectation=expectation
)
Supprimer
.delete_expectation()
suite.delete_expectation(
expectation=expectation
)
Mettez à jour l’attribut .value et enregistrez :
expectation = gx.expectations.ExpectTableColumnCountToEqual( value=10 )expectation.value = 11expectation.save()
Assurez-vous que l’Expectation appartient à une Suite, sinon :
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"
)
# Définir une Expectation col_name_expectation = gx.expectations.ExpectColumnToExist(column="GHI")# Ajouter l’Expectation à la Suite suite.add_expectation(expectation=col_name_expectation)# Exécuter la Validation Definition associée à la Suite validation_results = validation_definition.run()
Enregistrez la Suite avant d’exécuter la Validation Definition pour éviter les erreurs :
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.
Utilisez la méthode .save() pour enregistrer la Suite et exécuter la Validation Definition sans erreur :
suite.save()validation_results = validation_definition.run()print(validation_results.success)
False
Copier une Expectation :
expectation_copy = expectation.copy()
expectation_copy.id = None
Vérifier si l’Expectation est dans la Suite :
expectation in suite.expectations
Supprimer une Expectation :
suite.delete_expectation(expectation)
Mettre à jour la valeur d’une Expectation :
expectation.value = new_value
Enregistrer les modifications de l’Expectation :
expectation.save()
Enregistrer les modifications de l’Expectation Suite :
suite.save()
Introduction à la qualité des données avec Great Expectations