Great Expectations로 배우는 데이터 품질 입문
Davina Moossazadeh
Data Scientist
expectation = gx.expectations.ExpectTableColumnCountToEqual(
value=10
)
suite = gx.ExpectationSuite(
name="my_suite"
)
# Suite에 Expectation 추가
suite.add_expectation(
expectation=expectation
)
# 또 다른 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`.
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을 복사하고 .id를 None으로 설정한 뒤, 오류 없이 새 Suite에 추가합니다:
expectation_copy = expectation.copy()expectation_copy.id = None
another_suite.add_expectation(
expectation=expectation_copy
)
print(
expectation_copy in another_suite.expectations
)
True
추가
.add_expectation()
suite.add_expectation(
expectation=expectation
)
삭제
.delete_expectation()
suite.delete_expectation(
expectation=expectation
)
.value 속성을 업데이트하고 저장합니다:
expectation = gx.expectations.ExpectTableColumnCountToEqual( value=10 )expectation.value = 11expectation.save()
Expectation이 Suite에 속해야 합니다. 그렇지 않으면:
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"
)
# 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()
오류를 피하려면 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.
.save() 메서드로 Suite를 저장한 뒤, 오류 없이 Validation Definition을 실행합니다:
suite.save()validation_results = validation_definition.run()print(validation_results.success)
False
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로 배우는 데이터 품질 입문