Join the Kedro community

M
M
M
D
M

Getting node name while running inside a node

Hi all!

I was wondering if it is possible to get the name of a node while running inside a node. Use case I want to use it for writing a decorator around nodes that stores statistics on data processing, and I want to pass the name of the node to that as well, such that I can create a nice dataset πŸ™‚

Cheers,
Thomas

3
V
T
m
10 comments

Hi Thomas
Did you explore kedro Hooks. They might help you to prepare statistics for each node.

Good point thanks! Will explore this πŸ™‚ still curious if I can get the name of a node within a node context though

No and it's a bad pattern

Use hooks for such things as suggested

yeah node functions don't know they're being called from Kedro, they're Kedro-agnostic (it's a design decision so that they can be reused)

these questions come in very often though. the answer is using hooks but let us know if that fulfills your use case

I can feel your curiosity. You must be feeling more powerful within nodes πŸ™‚ . But believe me explore kedro properly and you will enjoy it . I am still trying to learn why kedro introduced each feature.

thanks a lot all! makes sense, thank you for the push to hooks and to good patterns πŸ™‚

I attempted to answer this question from a presentation before. Apologies that I never finish my half-written blog post.

But I have the materials here: https://github.com/noklam/miniKedro

The idea is that I try to "derive" individual feature steps by steps.

Thanks for sharing this beautiful piece of work. I have been looking for something like this . project like this will help someone like me who wants to start understanding kedro for open source contributions.

For a better developer experience the documentation is good enough to understand any tool and start using it. But when it comes to making some contributions it is really important to understand the underlying concepts on which a tool is created.
Again thanks for sharing a beautiful repo. I will find some time and go through this 😊

Before and after node run hook have access to Node class, which holds the func and name paramter. I think that should suffice to write a logic that treats nodes differently.

Attachment
image.png
Add a reply
Sign up and join the conversation on Slack
Join