Обновление наборов ожиданий

Введение в качество данных с Great Expectations

Davina Moossazadeh

Data Scientist

Добавление ожиданий

expectation = gx.expectations.ExpectTableColumnCountToEqual(
    value=10
)
suite = gx.ExpectationSuite(
    name="my_suite"
)
# Add Expectation to Suite
suite.add_expectation(
    expectation=expectation
)
Введение в качество данных с Great Expectations

Несколько наборов ожиданий

# Create another Expectation Suite
another_suite = gx.ExpectationSuite(name="my_other_suite")
# Add the same Expectation to the new Suite
another_suite.add_expectation(expectation=expectation)

Ожидание не может принадлежать нескольким наборам одновременно:

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

Копирование ожиданий

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`.

Скопируйте ожидание, установите .id в None и добавьте его в новый набор без ошибок:

expectation_copy = expectation.copy()

expectation_copy.id = None
another_suite.add_expectation(
    expectation=expectation_copy
)
Введение в качество данных с Great Expectations

Проверка ожиданий

print(
    expectation_copy in another_suite.expectations
)
True
Введение в качество данных с Great Expectations

Удаление ожиданий

Добавить

.add_expectation()

suite.add_expectation(
    expectation=expectation
)

Удалить

.delete_expectation()

suite.delete_expectation(
    expectation=expectation
)
Введение в качество данных с Great Expectations

Изменение ожиданий

Обновите атрибут .value и сохраните изменения:

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

expectation.value = 11
expectation.save()

Ожидание должно принадлежать набору, иначе:

RuntimeError: Expectation must be added to ExpectationSuite before it can be saved.
Введение в качество данных с Great Expectations

Обновление набора ожиданий

suite = gx.ExpectationSuite(name="my_suite") 
validation_definition = gx.ValidationDefinition(
    data=batch_definition, suite=suite, name="my_validation_definition"
)
# Define Expectation
col_name_expectation = gx.expectations.ExpectColumnToExist(column="GHI")

# Add Expectation to Suite suite.add_expectation(expectation=col_name_expectation)
# Run Validation Definition associated with the Suite validation_results = validation_definition.run()
Введение в качество данных с Great Expectations

Сохранение набора ожиданий

Сохраните изменения в наборе перед запуском определения валидации, чтобы избежать ошибок:

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

Сохранение набора ожиданий

Используйте метод .save(), чтобы сохранить набор и запустить определение валидации без ошибок:

suite.save()

validation_results = validation_definition.run()
print(validation_results.success)
False
Введение в качество данных с Great Expectations

Шпаргалка

Скопировать ожидание:

expectation_copy = expectation.copy()
expectation_copy.id = None

Проверить наличие ожидания в наборе:

expectation in suite.expectations

Удалить ожидание:

suite.delete_expectation(expectation)

Обновить значение ожидания:

expectation.value = new_value

Сохранить изменения ожидания:

expectation.save()

Сохранить изменения набора ожиданий:

suite.save()
Введение в качество данных с Great Expectations

Давайте потренируемся!

Введение в качество данных с Great Expectations

Preparing Video For Download...