Atualizar Expectation Suites

Introdução à Qualidade de Dados com Great Expectations

Davina Moossazadeh

Data Scientist

Adicionando Expectations

expectation = gx.expectations.ExpectTableColumnCountToEqual(
    value=10
)
suite = gx.ExpectationSuite(
    name="my_suite"
)
# Adicionar Expectation à Suite
suite.add_expectation(
    expectation=expectation
)
Introdução à Qualidade de Dados com Great Expectations

Múltiplas Expectation Suites

# Criar outra Expectation Suite
another_suite = gx.ExpectationSuite(name="my_other_suite")
# Adicionar a mesma Expectation à nova Suite
another_suite.add_expectation(expectation=expectation)

Expectations não podem pertencer a várias Suites ao mesmo tempo:

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`.
Introdução à Qualidade de Dados com Great Expectations

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

Copie a Expectation, defina .id como None e adicione-a à nova Suite sem erros:

expectation_copy = expectation.copy()

expectation_copy.id = None
another_suite.add_expectation(
    expectation=expectation_copy
)
Introdução à Qualidade de Dados com Great Expectations

Verificando Expectations

print(
    expectation_copy in another_suite.expectations
)
True
Introdução à Qualidade de Dados com Great Expectations

Excluindo Expectations

Adicionar

.add_expectation()

suite.add_expectation(
    expectation=expectation
)

Excluir

.delete_expectation()

suite.delete_expectation(
    expectation=expectation
)
Introdução à Qualidade de Dados com Great Expectations

Ajustando Expectations

Atualize o atributo .value e salve as mudanças:

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

expectation.value = 11
expectation.save()

Garanta que a Expectation pertença a uma Suite, senão:

RuntimeError: Expectation must be added to ExpectationSuite before it can be saved.
Introdução à Qualidade de Dados com Great Expectations

Atualizando uma Expectation Suite

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

# Adicionar Expectation à Suite suite.add_expectation(expectation=col_name_expectation)
# Executar a Validation Definition associada à Suite validation_results = validation_definition.run()
Introdução à Qualidade de Dados com Great Expectations

Salvando uma Expectation Suite

Salve as mudanças na Suite antes de rodar a Validation Definition para evitar erros:

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.
Introdução à Qualidade de Dados com Great Expectations

Salvando uma Expectation Suite

Use o método .save() para salvar a Suite e rodar a Validation Definition sem erros:

suite.save()

validation_results = validation_definition.run()
print(validation_results.success)
False
Introdução à Qualidade de Dados com Great Expectations

Guia rápido

Copiar Expectation:

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

Conferir se a Expectation está na Suite:

expectation in suite.expectations

Excluir Expectation:

suite.delete_expectation(expectation)

Atualizar o valor da Expectation:

expectation.value = new_value

Salvar mudanças na Expectation:

expectation.save()

Salvar mudanças na Expectation Suite:

suite.save()
Introdução à Qualidade de Dados com Great Expectations

Vamos praticar!

Introdução à Qualidade de Dados com Great Expectations

Preparing Video For Download...