Expectation Suite 업데이트

Great Expectations로 배우는 데이터 품질 입문

Davina Moossazadeh

Data Scientist

Expectation 추가

expectation = gx.expectations.ExpectTableColumnCountToEqual(
    value=10
)
suite = gx.ExpectationSuite(
    name="my_suite"
)
# Suite에 Expectation 추가
suite.add_expectation(
    expectation=expectation
)
Great Expectations로 배우는 데이터 품질 입문

여러 Expectation Suite

# 또 다른 Expectation Suite 생성
another_suite = gx.ExpectationSuite(name="my_other_suite")
# 동일한 Expectation을 새 Suite에 추가
another_suite.add_expectation(expectation=expectation)

하나의 Expectation은 동시에 여러 Suite에 속할 수 없습니다:

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로 배우는 데이터 품질 입문

Expectation 복사

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

Expectation을 복사하고 .idNone으로 설정한 뒤, 오류 없이 새 Suite에 추가합니다:

expectation_copy = expectation.copy()

expectation_copy.id = None
another_suite.add_expectation(
    expectation=expectation_copy
)
Great Expectations로 배우는 데이터 품질 입문

Expectation 확인

print(
    expectation_copy in another_suite.expectations
)
True
Great Expectations로 배우는 데이터 품질 입문

Expectation 삭제

추가

.add_expectation()

suite.add_expectation(
    expectation=expectation
)

삭제

.delete_expectation()

suite.delete_expectation(
    expectation=expectation
)
Great Expectations로 배우는 데이터 품질 입문

Expectation 조정

.value 속성을 업데이트하고 저장합니다:

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

expectation.value = 11
expectation.save()

Expectation이 Suite에 속해야 합니다. 그렇지 않으면:

RuntimeError: Expectation must be added to ExpectationSuite before it can be saved.
Great Expectations로 배우는 데이터 품질 입문

Expectation Suite 업데이트

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

# Suite에 Expectation 추가 suite.add_expectation(expectation=col_name_expectation)
# Suite에 연결된 Validation Definition 실행 validation_results = validation_definition.run()
Great Expectations로 배우는 데이터 품질 입문

Expectation Suite 저장

오류를 피하려면 Validation Definition 실행 전 Suite 변경 사항을 저장하십시오:

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로 배우는 데이터 품질 입문

Expectation Suite 저장

.save() 메서드로 Suite를 저장한 뒤, 오류 없이 Validation Definition을 실행합니다:

suite.save()

validation_results = validation_definition.run()
print(validation_results.success)
False
Great Expectations로 배우는 데이터 품질 입문

치트시트

Expectation 복사:

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

Expectation이 Suite에 있는지 확인:

expectation in suite.expectations

Expectation 삭제:

suite.delete_expectation(expectation)

Expectation 값 업데이트:

expectation.value = new_value

Expectation 변경 사항 저장:

expectation.save()

Expectation Suite 변경 사항 저장:

suite.save()
Great Expectations로 배우는 데이터 품질 입문

연습해 봅시다!

Great Expectations로 배우는 데이터 품질 입문

Preparing Video For Download...