如何为Pandas Dataframe 创建远大前程检查点?

voase2hg  于 2022-11-27  发布在  其他
关注(0)|答案(1)|浏览(95)

我的数据源配置如下所示:

datasource_config = {
    "name": "example_datasource",
    "class_name": "Datasource",
    "module_name": "great_expectations.datasource",
    "execution_engine": {
        "module_name": "great_expectations.execution_engine",
        "class_name": "PandasExecutionEngine",
    },
    "data_connectors": {
        "default_runtime_data_connector_name": {
            "class_name": "RuntimeDataConnector",
            "module_name": "great_expectations.datasource.data_connector",
            "batch_identifiers": ["default_identifier_name"],
        },
    },
}
context.add_datasource(**datasource_config)

我的Pandas Dataframe 和batch_requests已通过以下命令成功创建:

...
df = read_csv_pandas(file_path="../done/my_file.txt", 
                           sep="|", 
                           header=0,
                           quoting=csv.QUOTE_ALL)

batch_request = RuntimeBatchRequest(
datasource_name="example_datasource",
data_connector_name="default_runtime_data_connector_name",
data_asset_name="MyDataAsset",
runtime_parameters={"batch_data": df},
batch_identifiers={"default_identifier_name": "default_identifier"}
)

我的期望套件:

expectation_suite_name = "My_validations"
suite = context.create_expectation_suite(expectation_suite_name, overwrite_existing=True)

然后创建验证程序。

validator = context.get_validator(
    batch_request=batch_request, expectation_suite_name=expectation_suite_name
)
validator.head(2)

最后一个命令成功打印了我的 Dataframe 的2行。
那我就给我的套房增加了期待。

validator.expect_table_columns_to_match_ordered_list(['last_name', 'first_name', 'sex'])
validator.expect_column_values_to_be_in_set("sex", ["male", "female", "other", "unknown"])
validator.save_expectation_suite(discard_failed_expectations=False)

然后生成数据文档:

suite_identifier = ExpectationSuiteIdentifier(expectation_suite_name=expectation_suite_name)
context.build_data_docs(resource_identifiers=[suite_identifier])
context.open_data_docs(resource_identifier=suite_identifier)

我的检查点如下所示:

name: my_checkpoint_2
config_version: 1
class_name: SimpleCheckpoint
validations:
    - batch_request:
        datasource_name: example_datasource
        data_connector_name: default_runtime_data_connector_name
        data_asset_name: MyDataAsset
        runtime_parameters:
          batch_data: {df}
        batch_identifiers:
          default_identifier_name: default_identifier
expectation_suite_name: My_validations

但这个命令

context.run_checkpoint(checkpoint_name="my_checkpoint_2")

产生错误:

ValueError: RuntimeDataBatchSpec must provide a Pandas DataFrame or PandasBatchData object.
ozxc1zmp

ozxc1zmp1#

Great Expectations具有多个执行引擎。您正在指定PandasExecutionEngine。执行引擎应更改为SparkDFExecutionEngine,或者您应将 Dataframe 转换为Pandas。

相关问题