You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/faq/faq.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ This is a growing set of technical FAQs. The [product FAQs on the Kedro website]
14
14
15
15
## Working with Jupyter
16
16
17
-
*[How can I convert functions from Jupyter Notebooks into Kedro nodes](../notebooks_and_ipython/kedro_and_notebooks.md#how-to-use-tags-to-convert-functions-from-jupyter-notebooks-into-kedro-nodes)?
17
+
*[How can I debug a Kedro project in a Jupyter notebook](../notebooks_and_ipython/kedro_and_notebooks.md#debugging-with-debug-and-pdb)?
18
18
*[How do I connect a Kedro project kernel to other Jupyter clients like JupyterLab](../notebooks_and_ipython/kedro_and_notebooks.md#ipython-jupyterlab-and-other-jupyter-clients)?
Copy file name to clipboardExpand all lines: docs/source/notebooks_and_ipython/kedro_and_notebooks.md
+46-17Lines changed: 46 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -209,32 +209,61 @@ You don't need to restart the kernel for the `catalog`, `context`, `pipelines` a
209
209
210
210
For more details, run `%reload_kedro?`.
211
211
212
-
## How to use tags to convert functions from Jupyter notebooks into Kedro nodes
212
+
## Useful to know (for advanced users)
213
+
Each Kedro project has its own Jupyter kernel so you can switch between Kedro projects from a single Jupyter instance by selecting the appropriate kernel.
213
214
214
-
You can use the notebook to write experimental code for your Kedro project. If you later want to convert functions you've written to Kedro nodes, you can do this using `node` tags to export them to a Python file. Say you have the following code in your notebook:
215
+
To ensure that a Jupyter kernel always points to the correct Python executable, if one already exists with the same name `kedro_<package_name>`, then it is replaced.
215
216
216
-
```ipython
217
-
def some_action():
218
-
print("This function came from `notebooks/my_notebook.ipynb`")
219
-
```
217
+
You can use the `jupyter kernelspec` set of commands to manage your Jupyter kernels. For example, to remove a kernel, run `jupyter kernelspec remove <kernel_name>`.

219
+
### Debugging with %debug and %pdb
223
220
224
-
2. Add the `node` tag to the cell containing your function
225
-

221
+
You can use the `%debug`[line magic](https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-debug) to launch an interactive debugger in your Jupyter notebook. Declare it before a single-line statement to step through the execution in debug mode. You can use the argument `--breakpoint` or `-b` to provide a breakpoint.
222
+
The follow sequence occurs when `%debug` runs immediately after an error occurs:
223
+
- The stack trace of the last unhandled exception loads.
224
+
- The program stops at the point where the exception occurred.
225
+
- An interactive shell where the user can navigate through the stack trace opens.
226
226
227
+
You can then inspect the value of expressions and arguments, or add breakpoints to the code.
227
228
228
-
3. Save your Jupyter notebook to `notebooks/my_notebook.ipynb`
229
-
4. From your terminal, run `kedro jupyter convert notebooks/my_notebook.ipynb` from the Kedro project directory. The output is a Python file `src/<package_name>/nodes/my_notebook.py` containing the `some_action` function definition
230
-
5. The `some_action` function can now be used in your Kedro pipelines
229
+
<details>
230
+
<summary>Click to see an example.</summary>
231
231
232
-
## Useful to know (for advanced users)
233
-
Each Kedro project has its own Jupyter kernel so you can switch between Kedro projects from a single Jupyter instance by selecting the appropriate kernel.
If a Jupyter kernel with the name `kedro_<package_name>` already exists then it is replaced. This ensures that the kernel always points to the correct Python executable. For example, if you change conda environment in a Kedro project then you should re-run `kedro jupyter notebook` to replace the kernel specification with one that points to the new environment.
234
+
</details>
235
+
236
+
---
237
+
238
+
You can set up the debugger to run automatically when an exception occurs by using the `%pdb`[line magic](https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-pdb). This automatic behaviour can be enabled with `%pdb 1` or `%pdb on` before executing a program, and disabled with `%pdb 0` or `%pdb off`.
|`h(elp)`| Show a list of commands, or find help on a specific command |
255
+
|`q(uit)`| Quit the debugger and the program |
256
+
|`c(ontinue)`| Quit the debugger, continue in the program |
257
+
|`n(ext)`| Go to the next step of the program |
258
+
|`<enter>`| Repeat the previous command |
259
+
|`p(rint)`| Print variables |
260
+
|`s(tep)`| Step into a subroutine |
261
+
|`r(eturn)`| Return out of a subroutine |
262
+
|`b(reak)`| Insert a breakpoint |
263
+
|`a(rgs)`| Print the argument list of the current function |
264
+
265
+
For more information, use the `help` command in the debugger, or take at the [ipdb repository](https://github.com/gotcha/ipdb) for guidance.
236
266
237
-
You can use the `jupyter kernelspec` set of commands to manage your Jupyter kernels. For example, to remove a kernel, run `jupyter kernelspec remove <kernel_name>`.
0 commit comments