【发布时间】:2021-02-02 12:00:10
【问题描述】:
我们使用的是 kedro 版本 0.15.8,我们以这种方式从目录中加载一个特定项目:
from kedro.context import load_context
get_context().catalog.datasets.__dict__[key]
现在,我们正在更改为 kedro 0.17.0 并尝试以相同的方式加载目录数据集(使用框架上下文):
from kedro.framework.context import load_context
get_context().catalog.datasets.__dict__[key]
现在我们得到了错误:
kedro.framework.context.context.KedroContextError:应为
ConfigLoader的实例,但得到NoneType。
这是因为项目中的 hook register_config_loader 没有被调用该函数的 hook_manager 使用。
项目挂钩的定义方式如下:
class ProjectHooks:
@hook_impl
def register_pipelines(self) -> Dict[str, Pipeline]:
"""Register the project's pipeline.
Returns:
A mapping from a pipeline name to a ``Pipeline`` object.
"""
pm = pre_master.create_pipeline()
return {
"pre_master": pm,
"__default__": pm
}
@hook_impl
def register_config_loader(self, conf_paths: Iterable[str]) -> ConfigLoader:
return ConfigLoader(conf_paths)
@hook_impl
def register_catalog(
self,
catalog: Optional[Dict[str, Dict[str, Any]]],
credentials: Dict[str, Dict[str, Any]],
load_versions: Dict[str, str],
save_version: str,
journal: Journal,
) -> DataCatalog:
return DataCatalog.from_config(
catalog, credentials, load_versions, save_version, journal
)
project_hooks = ProjectHooks()
设置的调用方式如下: """项目设置。"""
from price_based_trading.hooks import ProjectHooks
HOOKS = (ProjectHooks(),)
我们如何配置它以使用钩子调用方法 load_context(_working_dir).catalog.datasets ?
我在kedro社区发布了同样的问题:https://discourse.kedro.community/t/how-to-load-a-specific-catalog-item-in-kedro-0-17-0/310
【问题讨论】:
-
嗨,你在哪里运行这段代码?尝试使用会话:kedro.readthedocs.io/en/latest/04_kedro_project_setup/… -- 在页面底部有一个获取当前会话并加载特定数据集的示例。
-
我的另一个预感是,也许您正试图在 IPython 笔记本中执行此操作,并且您的 IPython 初始化脚本可能与 Kedro 0.17 不兼容。尝试使用
kedro new生成一个新项目,并使用新项目中同一文件中的内容覆盖.ipython/profile_default/startup/00-kedro-init.py的内容。 -
您好,您指出了正确的方向,我没有创建 KedroSession,这是未使用挂钩的原因