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 suite d'Expectations
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, réglez son .id à None, puis 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 définition de validation associée à la suite validation_results = validation_definition.run()
Enregistrez la suite avant d'exécuter la définition de validation 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, puis exécutez la définition de validation 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 de l'Expectation :
expectation.value = new_value
Enregistrer les changements de l'Expectation :
expectation.save()
Enregistrer les changements de la suite d'Expectations :
suite.save()
Introduction à la qualité des données avec Great Expectations