Aktualizace sad očekávání

Úvod do kvality dat s Great Expectations

Davina Moossazadeh

Data Scientist

Přidávání očekávání

expectation = gx.expectations.ExpectTableColumnCountToEqual(
    value=10
)
suite = gx.ExpectationSuite(
    name="my_suite"
)
# Add Expectation to Suite
suite.add_expectation(
    expectation=expectation
)
Úvod do kvality dat s Great Expectations

Více sad očekávání

# 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)

Očekávání nemůže patřit do více sad najednou:

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`.
Úvod do kvality dat s Great Expectations

Kopírování očekávání

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

Zkopírujte očekávání, nastavte jeho .id na None a bez chyby ho přidejte do nové sady:

expectation_copy = expectation.copy()

expectation_copy.id = None
another_suite.add_expectation(
    expectation=expectation_copy
)
Úvod do kvality dat s Great Expectations

Kontrola očekávání

print(
    expectation_copy in another_suite.expectations
)
True
Úvod do kvality dat s Great Expectations

Odstraňování očekávání

Přidání

.add_expectation()

suite.add_expectation(
    expectation=expectation
)

Odstranění

.delete_expectation()

suite.delete_expectation(
    expectation=expectation
)
Úvod do kvality dat s Great Expectations

Úprava očekávání

Aktualizujte atribut .value a uložte změny:

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

expectation.value = 11
expectation.save()

Očekávání musí patřit do sady, jinak nastane chyba:

RuntimeError: Expectation must be added to ExpectationSuite before it can be saved.
Úvod do kvality dat s Great Expectations

Aktualizace sady očekávání

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()
Úvod do kvality dat s Great Expectations

Uložení sady očekávání

Před spuštěním definice validace uložte změny sady, jinak nastane chyba:

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.
Úvod do kvality dat s Great Expectations

Uložení sady očekávání

Použijte metodu .save() k uložení sady a bezchybnému spuštění definice validace:

suite.save()

validation_results = validation_definition.run()
print(validation_results.success)
False
Úvod do kvality dat s Great Expectations

Přehled

Kopírování očekávání:

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

Kontrola přítomnosti očekávání v sadě:

expectation in suite.expectations

Odstranění očekávání:

suite.delete_expectation(expectation)

Aktualizace hodnoty očekávání:

expectation.value = new_value

Uložení změn očekávání:

expectation.save()

Uložení změn sady očekávání:

suite.save()
Úvod do kvality dat s Great Expectations

Pojďme si procvičit!

Úvod do kvality dat s Great Expectations

Preparing Video For Download...