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

Taipy Core配置及数据节点调用报错问题求助

Taipy Core 使用问题:加载配置并合并CSV数据时的报错处理

背景说明

  • 测试Taipy Core,需求是读取两个CSV文件并合并为pandas DataFrame,供Taipy GUI仪表板使用
  • 直接使用pandas读取转换数据时,仪表板运行正常,说明CSV文件和Taipy GUI本身无问题
  • 选择使用Taipy Core而非直接用pandas,唯一目的是学习该库,为后续实现复杂功能做铺垫

配置与代码实现

TOML配置文件(taipy-config.toml)

[TAIPY]

[JOB]

[DATA_NODE.fossil_energy]
storage_type = "csv"
scope = "GLOBAL:SCOPE"
default_path = "data/per-capita-fossil-energy-vs-gdp.csv"
has_header = "True:bool"
exposed_type = "pandas"

[DATA_NODE.country_codes]
storage_type = "csv"
scope = "GLOBAL:SCOPE"
default_path = "data/country_codes.csv"
has_header = "True:bool"
exposed_type = "pandas"

[DATA_NODE.final_dataset]
storage_type = "pickle"
scope = "CYCLE:SCOPE"
exposed_type = "pandas"


[TASK.add_continent]
inputs = [ "fossil_energy:SECTION", "country_codes:SECTION"]
function = "config.functions.preprocess:function"
outputs = [ "final_dataset:SECTION",]
skippable = "False:bool"


[PIPELINE.create_dataset]
tasks = [ "add_continent:SECTION", ]


[SCENARIO.scenario_configuration]
pipelines = [ "create_dataset:SECTION", ]
frequency = "MONTHLY:FREQUENCY"

初始config.py文件

from taipy import Config
import pandas as pd

Config.load("config/taipy-config.toml")

初始应用代码

# from data.data import dataset_fossil_fuels_gdp

import config.config as config

pipeline = tp.create_pipeline(config.create_dataset, name="Pipeline to load the dataset")

dataset_fossil_fuels_gdp = pipeline.final_dataset

....

第一次报错

运行应用代码后出现如下报错:

pipeline = tp.create_pipeline(config.create_dataset, name="Pipeline to load the dataset")
AttributeError: module 'config.config' has no attribute 'create_dataset'

同时日志显示配置已成功加载:

[2023-04-03 00:00:33,367][Taipy][INFO] Loading configuration. Filename: 'config/taipy-config.toml'
[2023-04-03 00:00:33,369][Taipy][INFO] Configuration 'config/taipy-config.toml' successfully loaded.


补充信息与第二次尝试

preprocess函数代码(用于合并并转换DataFrame)

def preprocess(dataset_fossil_fuels_gdp, country_codes):
    print("merging datasets")

    dataset_fossil_fuels_gdp = dataset_fossil_fuels_gdp.merge(
        country_codes[["alpha-3", "region"]],
        how="left",
        left_on="Code",
        right_on="alpha-3",
    )
    dataset_fossil_fuels_gdp = dataset_fossil_fuels_gdp[
        ~dataset_fossil_fuels_gdp["Fossil fuels per capita (kWh)"].isnull()
    ].reset_index()

    dataset_fossil_fuels_gdp["Fossil fuels per capita (kWh)"] = (
        dataset_fossil_fuels_gdp["Fossil fuels per capita (kWh)"] * 1000
    )

    return dataset_fossil_fuels_gdp

修改后的config.py文件

Config.load("config/taipy-config.toml")

# Get the pipeline and scenario configuration
pipeline_cfg = Config.pipelines['create_dataset']
scenario_cfg = Config.scenarios['scenario_configuration']

# Run the Core service
tp.Core().run()

# Creation of a pipeline and scenario based on the configuration
pipeline = tp.create_pipeline(pipeline_cfg)
scenario = tp.create_scenario(scenario_cfg)

修改后的应用代码

import config.config as config

pipeline = config.pipeline_cfg

dataset_fossil_fuels_gdp = pipeline.final_dataset

print(dataset_fossil_fuels_gdp.head())

.........

第二次报错

运行修改后的代码后出现新报错:

print(dataset_fossil_fuels_gdp.head())
AttributeError: 'NoneType' object has no attribute 'head'

疑问

原以为数据节点是pandas DataFrame这类数据结构,任务会对输入结构应用函数并输出对应数据结构,但现在出现上述报错,无法理解原因,需要解决该问题以实现目标功能,后续还会进一步扩展应用。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 21:17:20