You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从Pandas Profiling报告生成Great Expectations Suite报错求助

问题:Pandas Profiling转Great Expectations Expectation Suite报错找不到action_list_operator

我之前通过常规数据源连接方式用Great Expectations生成过断言,现在想结合Pandas Profiling,基于Profiling报告创建Expectation Suite,编写了如下代码:

import great_expectations as ge
import pandas as pd

from pandas_profiling import ProfileReport
import os

p = os.getcwd()
p += "\data\cars.csv"

df = pd.read_csv(p)

profile = ProfileReport(df, title="Pandas Profiling Report", explorative=True)

# Obtain expectation suite, this includes profiling the dataset, saving the expectation suite, validating the
# dataframe, and building data docs
suite = profile.to_expectation_suite(suite_name="cars_expectations")

运行后抛出如下错误:

Summarize dataset: 100%
81/81 [00:37<00:00, 3.01it/s, Completed]
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\great_expectations\data_context\data_context\base_data_context.py in run_validation_operator(self, validation_operator_name, assets_to_validate, run_id, evaluation_parameters, run_name, run_time, result_format, **kwargs)
    510         try:
--> 511             validation_operator = self.validation_operators[validation_operator_name]
    512         except KeyError:

KeyError: 'action_list_operator'

During handling of the above exception, another exception occurred:

DataContextError                          Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_4484/2792258824.py in <module>
     16 # Obtain expectation suite, this includes profiling the dataset, saving the expectation suite, validating the
     17 # dataframe, and building data docs
--> 18 suite = profile.to_expectation_suite(suite_name="cars_expectations")

C:\ProgramData\Anaconda3\lib\site-packages\pandas_profiling\expectations_report.py in to_expectation_suite(self, suite_name, data_context, save_suite, run_validation, build_data_docs, handler)
    101             batch = ge.dataset.PandasDataset(self.df, expectation_suite=suite)
    102 
--> 103             results = data_context.run_validation_operator(
    104                 "action_list_operator", assets_to_validate=[batch]
    105             )

C:\ProgramData\Anaconda3\lib\site-packages\great_expectations\core\usage_statistics\usage_statistics.py in usage_statistics_wrapped_method(*args, **kwargs)
    302                     nested_update(event_payload, args_payload_fn(*args, **kwargs))
    303 
--> 304                 result = func(*args, **kwargs)
    305                 message["success"] = True
    306             except Exception:

C:\ProgramData\Anaconda3\lib\site-packages\great_expectations\data_context\data_context\base_data_context.py in run_validation_operator(self, validation_operator_name, assets_to_validate, run_id, evaluation_parameters, run_name, run_time, result_format, **kwargs)
    511             validation_operator = self.validation_operators[validation_operator_name]
    512         except KeyError:
--> 513             raise ge_exceptions.DataContextError(
    514                 f"No validation operator `{validation_operator_name}` was found in your project. Please verify this in your great_expectations.yml"
    515             )

DataContextError: No validation operator `action_list_operator` was found in your project. Please verify this in your great_expectations.yml

使用版本:

  • Pandas-Profiling 3.4.0
  • Great Expectations 0.15.32

解决方法

这个错误的核心原因是Great Expectations的项目配置中缺少action_list_operator验证算子,或者未初始化GE项目环境。以下是三种可行的解决方案:

1. 初始化Great Expectations项目

如果当前工作目录还不是GE项目,运行以下命令初始化:

great_expectations init

初始化过程会自动生成包含action_list_operator默认配置的great_expectations.yml文件,以及完整的GE项目结构。

2. 手动添加算子配置到已有项目

若已有GE项目但配置缺失,打开great_expectations.yml,找到validation_operators节点,添加如下配置:

validation_operators:
  action_list_operator:
    class_name: ActionListValidationOperator
    action_list:
      - name: store_validation_result
        action:
          class_name: StoreValidationResultAction
      - name: store_evaluation_params
        action:
          class_name: StoreEvaluationParametersAction
      - name: update_data_docs
        action:
          class_name: UpdateDataDocsAction

保存配置后重新运行代码即可。

3. 跳过验证和文档构建

如果不需要执行验证或构建数据文档,可以修改to_expectation_suite的调用参数,跳过这些依赖算子的步骤:

suite = profile.to_expectation_suite(
    suite_name="cars_expectations",
    run_validation=False,
    build_data_docs=False
)

这种方式仅生成Expectation Suite,无需依赖action_list_operator。


内容的提问来源于stack exchange,提问作者HenrikS

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 19:51:02