gpt4 book ai didi

python - 检查 Great Expectations 中的列名和列类型

转载 作者:行者123 更新时间:2023-12-05 05:31:00 24 4
gpt4 key购买 nike

目前,我正在通过输入列列表来使用 expect_table_columns_to_match_set 验证表架构。但是,我想验证与每一列关联的架构,例如 string。唯一可用的 Great Expectations 规则 expect_column_values_to_be_of_type 必须为每个列名编写,并且还通过重复列名创建冗余。

我是否缺少任何可以同时验证名称和架构的规则?

例如,给定列 a: string, b: int, c: boolean,我想将整个信息传递到一个函数中,而不必将其分解为 [a, b,c] 并分别为每一列验证 [a], string`。

理想情况下,它将类似于 expect_column_schmea([(column_name_a, column_type_a), (column_name_b, column_type_b)]

最佳答案

您可以使用 expect_column_values_to_match_json_schema(或正则表达式/模式 - 取决于您更熟悉的)。 Here是可以使用的期望列表。

expect_column_values_to_match_json_schema你可以用 json 格式定义你的模式:

schema = {
"column_name_a": {"type": "string"},
"column_name_b": {"type": "integer"},
"column_name_c": {"type": "boolean"},
}

创建一个新的 ExpectColumnValuesToMatchSchema 实例(为此导入 from great_expectations.expectations.core.expect_column_values_to_match_schema import ( ExpectColumnValuesToMatchSchema, )):

expectation = ExpectColumnValuesToMatchSchema(schema=schema)

最后验证它以获得结果:`result = expectation.validate(dataset)!

你会得到一个 ExpectationSuiteValidationResult作为返回,并可以相应地检查您提供的列是否匹配/不匹配架构!

关于python - 检查 Great Expectations 中的列名和列类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74483457/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com