33In the previous tutorials and how-to guides, you learned that dependencies and products
44can be represented as plain Python objects with
55[ pytask.PythonNode] ( ../api/nodes_and_tasks.md#pytask.PythonNode ) or as paths where every
6- ` pathlib.Path ` is converted to a
6+ \[ ` pathlib.Path ` \] [ ] is converted to a
77[ pytask.PathNode] ( ../api/nodes_and_tasks.md#pytask.PathNode ) .
88
99In this how-to guide, you will learn about the general concept of nodes and how to write
1010your own to improve your workflows.
1111
1212## Use-case
1313
14- A typical task operation is to load data like a ` pandas.DataFrame ` from a pickle file,
15- transform it, and store it on disk. The usual way would be to use paths to point to
16- inputs and outputs and call ` pandas.read_pickle ` and ` pandas.DataFrame.to_pickle ` .
14+ A typical task operation is to load data like a \[ ` pandas.DataFrame ` \] [ ] from a pickle
15+ file, transform it, and store it on disk. The usual way would be to use paths to point
16+ to inputs and outputs and call \[ ` pandas.read_pickle ` \] [ ] and
17+ \[ ` pandas.DataFrame.to_pickle ` \] [ ] .
1718
1819``` py
1920-- 8 < -- " docs_src/how_to_guides/writing_custom_nodes_example_1.py"
@@ -23,7 +24,7 @@ To remove IO operations from the task and delegate them to pytask, we will repli
2324[ pytask.PickleNode] ( ../api/nodes_and_tasks.md#pytask.PickleNode ) that automatically
2425loads and stores Python objects.
2526
26- And we pass the value to ` df ` via ` typing.Annotated ` to preserve the type hint.
27+ And we pass the value to ` df ` via \[ ` typing.Annotated ` \] [ ] to preserve the type hint.
2728
2829The result will be the following task.
2930
@@ -82,28 +83,34 @@ Here are some explanations.
8283 [ pytask.PickleNode.from_path] ( ../api/nodes_and_tasks.md#pytask.PickleNode.from_path )
8384 is a convenient method to instantiate the class.
8485
85- - The method ` pytask.PickleNode.state ` yields a value that signals the node's state. If
86- the value changes, pytask knows it needs to regenerate the workflow. We can use the
87- timestamp of when the node was last modified.
86+ - The method
87+ [ ` pytask.PickleNode.state ` ] ( ../api/nodes_and_tasks.md#pytask.PickleNode.state ) yields
88+ a value that signals the node's state. If the value changes, pytask knows it needs
89+ to regenerate the workflow. We can use the timestamp of when the node was last
90+ modified.
8891
89- - pytask calls ` pytask.PickleNode.load ` when it collects the values of function
90- arguments to run the function. The argument ` is_product ` signals that the node is
91- loaded as a product with a
92+ - pytask calls
93+ [ ` pytask.PickleNode.load ` ] ( ../api/nodes_and_tasks.md#pytask.PickleNode.load ) when it
94+ collects the values of function arguments to run the function. The argument
95+ ` is_product ` signals that the node is loaded as a product with a
9296 [ pytask.Product] ( ../api/utilities_and_typing.md#pytask.Product ) annotation or via
9397 ` produces ` .
9498
9599 When the node is loaded as a dependency, we want to inject the value of the pickle
96100 file. In the other case, the node returns itself so users can call
97- ` pytask.PickleNode.save ` themselves.
101+ [ ` pytask.PickleNode.save ` ] ( ../api/nodes_and_tasks.md#pytask.PickleNode.save )
102+ themselves.
98103
99- - ` pytask.PickleNode.save ` is called when a task function returns and allows to save the
100- return values.
104+ - [ ` pytask.PickleNode.save ` ] ( ../api/nodes_and_tasks.md#pytask.PickleNode.save ) is called
105+ when a task function returns and allows to save the return values.
101106
102107## Improvements
103108
104- Usually, you would like your custom node to work with ` pathlib.Path ` objects and
105- ` upath.UPath ` objects allowing to work with remote filesystems. To simplify getting the
106- state of the node, you can use the ` pytask.get_state_of_path ` function.
109+ Usually, you would like your custom node to work with \[ ` pathlib.Path ` \] [ ] objects and
110+ \[ ` upath.UPath ` \] [ ] objects allowing to work with remote filesystems. To simplify
111+ getting the state of the node, you can use the
112+ [ ` pytask.get_state_of_path ` ] ( ../api/utilities_and_typing.md#pytask.get_state_of_path )
113+ function.
107114
108115## Conclusion
109116
0 commit comments