Оновлення наборів Expectation Suites

Вступ до контролю якості даних із Great Expectations

Davina Moossazadeh

Data Scientist

Додавання Expectations

expectation = gx.expectations.ExpectTableColumnCountToEqual(
    value=10
)
suite = gx.ExpectationSuite(
    name="my_suite"
)
# Додати Expectation до Suite
suite.add_expectation(
    expectation=expectation
)
Вступ до контролю якості даних із Great Expectations

Кілька Expectation Suites

# Створити ще один 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`.
Вступ до контролю якості даних із Great Expectations

Копіювання Expectations

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
)
Вступ до контролю якості даних із Great Expectations

Перевірка Expectations

print(
    expectation_copy in another_suite.expectations
)
True
Вступ до контролю якості даних із Great Expectations

Видалення Expectations

Додати

.add_expectation()

suite.add_expectation(
    expectation=expectation
)

Видалити

.delete_expectation()

suite.delete_expectation(
    expectation=expectation
)
Вступ до контролю якості даних із Great Expectations

Коригування Expectations

Оновіть атрибут .value і збережіть зміни:

expectation = gx.expectations.ExpectTableColumnCountToEqual(
    value=10
)

expectation.value = 11
expectation.save()

Переконайтеся, що Expectation належить до Suite, інакше:

RuntimeError: Expectation must be added to ExpectationSuite before it can be saved.
Вступ до контролю якості даних із Great Expectations

Оновлення Expectation Suite

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()
Вступ до контролю якості даних із Great Expectations

Збереження Expectation Suite

Збережіть зміни в 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.
Вступ до контролю якості даних із Great Expectations

Збереження Expectation Suite

Скористайтеся методом .save(), щоб зберегти Suite і запустити Validation Definition без помилок:

suite.save()

validation_results = validation_definition.run()
print(validation_results.success)
False
Вступ до контролю якості даних із Great Expectations

Шпаргалка

Копіювати 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

Давайте потренуємось!

Вступ до контролю якості даних із Great Expectations

Preparing Video For Download...