Introdução à Qualidade de Dados com Great Expectations
Davina Moossazadeh
Data Scientist
expectation = gx.expectations.ExpectTableColumnCountToEqual(
value=10
)
suite = gx.ExpectationSuite(
name="my_suite"
)
# Adicionar Expectation à Suite
suite.add_expectation(
expectation=expectation
)
# 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`.
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
)
print(
expectation_copy in another_suite.expectations
)
True
Adicionar
.add_expectation()
suite.add_expectation(
expectation=expectation
)
Excluir
.delete_expectation()
suite.delete_expectation(
expectation=expectation
)
Atualize o atributo .value e salve as mudanças:
expectation = gx.expectations.ExpectTableColumnCountToEqual( value=10 )expectation.value = 11expectation.save()
Garanta que a Expectation pertença a uma Suite, senão:
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"
)
# 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()
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.
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
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