Einführung in Data Quality mit Great Expectations
Davina Moossazadeh
Data Scientist
expectation = gx.expectations.ExpectTableColumnCountToEqual(
value=10
)
suite = gx.ExpectationSuite(
name="my_suite"
)
# Expectation zur Suite hinzufügen
suite.add_expectation(
expectation=expectation
)
# Weitere Expectation Suite erstellen
another_suite = gx.ExpectationSuite(name="my_other_suite")
# Dieselbe Expectation zur neuen Suite hinzufügen
another_suite.add_expectation(expectation=expectation)
Expectations können nicht mehreren Suites gleichzeitig angehören:
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`.
Kopiere die Expectation, setze .id auf None, und füge sie der neuen Suite fehlerfrei hinzu:
expectation_copy = expectation.copy()expectation_copy.id = None
another_suite.add_expectation(
expectation=expectation_copy
)
print(
expectation_copy in another_suite.expectations
)
True
Hinzufügen
.add_expectation()
suite.add_expectation(
expectation=expectation
)
Löschen
.delete_expectation()
suite.delete_expectation(
expectation=expectation
)
Aktualisiere das Attribut .value und speichere:
expectation = gx.expectations.ExpectTableColumnCountToEqual( value=10 )expectation.value = 11expectation.save()
Stelle sicher, dass die Expectation zu einer Suite gehört, sonst:
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"
)
# Expectation definieren col_name_expectation = gx.expectations.ExpectColumnToExist(column="GHI")# Expectation zur Suite hinzufügen suite.add_expectation(expectation=col_name_expectation)# Validation Definition zur Suite ausführen validation_results = validation_definition.run()
Speichere die Suite vor dem Ausführen der Validation Definition, um Fehler zu vermeiden:
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.
Verwende .save(), um die Suite zu speichern und die Validation Definition fehlerfrei auszuführen:
suite.save()validation_results = validation_definition.run()print(validation_results.success)
False
Expectation kopieren:
expectation_copy = expectation.copy()
expectation_copy.id = None
Prüfen, ob Expectation in Suite ist:
expectation in suite.expectations
Expectation löschen:
suite.delete_expectation(expectation)
Expectation-Wert aktualisieren:
expectation.value = new_value
Änderungen an Expectation speichern:
expectation.save()
Änderungen an Expectation Suite speichern:
suite.save()
Einführung in Data Quality mit Great Expectations