Great Expectations ile Veri Kalitesine Giriş
Davina Moossazadeh
Data Scientist
expectation = gx.expectations.ExpectTableColumnCountToEqual(
value=10
)
suite = gx.ExpectationSuite(
name="my_suite"
)
# Beklentiyi Takıma ekle
suite.add_expectation(
expectation=expectation
)
# Başka bir Beklenti Takımı oluştur
another_suite = gx.ExpectationSuite(name="my_other_suite")
# Aynı Beklentiyi yeni Takıma ekle
another_suite.add_expectation(expectation=expectation)
Beklentiler aynı anda birden fazla Takıma ait olamaz:
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`.
Beklentiyi kopyalayın, .id değerini None yapın ve hatasız şekilde yeni Takıma ekleyin:
expectation_copy = expectation.copy()expectation_copy.id = None
another_suite.add_expectation(
expectation=expectation_copy
)
print(
expectation_copy in another_suite.expectations
)
True
Ekle
.add_expectation()
suite.add_expectation(
expectation=expectation
)
Sil
.delete_expectation()
suite.delete_expectation(
expectation=expectation
)
.value özniteliğini güncelleyin ve değişiklikleri kaydedin:
expectation = gx.expectations.ExpectTableColumnCountToEqual( value=10 )expectation.value = 11expectation.save()
Beklentinin bir Takıma ait olduğundan emin olun, aksi halde:
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"
)
# Beklentiyi tanımla col_name_expectation = gx.expectations.ExpectColumnToExist(column="GHI")# Beklentiyi Takıma ekle suite.add_expectation(expectation=col_name_expectation)# Takım ile ilişkili Doğrulama Tanımını çalıştır validation_results = validation_definition.run()
Hataları önlemek için Doğrulama Tanımını çalıştırmadan önce Takımdaki değişiklikleri kaydedin:
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.
Takımı kaydetmek ve Doğrulama Tanımını hatasız çalıştırmak için .save() yöntemini kullanın:
suite.save()validation_results = validation_definition.run()print(validation_results.success)
False
Beklentiyi kopyalayın:
expectation_copy = expectation.copy()
expectation_copy.id = None
Beklentinin Takımda olup olmadığını kontrol edin:
expectation in suite.expectations
Beklentiyi silin:
suite.delete_expectation(expectation)
Beklenti değerini güncelleyin:
expectation.value = new_value
Beklentideki değişiklikleri kaydedin:
expectation.save()
Beklenti Takımındaki değişiklikleri kaydedin:
suite.save()
Great Expectations ile Veri Kalitesine Giriş