https://kedro.org/ logo
#resources
Title
# resources
c

Chris Schopp

12/05/2023, 2:52 PM
A tip I wanted to share: You can name a node using the dunder method
__name__
instead of typing out a
str
.
Copy code
node(
func=explode_missing_values,
...
name=explode_missing_values.__name__,
)

# is equivalent to

node(
func=explode_missing_values,
...
name="explode_missing_values",
)
If you're setting the node name to be the function name, this makes it so renaming the function and the node is just one step.
K 4
๐Ÿ™๐Ÿผ 1
๐Ÿ™ 1
d

datajoely

12/05/2023, 2:54 PM
out of interest, would you like this if it was default behaviour? i.e. if not provided we do this
c

Chris Schopp

12/05/2023, 2:55 PM
Just tried commenting out where I named the nodes and am wondering if this is default behavior already? I think it would be a good default behavior, if it's not already.
j

Juan Luis

12/05/2023, 2:56 PM
I think the default is
name=None
, I'm 100 % supportive of making
func.__name__
the default if not given
thanks for sharing @Chris Schopp!
d

datajoely

12/05/2023, 2:58 PM
Would this count as a breaking change?
I think itโ€™s
None
python side, but Viz may do some guesswork
j

Juan Luis

12/05/2023, 2:59 PM
yeah, better to proceed with care
d

datajoely

12/05/2023, 3:00 PM
my point is we canโ€™t squeeze it into 0.19.x right?
c

Chris Schopp

12/05/2023, 3:07 PM
From what I can tell there is no difference in Kedro Viz between
name=None
and
name=func.__name__
but the logger shows a minor difference: None:
Running node: explode_missing_values([input]) -> [output]
___name___:
Running node: explode_missing_values: explode_missing_values([input]) -> [output]
d

datajoely

12/05/2023, 3:09 PM
Yeah I think the point is Viz is inferring this rather than it really being true in the Python node
๐Ÿ‘ 1
j

Juan Luis

12/05/2023, 4:13 PM
my point is we canโ€™t squeeze it into 0.19.x right?
I think it's safe to say we're in "feature freeze" mode atm, the release will come in a few days and we're squashing the last blockers
๐Ÿ‘ 1
d

datajoely

12/05/2023, 4:17 PM
shame - but we should put it in the next version
m

Marc Gris

12/06/2023, 10:33 AM
Thx @Chris Schopp Very handy indeed. And (for what my opinion is worth ๐Ÿ˜… )I will second @Juan Luis in saying that too am โ€œ_100 % supportive of making
func.__name__
the default if not given_โ€
๐Ÿ‘ 2
j

Juan Luis

12/12/2023, 12:03 PM
from the 0.19.0 release notes:
Anonymous nodes are given default names of the form
<function_name>([in1;in2;...]) -> [out1;out2;...]
, with the names of inputs and outputs separated by semicolons.
5 Views