Uppdatera Expectation Suites

Introduktion till datakvalitet med Great Expectations

Davina Moossazadeh

Data Scientist

Lägga till Expectations

expectation = gx.expectations.ExpectTableColumnCountToEqual(
    value=10
)
suite = gx.ExpectationSuite(
    name="my_suite"
)
# Add Expectation to Suite
suite.add_expectation(
    expectation=expectation
)
Introduktion till datakvalitet med Great Expectations

Flera Expectation Suites

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

En Expectation kan inte tillhöra flera Suites samtidigt:

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`.
Introduktion till datakvalitet med Great Expectations

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

Kopiera Expectation, sätt dess .id till None och lägg till den i den nya Suite:n utan fel:

expectation_copy = expectation.copy()

expectation_copy.id = None
another_suite.add_expectation(
    expectation=expectation_copy
)
Introduktion till datakvalitet med Great Expectations

Kontrollera Expectations

print(
    expectation_copy in another_suite.expectations
)
True
Introduktion till datakvalitet med Great Expectations

Ta bort Expectations

Lägg till

.add_expectation()

suite.add_expectation(
    expectation=expectation
)

Ta bort

.delete_expectation()

suite.delete_expectation(
    expectation=expectation
)
Introduktion till datakvalitet med Great Expectations

Justera Expectations

Uppdatera attributet .value och spara ändringarna:

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

expectation.value = 11
expectation.save()

Expectation måste tillhöra en Suite, annars:

RuntimeError: Expectation must be added to ExpectationSuite before it can be saved.
Introduktion till datakvalitet med Great Expectations

Uppdatera en Expectation Suite

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()
Introduktion till datakvalitet med Great Expectations

Spara en Expectation Suite

Spara ändringarna i Suite:n innan du kör Validation Definition för att undvika fel:

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.
Introduktion till datakvalitet med Great Expectations

Spara en Expectation Suite

Använd metoden .save() för att spara Suite:n och köra Validation Definition utan fel:

suite.save()

validation_results = validation_definition.run()
print(validation_results.success)
False
Introduktion till datakvalitet med Great Expectations

Lathund

Kopiera Expectation:

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

Kontrollera om Expectation finns i Suite:n:

expectation in suite.expectations

Ta bort Expectation:

suite.delete_expectation(expectation)

Uppdatera Expectation-värde:

expectation.value = new_value

Spara ändringar i Expectation:

expectation.save()

Spara ändringar i Expectation Suite:

suite.save()
Introduktion till datakvalitet med Great Expectations

Nu kör vi en övning!

Introduktion till datakvalitet med Great Expectations

Preparing Video For Download...