Вступ до контролю якості даних із Great Expectations
Davina Moossazadeh
Data Scientist
expectation = gx.expectations.ExpectTableColumnCountToEqual(
value=10
)
suite = gx.ExpectationSuite(
name="my_suite"
)
# Додати Expectation до Suite
suite.add_expectation(
expectation=expectation
)
# Створити ще один Expectation Suite
another_suite = gx.ExpectationSuite(name="my_other_suite")
# Додати той самий Expectation до нового Suite
another_suite.add_expectation(expectation=expectation)
Expectations не можуть одночасно належати кільком Suites:
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`.
Скопіюйте Expectation, встановіть його .id у None і додайте до нового Suite без помилок:
expectation_copy = expectation.copy()expectation_copy.id = None
another_suite.add_expectation(
expectation=expectation_copy
)
print(
expectation_copy in another_suite.expectations
)
True
Додати
.add_expectation()
suite.add_expectation(
expectation=expectation
)
Видалити
.delete_expectation()
suite.delete_expectation(
expectation=expectation
)
Оновіть атрибут .value і збережіть зміни:
expectation = gx.expectations.ExpectTableColumnCountToEqual( value=10 )expectation.value = 11expectation.save()
Переконайтеся, що Expectation належить до Suite, інакше:
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 col_name_expectation = gx.expectations.ExpectColumnToExist(column="GHI")# Додати Expectation до Suite suite.add_expectation(expectation=col_name_expectation)# Запустити Validation Definition, пов'язане з Suite validation_results = validation_definition.run()
Збережіть зміни в Suite перед запуском Validation Definition, щоб уникнути помилок:
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.
Скористайтеся методом .save(), щоб зберегти Suite і запустити Validation Definition без помилок:
suite.save()validation_results = validation_definition.run()print(validation_results.success)
False
Копіювати Expectation:
expectation_copy = expectation.copy()
expectation_copy.id = None
Перевірити, чи є Expectation у Suite:
expectation in suite.expectations
Видалити Expectation:
suite.delete_expectation(expectation)
Оновити значення Expectation:
expectation.value = new_value
Зберегти зміни в Expectation:
expectation.save()
Зберегти зміни в Expectation Suite:
suite.save()
Вступ до контролю якості даних із Great Expectations