Introduction to error handling#
+Learning Objectives#
+After working through this topic, you should be able to:
+-
+
Explain why error handling is important
+
Materials#
+Here is the +screencast. +These are the slides.
+diff --git a/_downloads/02455a388cef9885eb9ffbbbd37a47a9/python_basics-strings.pdf b/_downloads/02455a388cef9885eb9ffbbbd37a47a9/python_basics-strings.pdf index 332c0f55..0b152223 100644 Binary files a/_downloads/02455a388cef9885eb9ffbbbd37a47a9/python_basics-strings.pdf and b/_downloads/02455a388cef9885eb9ffbbbd37a47a9/python_basics-strings.pdf differ diff --git a/_downloads/02ea9566cd25492254b8ecd69e2dab51/plotting-goals_workflow.pdf b/_downloads/02ea9566cd25492254b8ecd69e2dab51/plotting-goals_workflow.pdf index 4540a543..54f289f1 100644 Binary files a/_downloads/02ea9566cd25492254b8ecd69e2dab51/plotting-goals_workflow.pdf and b/_downloads/02ea9566cd25492254b8ecd69e2dab51/plotting-goals_workflow.pdf differ diff --git a/_downloads/03b64cf485748e55c9f602b44d3cfba0/projects-writing_simple_pytasks.pdf b/_downloads/03b64cf485748e55c9f602b44d3cfba0/projects-writing_simple_pytasks.pdf index 567c1380..f086726b 100644 Binary files a/_downloads/03b64cf485748e55c9f602b44d3cfba0/projects-writing_simple_pytasks.pdf and b/_downloads/03b64cf485748e55c9f602b44d3cfba0/projects-writing_simple_pytasks.pdf differ diff --git a/_downloads/048af2856cd5004e582b3719a6ed54f5/software_engineering-idea_of_testing.pdf b/_downloads/048af2856cd5004e582b3719a6ed54f5/software_engineering-idea_of_testing.pdf index da94d6c4..ec0f38b5 100644 Binary files a/_downloads/048af2856cd5004e582b3719a6ed54f5/software_engineering-idea_of_testing.pdf and b/_downloads/048af2856cd5004e582b3719a6ed54f5/software_engineering-idea_of_testing.pdf differ diff --git a/_downloads/06a094bd3c5d699718160812bd1fade7/projects-directory_structure.pdf b/_downloads/06a094bd3c5d699718160812bd1fade7/projects-directory_structure.pdf index 59bf938e..9b5a3a26 100644 Binary files a/_downloads/06a094bd3c5d699718160812bd1fade7/projects-directory_structure.pdf and b/_downloads/06a094bd3c5d699718160812bd1fade7/projects-directory_structure.pdf differ diff --git a/_downloads/06b4f966cd9a770240a7476ea1c3985d/background-os_history.pdf b/_downloads/06b4f966cd9a770240a7476ea1c3985d/background-os_history.pdf index 203fa1a8..e280e57b 100644 Binary files a/_downloads/06b4f966cd9a770240a7476ea1c3985d/background-os_history.pdf and b/_downloads/06b4f966cd9a770240a7476ea1c3985d/background-os_history.pdf differ diff --git a/_downloads/07628fb03f37043c159a28dd5e8acac2/software_engineering-pure_functions.pdf b/_downloads/07628fb03f37043c159a28dd5e8acac2/software_engineering-pure_functions.pdf index 1b9dae7c..f8b6d024 100644 Binary files a/_downloads/07628fb03f37043c159a28dd5e8acac2/software_engineering-pure_functions.pdf and b/_downloads/07628fb03f37043c159a28dd5e8acac2/software_engineering-pure_functions.pdf differ diff --git a/_downloads/0cc420ff7ff8312cf025170258d15f74/plotting-tweak_px.pdf b/_downloads/0cc420ff7ff8312cf025170258d15f74/plotting-tweak_px.pdf index 59f03dd5..97a32e95 100644 Binary files a/_downloads/0cc420ff7ff8312cf025170258d15f74/plotting-tweak_px.pdf and b/_downloads/0cc420ff7ff8312cf025170258d15f74/plotting-tweak_px.pdf differ diff --git a/_downloads/0f33f4cb8a10352106b283c781a3e269/python_basics-functions_basics.pdf b/_downloads/0f33f4cb8a10352106b283c781a3e269/python_basics-functions_basics.pdf index 9a95e2e1..b69b5a52 100644 Binary files a/_downloads/0f33f4cb8a10352106b283c781a3e269/python_basics-functions_basics.pdf and b/_downloads/0f33f4cb8a10352106b283c781a3e269/python_basics-functions_basics.pdf differ diff --git a/_downloads/13c484b9f525026d99cf31d30670ee68/python_basics-pathlib.pdf b/_downloads/13c484b9f525026d99cf31d30670ee68/python_basics-pathlib.pdf index 8b3b3768..280bc6c2 100644 Binary files a/_downloads/13c484b9f525026d99cf31d30670ee68/python_basics-pathlib.pdf and b/_downloads/13c484b9f525026d99cf31d30670ee68/python_basics-pathlib.pdf differ diff --git a/_downloads/15ad80c05b0e5675f14eed62f3766214/projects-reproducibility.pdf b/_downloads/15ad80c05b0e5675f14eed62f3766214/projects-reproducibility.pdf index 8049e1b8..45763bb1 100644 Binary files a/_downloads/15ad80c05b0e5675f14eed62f3766214/projects-reproducibility.pdf and b/_downloads/15ad80c05b0e5675f14eed62f3766214/projects-reproducibility.pdf differ diff --git a/_downloads/22393dd56dc1451a88a1a245f8716811/pandas-what_is_pandas.pdf b/_downloads/22393dd56dc1451a88a1a245f8716811/pandas-what_is_pandas.pdf index 00a58f2c..64d3485c 100644 Binary files a/_downloads/22393dd56dc1451a88a1a245f8716811/pandas-what_is_pandas.pdf and b/_downloads/22393dd56dc1451a88a1a245f8716811/pandas-what_is_pandas.pdf differ diff --git a/_downloads/296f9d7b6a2c1a89f30b04766d949f47/background-file_systems.pdf b/_downloads/296f9d7b6a2c1a89f30b04766d949f47/background-file_systems.pdf index 27cd497d..9d8ebf20 100644 Binary files a/_downloads/296f9d7b6a2c1a89f30b04766d949f47/background-file_systems.pdf and b/_downloads/296f9d7b6a2c1a89f30b04766d949f47/background-file_systems.pdf differ diff --git a/_downloads/2c55eab50a3eba258876c70376ddaf46/software_engineering-reuse_test_code.pdf b/_downloads/2c55eab50a3eba258876c70376ddaf46/software_engineering-reuse_test_code.pdf index 9e8f7127..e09cb99d 100644 Binary files a/_downloads/2c55eab50a3eba258876c70376ddaf46/software_engineering-reuse_test_code.pdf and b/_downloads/2c55eab50a3eba258876c70376ddaf46/software_engineering-reuse_test_code.pdf differ diff --git a/_downloads/2e495dd57d3d5b8c1e03386ab3c34ba0/tools-windows_navigation.pdf b/_downloads/2e495dd57d3d5b8c1e03386ab3c34ba0/tools-windows_navigation.pdf index 90e96a8a..f37e9822 100644 Binary files a/_downloads/2e495dd57d3d5b8c1e03386ab3c34ba0/tools-windows_navigation.pdf and b/_downloads/2e495dd57d3d5b8c1e03386ab3c34ba0/tools-windows_navigation.pdf differ diff --git a/_downloads/30e1b642a2ee90a95beffbebdcc7e8f1/python_installation_execution-executing_py_shell.pdf b/_downloads/30e1b642a2ee90a95beffbebdcc7e8f1/python_installation_execution-executing_py_shell.pdf index 459691b5..b200684e 100644 Binary files a/_downloads/30e1b642a2ee90a95beffbebdcc7e8f1/python_installation_execution-executing_py_shell.pdf and b/_downloads/30e1b642a2ee90a95beffbebdcc7e8f1/python_installation_execution-executing_py_shell.pdf differ diff --git a/_downloads/329adf43100cc51769b6c3102f726419/tools-why_shells_today.pdf b/_downloads/329adf43100cc51769b6c3102f726419/tools-why_shells_today.pdf index 0c5599bf..8952e889 100644 Binary files a/_downloads/329adf43100cc51769b6c3102f726419/tools-why_shells_today.pdf and b/_downloads/329adf43100cc51769b6c3102f726419/tools-why_shells_today.pdf differ diff --git a/_downloads/3793951a17990cd6feb257c3fe80858f/projects-setup.pdf b/_downloads/3793951a17990cd6feb257c3fe80858f/projects-setup.pdf index 01c01848..de2d6448 100644 Binary files a/_downloads/3793951a17990cd6feb257c3fe80858f/projects-setup.pdf and b/_downloads/3793951a17990cd6feb257c3fe80858f/projects-setup.pdf differ diff --git a/_downloads/3ac9bbbdb4a26f6f1742605a5f43f70d/pandas-loading_and_saving.pdf b/_downloads/3ac9bbbdb4a26f6f1742605a5f43f70d/pandas-loading_and_saving.pdf index 3c171966..2f781ef9 100644 Binary files a/_downloads/3ac9bbbdb4a26f6f1742605a5f43f70d/pandas-loading_and_saving.pdf and b/_downloads/3ac9bbbdb4a26f6f1742605a5f43f70d/pandas-loading_and_saving.pdf differ diff --git a/_downloads/3ed1f0100c7aa24a3649081fa05a962d/scientific_computing-indexing.pdf b/_downloads/3ed1f0100c7aa24a3649081fa05a962d/scientific_computing-indexing.pdf index 699d366c..c91b0c46 100644 Binary files a/_downloads/3ed1f0100c7aa24a3649081fa05a962d/scientific_computing-indexing.pdf and b/_downloads/3ed1f0100c7aa24a3649081fa05a962d/scientific_computing-indexing.pdf differ diff --git a/_downloads/42992eab203923aca81c879a5399449f/projects-pytask_docs.pdf b/_downloads/42992eab203923aca81c879a5399449f/projects-pytask_docs.pdf index f49fe081..c2526280 100644 Binary files a/_downloads/42992eab203923aca81c879a5399449f/projects-pytask_docs.pdf and b/_downloads/42992eab203923aca81c879a5399449f/projects-pytask_docs.pdf differ diff --git a/_downloads/453ea7970daf3fd8a7fe6c3f544af8d5/python_installation_execution-executing_notebook_vscode.pdf b/_downloads/453ea7970daf3fd8a7fe6c3f544af8d5/python_installation_execution-executing_notebook_vscode.pdf index f1b4e732..329dbcf3 100644 Binary files a/_downloads/453ea7970daf3fd8a7fe6c3f544af8d5/python_installation_execution-executing_notebook_vscode.pdf and b/_downloads/453ea7970daf3fd8a7fe6c3f544af8d5/python_installation_execution-executing_notebook_vscode.pdf differ diff --git a/_downloads/4c66bfbe3a35405995054adb622e4700/plotting-what_to_plot.pdf b/_downloads/4c66bfbe3a35405995054adb622e4700/plotting-what_to_plot.pdf index 740c36e6..5cf141fd 100644 Binary files a/_downloads/4c66bfbe3a35405995054adb622e4700/plotting-what_to_plot.pdf and b/_downloads/4c66bfbe3a35405995054adb622e4700/plotting-what_to_plot.pdf differ diff --git a/_downloads/4fc2a5a7ae966a3e4a028dd490024ced/projects-reusing_pytask_functions.pdf b/_downloads/4fc2a5a7ae966a3e4a028dd490024ced/projects-reusing_pytask_functions.pdf index d54c0fb2..cc81d549 100644 Binary files a/_downloads/4fc2a5a7ae966a3e4a028dd490024ced/projects-reusing_pytask_functions.pdf and b/_downloads/4fc2a5a7ae966a3e4a028dd490024ced/projects-reusing_pytask_functions.pdf differ diff --git a/_downloads/5140db96ccdfb8ce7cbb85ed14c1d041/projects-paths.pdf b/_downloads/5140db96ccdfb8ce7cbb85ed14c1d041/projects-paths.pdf index 5bfee520..5273527d 100644 Binary files a/_downloads/5140db96ccdfb8ce7cbb85ed14c1d041/projects-paths.pdf and b/_downloads/5140db96ccdfb8ce7cbb85ed14c1d041/projects-paths.pdf differ diff --git a/_downloads/5758640a3af1b3d13e57bc59ebea0bbb/python_basics-importing.pdf b/_downloads/5758640a3af1b3d13e57bc59ebea0bbb/python_basics-importing.pdf index 97f283c0..614e197f 100644 Binary files a/_downloads/5758640a3af1b3d13e57bc59ebea0bbb/python_basics-importing.pdf and b/_downloads/5758640a3af1b3d13e57bc59ebea0bbb/python_basics-importing.pdf differ diff --git a/_downloads/58df93097a2a6ca43c53b1ad421c796e/python_installation_execution-executing_py_vscode.pdf b/_downloads/58df93097a2a6ca43c53b1ad421c796e/python_installation_execution-executing_py_vscode.pdf index 923a75e9..b5e6961d 100644 Binary files a/_downloads/58df93097a2a6ca43c53b1ad421c796e/python_installation_execution-executing_py_vscode.pdf and b/_downloads/58df93097a2a6ca43c53b1ad421c796e/python_installation_execution-executing_py_vscode.pdf differ diff --git a/_downloads/5a88042a5b93818d82a05790e5d0e9b0/software_engineering-what_does_pytest_do.pdf b/_downloads/5a88042a5b93818d82a05790e5d0e9b0/software_engineering-what_does_pytest_do.pdf index 75612bd9..6b2142a0 100644 Binary files a/_downloads/5a88042a5b93818d82a05790e5d0e9b0/software_engineering-what_does_pytest_do.pdf and b/_downloads/5a88042a5b93818d82a05790e5d0e9b0/software_engineering-what_does_pytest_do.pdf differ diff --git a/_downloads/5d004c6cbe8a015a4696d018810dcdd7/software_engineering-writing_simple_pytests.pdf b/_downloads/5d004c6cbe8a015a4696d018810dcdd7/software_engineering-writing_simple_pytests.pdf index d493add5..5e4ac0de 100644 Binary files a/_downloads/5d004c6cbe8a015a4696d018810dcdd7/software_engineering-writing_simple_pytests.pdf and b/_downloads/5d004c6cbe8a015a4696d018810dcdd7/software_engineering-writing_simple_pytests.pdf differ diff --git a/_downloads/61d4c36d3448dfe36e736b034ea41645/pandas-functional.pdf b/_downloads/61d4c36d3448dfe36e736b034ea41645/pandas-functional.pdf index 77f52c93..8ed45904 100644 Binary files a/_downloads/61d4c36d3448dfe36e736b034ea41645/pandas-functional.pdf and b/_downloads/61d4c36d3448dfe36e736b034ea41645/pandas-functional.pdf differ diff --git a/_downloads/625f517e924ac315b36bcb80e89f8e0b/python_basics-comprehensions.pdf b/_downloads/625f517e924ac315b36bcb80e89f8e0b/python_basics-comprehensions.pdf index 208fd2c8..94e37d85 100644 Binary files a/_downloads/625f517e924ac315b36bcb80e89f8e0b/python_basics-comprehensions.pdf and b/_downloads/625f517e924ac315b36bcb80e89f8e0b/python_basics-comprehensions.pdf differ diff --git a/_downloads/632263fe7c244d00de46295397df23b0/pandas-rules.pdf b/_downloads/632263fe7c244d00de46295397df23b0/pandas-rules.pdf index c98a387b..b99a892d 100644 Binary files a/_downloads/632263fe7c244d00de46295397df23b0/pandas-rules.pdf and b/_downloads/632263fe7c244d00de46295397df23b0/pandas-rules.pdf differ diff --git a/_downloads/6af7b7987d7b9db774a5e6a322d671a5/git-introduction.pdf b/_downloads/6af7b7987d7b9db774a5e6a322d671a5/git-introduction.pdf index f34c9b5f..a2b1e7bb 100644 Binary files a/_downloads/6af7b7987d7b9db774a5e6a322d671a5/git-introduction.pdf and b/_downloads/6af7b7987d7b9db774a5e6a322d671a5/git-introduction.pdf differ diff --git a/_downloads/6c9fa5aa9026570c8af4b5a275fcd3b3/python_basics-lists_tuples_sets.pdf b/_downloads/6c9fa5aa9026570c8af4b5a275fcd3b3/python_basics-lists_tuples_sets.pdf index ea19d553..37efcd26 100644 Binary files a/_downloads/6c9fa5aa9026570c8af4b5a275fcd3b3/python_basics-lists_tuples_sets.pdf and b/_downloads/6c9fa5aa9026570c8af4b5a275fcd3b3/python_basics-lists_tuples_sets.pdf differ diff --git a/_downloads/7074395418673116e11fdceabd3f837c/texts-markdown_applications.pdf b/_downloads/7074395418673116e11fdceabd3f837c/texts-markdown_applications.pdf index 5c80be4e..35b16fee 100644 Binary files a/_downloads/7074395418673116e11fdceabd3f837c/texts-markdown_applications.pdf and b/_downloads/7074395418673116e11fdceabd3f837c/texts-markdown_applications.pdf differ diff --git a/_downloads/71ec56bb1ce9431f6f20f7422348253a/background-graphs.pdf b/_downloads/71ec56bb1ce9431f6f20f7422348253a/background-graphs.pdf index 6e89bf33..62f7aea1 100644 Binary files a/_downloads/71ec56bb1ce9431f6f20f7422348253a/background-graphs.pdf and b/_downloads/71ec56bb1ce9431f6f20f7422348253a/background-graphs.pdf differ diff --git a/_downloads/789d55a1b19869498e1dca83b05c6fd6/software_engineering-error_handling_intro.pdf b/_downloads/789d55a1b19869498e1dca83b05c6fd6/software_engineering-error_handling_intro.pdf new file mode 100644 index 00000000..c083ae34 Binary files /dev/null and b/_downloads/789d55a1b19869498e1dca83b05c6fd6/software_engineering-error_handling_intro.pdf differ diff --git a/_downloads/797a90c46f861a8856f79d051a71ab66/pandas-merging.pdf b/_downloads/797a90c46f861a8856f79d051a71ab66/pandas-merging.pdf index 964af085..e638fd85 100644 Binary files a/_downloads/797a90c46f861a8856f79d051a71ab66/pandas-merging.pdf and b/_downloads/797a90c46f861a8856f79d051a71ab66/pandas-merging.pdf differ diff --git a/_downloads/7c891eb5cbacd6d67972dc6ab799bfdf/pandas-inspecting_and_summarizing.pdf b/_downloads/7c891eb5cbacd6d67972dc6ab799bfdf/pandas-inspecting_and_summarizing.pdf index c3bd3203..7b52009d 100644 Binary files a/_downloads/7c891eb5cbacd6d67972dc6ab799bfdf/pandas-inspecting_and_summarizing.pdf and b/_downloads/7c891eb5cbacd6d67972dc6ab799bfdf/pandas-inspecting_and_summarizing.pdf differ diff --git a/_downloads/7cbbde004a3f97b43452042711b06cdd/plotting-graph_objects.pdf b/_downloads/7cbbde004a3f97b43452042711b06cdd/plotting-graph_objects.pdf index d1ad8e8e..62d22463 100644 Binary files a/_downloads/7cbbde004a3f97b43452042711b06cdd/plotting-graph_objects.pdf and b/_downloads/7cbbde004a3f97b43452042711b06cdd/plotting-graph_objects.pdf differ diff --git a/_downloads/7ceda313aad825479ec338239f6bf7b4/software_engineering-what_and_how_to_test.pdf b/_downloads/7ceda313aad825479ec338239f6bf7b4/software_engineering-what_and_how_to_test.pdf index 9566172b..3754b959 100644 Binary files a/_downloads/7ceda313aad825479ec338239f6bf7b4/software_engineering-what_and_how_to_test.pdf and b/_downloads/7ceda313aad825479ec338239f6bf7b4/software_engineering-what_and_how_to_test.pdf differ diff --git a/_downloads/8030c72d58786632a25c3567a4d1b5d4/software_engineering-which_errors_to_handle.pdf b/_downloads/8030c72d58786632a25c3567a4d1b5d4/software_engineering-which_errors_to_handle.pdf new file mode 100644 index 00000000..fb6278e3 Binary files /dev/null and b/_downloads/8030c72d58786632a25c3567a4d1b5d4/software_engineering-which_errors_to_handle.pdf differ diff --git a/_downloads/83be5425c95a0fd95b0bf3cc42d1e254/git-pre_commits.pdf b/_downloads/83be5425c95a0fd95b0bf3cc42d1e254/git-pre_commits.pdf index be818ff1..deb3d155 100644 Binary files a/_downloads/83be5425c95a0fd95b0bf3cc42d1e254/git-pre_commits.pdf and b/_downloads/83be5425c95a0fd95b0bf3cc42d1e254/git-pre_commits.pdf differ diff --git a/_downloads/87f911a13823128cf33089e3b16a1f6d/projects-writing_pytasks_multiple_outputs.pdf b/_downloads/87f911a13823128cf33089e3b16a1f6d/projects-writing_pytasks_multiple_outputs.pdf index 1dc792ea..56a4c197 100644 Binary files a/_downloads/87f911a13823128cf33089e3b16a1f6d/projects-writing_pytasks_multiple_outputs.pdf and b/_downloads/87f911a13823128cf33089e3b16a1f6d/projects-writing_pytasks_multiple_outputs.pdf differ diff --git a/_downloads/8a24a95cdb3635530ee80fa72d9e598e/python_basics-functions_principles.pdf b/_downloads/8a24a95cdb3635530ee80fa72d9e598e/python_basics-functions_principles.pdf index d1838d41..108d0614 100644 Binary files a/_downloads/8a24a95cdb3635530ee80fa72d9e598e/python_basics-functions_principles.pdf and b/_downloads/8a24a95cdb3635530ee80fa72d9e598e/python_basics-functions_principles.pdf differ diff --git a/_downloads/8b6124abfc8e78494c7a9e9ec813e343/software_engineering-raising_errors.pdf b/_downloads/8b6124abfc8e78494c7a9e9ec813e343/software_engineering-raising_errors.pdf new file mode 100644 index 00000000..b08926c6 Binary files /dev/null and b/_downloads/8b6124abfc8e78494c7a9e9ec813e343/software_engineering-raising_errors.pdf differ diff --git a/_downloads/8c5c2ab8274b50eb811e7e2fa2464bb9/python_basics-assignment_and_scalar_types.pdf b/_downloads/8c5c2ab8274b50eb811e7e2fa2464bb9/python_basics-assignment_and_scalar_types.pdf index c5f65e3c..92d57030 100644 Binary files a/_downloads/8c5c2ab8274b50eb811e7e2fa2464bb9/python_basics-assignment_and_scalar_types.pdf and b/_downloads/8c5c2ab8274b50eb811e7e2fa2464bb9/python_basics-assignment_and_scalar_types.pdf differ diff --git a/_downloads/8d1c67ebba4b5b88ead060edaa601c5e/tools-unix_navigation.pdf b/_downloads/8d1c67ebba4b5b88ead060edaa601c5e/tools-unix_navigation.pdf index 46d4f27c..7f2b7c15 100644 Binary files a/_downloads/8d1c67ebba4b5b88ead060edaa601c5e/tools-unix_navigation.pdf and b/_downloads/8d1c67ebba4b5b88ead060edaa601c5e/tools-unix_navigation.pdf differ diff --git a/_downloads/910cbca26824838bbd0d41e3e23aa708/python_basics-tracebacks.pdf b/_downloads/910cbca26824838bbd0d41e3e23aa708/python_basics-tracebacks.pdf index 92ba5e94..68735a84 100644 Binary files a/_downloads/910cbca26824838bbd0d41e3e23aa708/python_basics-tracebacks.pdf and b/_downloads/910cbca26824838bbd0d41e3e23aa708/python_basics-tracebacks.pdf differ diff --git a/_downloads/9bbb01d4edb43a1a5e74132d956c2c92/python_basics-dicts.pdf b/_downloads/9bbb01d4edb43a1a5e74132d956c2c92/python_basics-dicts.pdf index 7ee1b2b0..106307a4 100644 Binary files a/_downloads/9bbb01d4edb43a1a5e74132d956c2c92/python_basics-dicts.pdf and b/_downloads/9bbb01d4edb43a1a5e74132d956c2c92/python_basics-dicts.pdf differ diff --git a/_downloads/a06eaa53c6a9367318583e7ba9e06a07/python_installation_execution-executing_notebook_browser.pdf b/_downloads/a06eaa53c6a9367318583e7ba9e06a07/python_installation_execution-executing_notebook_browser.pdf index 768fd972..a6d7b66d 100644 Binary files a/_downloads/a06eaa53c6a9367318583e7ba9e06a07/python_installation_execution-executing_notebook_browser.pdf and b/_downloads/a06eaa53c6a9367318583e7ba9e06a07/python_installation_execution-executing_notebook_browser.pdf differ diff --git a/_downloads/a509e4a67e3f9e44cbda610116a1f08c/plotting-why_plotly_prerequisites.pdf b/_downloads/a509e4a67e3f9e44cbda610116a1f08c/plotting-why_plotly_prerequisites.pdf index 66590522..12be5b8c 100644 Binary files a/_downloads/a509e4a67e3f9e44cbda610116a1f08c/plotting-why_plotly_prerequisites.pdf and b/_downloads/a509e4a67e3f9e44cbda610116a1f08c/plotting-why_plotly_prerequisites.pdf differ diff --git a/_downloads/a5cd74a273b58b2a37c0fb61b0829873/pandas-datatypes.pdf b/_downloads/a5cd74a273b58b2a37c0fb61b0829873/pandas-datatypes.pdf index d2f1ba0c..f5031f1b 100644 Binary files a/_downloads/a5cd74a273b58b2a37c0fb61b0829873/pandas-datatypes.pdf and b/_downloads/a5cd74a273b58b2a37c0fb61b0829873/pandas-datatypes.pdf differ diff --git a/_downloads/a8b235424fc9457bc5ffeef13bceb310/projects-what_does_pytask_do.pdf b/_downloads/a8b235424fc9457bc5ffeef13bceb310/projects-what_does_pytask_do.pdf index a2b92a2c..3089066d 100644 Binary files a/_downloads/a8b235424fc9457bc5ffeef13bceb310/projects-what_does_pytask_do.pdf and b/_downloads/a8b235424fc9457bc5ffeef13bceb310/projects-what_does_pytask_do.pdf differ diff --git a/_downloads/acd681a25c563b33ae9783852ff1c297/pandas-creating_variables.pdf b/_downloads/acd681a25c563b33ae9783852ff1c297/pandas-creating_variables.pdf index d1b6d59a..74671a02 100644 Binary files a/_downloads/acd681a25c563b33ae9783852ff1c297/pandas-creating_variables.pdf and b/_downloads/acd681a25c563b33ae9783852ff1c297/pandas-creating_variables.pdf differ diff --git a/_downloads/b7c5e64255df13f3fefbcbfa19a016a8/scientific_computing-what_is_numpy.pdf b/_downloads/b7c5e64255df13f3fefbcbfa19a016a8/scientific_computing-what_is_numpy.pdf index d60955ae..afccbf3c 100644 Binary files a/_downloads/b7c5e64255df13f3fefbcbfa19a016a8/scientific_computing-what_is_numpy.pdf and b/_downloads/b7c5e64255df13f3fefbcbfa19a016a8/scientific_computing-what_is_numpy.pdf differ diff --git a/_downloads/b91e063a3f0a95945309232042458e89/software_engineering-style_guides.pdf b/_downloads/b91e063a3f0a95945309232042458e89/software_engineering-style_guides.pdf index a1d5a957..6bc1a502 100644 Binary files a/_downloads/b91e063a3f0a95945309232042458e89/software_engineering-style_guides.pdf and b/_downloads/b91e063a3f0a95945309232042458e89/software_engineering-style_guides.pdf differ diff --git a/_downloads/bd9a2c40c03c40c252c2c72482d5a9b7/texts-markup_languages.pdf b/_downloads/bd9a2c40c03c40c252c2c72482d5a9b7/texts-markup_languages.pdf index 0bc3dcfb..d87eb54f 100644 Binary files a/_downloads/bd9a2c40c03c40c252c2c72482d5a9b7/texts-markup_languages.pdf and b/_downloads/bd9a2c40c03c40c252c2c72482d5a9b7/texts-markup_languages.pdf differ diff --git a/_downloads/c023cc969b9cb26a8a8d08a863dae075/plotting-quick_plots.pdf b/_downloads/c023cc969b9cb26a8a8d08a863dae075/plotting-quick_plots.pdf index 84dc2bdc..90a602a3 100644 Binary files a/_downloads/c023cc969b9cb26a8a8d08a863dae075/plotting-quick_plots.pdf and b/_downloads/c023cc969b9cb26a8a8d08a863dae075/plotting-quick_plots.pdf differ diff --git a/_downloads/cb575c6779071de1750436c36c0f21ab/pandas-selection.pdf b/_downloads/cb575c6779071de1750436c36c0f21ab/pandas-selection.pdf index b0e89607..c36c8854 100644 Binary files a/_downloads/cb575c6779071de1750436c36c0f21ab/pandas-selection.pdf and b/_downloads/cb575c6779071de1750436c36c0f21ab/pandas-selection.pdf differ diff --git a/_downloads/d23b6c04dfb5250081c1cce2563ac857/texts-markdown_syntax.pdf b/_downloads/d23b6c04dfb5250081c1cce2563ac857/texts-markdown_syntax.pdf index 61cee1e9..82455e54 100644 Binary files a/_downloads/d23b6c04dfb5250081c1cce2563ac857/texts-markdown_syntax.pdf and b/_downloads/d23b6c04dfb5250081c1cce2563ac857/texts-markdown_syntax.pdf differ diff --git a/_downloads/d6de29a86718ccdca654d77a04d7803d/software_engineering-pytest_error_handling.pdf b/_downloads/d6de29a86718ccdca654d77a04d7803d/software_engineering-pytest_error_handling.pdf index b8d07a5b..02e635ce 100644 Binary files a/_downloads/d6de29a86718ccdca654d77a04d7803d/software_engineering-pytest_error_handling.pdf and b/_downloads/d6de29a86718ccdca654d77a04d7803d/software_engineering-pytest_error_handling.pdf differ diff --git a/_downloads/da85e84f301287521c06ec8bfc78669c/python_basics-if_conditions.pdf b/_downloads/da85e84f301287521c06ec8bfc78669c/python_basics-if_conditions.pdf index e47e417d..28b9cdb6 100644 Binary files a/_downloads/da85e84f301287521c06ec8bfc78669c/python_basics-if_conditions.pdf and b/_downloads/da85e84f301287521c06ec8bfc78669c/python_basics-if_conditions.pdf differ diff --git a/_downloads/db875671b2c61c4fcbdba6f89f5ad948/pandas-columns_and_indices.pdf b/_downloads/db875671b2c61c4fcbdba6f89f5ad948/pandas-columns_and_indices.pdf index 8d7f445b..da8072ed 100644 Binary files a/_downloads/db875671b2c61c4fcbdba6f89f5ad948/pandas-columns_and_indices.pdf and b/_downloads/db875671b2c61c4fcbdba6f89f5ad948/pandas-columns_and_indices.pdf differ diff --git a/_downloads/df139a84f35436f8339569845315f423/scientific_computing-randomness.pdf b/_downloads/df139a84f35436f8339569845315f423/scientific_computing-randomness.pdf index f33510bf..211157e6 100644 Binary files a/_downloads/df139a84f35436f8339569845315f423/scientific_computing-randomness.pdf and b/_downloads/df139a84f35436f8339569845315f423/scientific_computing-randomness.pdf differ diff --git a/_downloads/e2e871c7829344ef74b246b61d6fe732/scientific_computing-creating_arrays.pdf b/_downloads/e2e871c7829344ef74b246b61d6fe732/scientific_computing-creating_arrays.pdf index ef32c34d..fc3b231f 100644 Binary files a/_downloads/e2e871c7829344ef74b246b61d6fe732/scientific_computing-creating_arrays.pdf and b/_downloads/e2e871c7829344ef74b246b61d6fe732/scientific_computing-creating_arrays.pdf differ diff --git a/_downloads/e3ed7701b9468b7f946b91043e5f0199/scientific_computing-calculations_between_arrays.pdf b/_downloads/e3ed7701b9468b7f946b91043e5f0199/scientific_computing-calculations_between_arrays.pdf index 6ed4e874..67c96484 100644 Binary files a/_downloads/e3ed7701b9468b7f946b91043e5f0199/scientific_computing-calculations_between_arrays.pdf and b/_downloads/e3ed7701b9468b7f946b91043e5f0199/scientific_computing-calculations_between_arrays.pdf differ diff --git a/_downloads/e447272ecd78c885703278ae78499cac/python_basics-for_loops.pdf b/_downloads/e447272ecd78c885703278ae78499cac/python_basics-for_loops.pdf index 785daad7..8ce6c357 100644 Binary files a/_downloads/e447272ecd78c885703278ae78499cac/python_basics-for_loops.pdf and b/_downloads/e447272ecd78c885703278ae78499cac/python_basics-for_loops.pdf differ diff --git a/_downloads/e459ceaf2fecdc2d90a41479eb777989/projects-what_are_templates.pdf b/_downloads/e459ceaf2fecdc2d90a41479eb777989/projects-what_are_templates.pdf index 5b0542d4..5353e02c 100644 Binary files a/_downloads/e459ceaf2fecdc2d90a41479eb777989/projects-what_are_templates.pdf and b/_downloads/e459ceaf2fecdc2d90a41479eb777989/projects-what_are_templates.pdf differ diff --git a/_downloads/e4bba0bad5b8b364b84a1dff5a090cd8/python_installation_execution-executing_pytask.pdf b/_downloads/e4bba0bad5b8b364b84a1dff5a090cd8/python_installation_execution-executing_pytask.pdf index 13192194..7840d318 100644 Binary files a/_downloads/e4bba0bad5b8b364b84a1dff5a090cd8/python_installation_execution-executing_pytask.pdf and b/_downloads/e4bba0bad5b8b364b84a1dff5a090cd8/python_installation_execution-executing_pytask.pdf differ diff --git a/_downloads/e57f785da689e76e22de44c7e95d151d/python_installation_execution-executing_pytest.pdf b/_downloads/e57f785da689e76e22de44c7e95d151d/python_installation_execution-executing_pytest.pdf index fd88c343..37f801df 100644 Binary files a/_downloads/e57f785da689e76e22de44c7e95d151d/python_installation_execution-executing_pytest.pdf and b/_downloads/e57f785da689e76e22de44c7e95d151d/python_installation_execution-executing_pytest.pdf differ diff --git a/_downloads/e738e5c4c7cb6626d110e165b864dac1/scientific_computing-calculations_on_arrays.pdf b/_downloads/e738e5c4c7cb6626d110e165b864dac1/scientific_computing-calculations_on_arrays.pdf index 0a1b19ac..991ecfc6 100644 Binary files a/_downloads/e738e5c4c7cb6626d110e165b864dac1/scientific_computing-calculations_on_arrays.pdf and b/_downloads/e738e5c4c7cb6626d110e165b864dac1/scientific_computing-calculations_on_arrays.pdf differ diff --git a/_downloads/eb76c8cf78f480f510d8e685f897a080/pandas-dataframes_and_series.pdf b/_downloads/eb76c8cf78f480f510d8e685f897a080/pandas-dataframes_and_series.pdf index 6c446dec..cdd4eeb4 100644 Binary files a/_downloads/eb76c8cf78f480f510d8e685f897a080/pandas-dataframes_and_series.pdf and b/_downloads/eb76c8cf78f480f510d8e685f897a080/pandas-dataframes_and_series.pdf differ diff --git a/_downloads/f35c8681367644c9662366746a03df79/software_engineering-naming.pdf b/_downloads/f35c8681367644c9662366746a03df79/software_engineering-naming.pdf index 8dfe825c..f6480369 100644 Binary files a/_downloads/f35c8681367644c9662366746a03df79/software_engineering-naming.pdf and b/_downloads/f35c8681367644c9662366746a03df79/software_engineering-naming.pdf differ diff --git a/_downloads/fa0fef36394d64b26fae2fe860a3d526/scientific_computing-broadcasting.pdf b/_downloads/fa0fef36394d64b26fae2fe860a3d526/scientific_computing-broadcasting.pdf index 9c3c0936..a9d5acf4 100644 Binary files a/_downloads/fa0fef36394d64b26fae2fe860a3d526/scientific_computing-broadcasting.pdf and b/_downloads/fa0fef36394d64b26fae2fe860a3d526/scientific_computing-broadcasting.pdf differ diff --git a/_sources/software_engineering/error_handling_intro/objectives_materials.ipynb b/_sources/software_engineering/error_handling_intro/objectives_materials.ipynb new file mode 100644 index 00000000..818fb8bc --- /dev/null +++ b/_sources/software_engineering/error_handling_intro/objectives_materials.ipynb @@ -0,0 +1,66 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Introduction to error handling \n", + "\n", + "## Learning Objectives\n", + "\n", + "After working through this topic, you should be able to:\n", + "\n", + "- Explain why error handling is important\n", + "\n", + "## Materials\n", + "\n", + "Here is the\n", + "[screencast](https://player.uni-bonn.educast.nrw/96b79d38-8313-4025-bfcb-66ccd649e507).\n", + "These are the [slides](software_engineering-error_handling_intro.pdf).\n", + "\n", + "\n", + "\n", + "## Quiz" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [ + "remove-input" + ] + }, + "outputs": [], + "source": [ + "content = {\n", + " \"What are benefits of good error handling\": {\n", + " \"You make fewer mistakes\": False,\n", + " \"You find mistakes earlier\": True,\n", + " \"You understand what went wrong immediately\": True,\n", + " \"Your code is more readable\": False,\n", + " },\n", + "}\n", + "\n", + "from epp_topics.quiz_utilities import display_quiz\n", + "\n", + "display_quiz(content)" + ] + } + ], + "metadata": { + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/_sources/software_engineering/raising_errors/objectives_materials.ipynb b/_sources/software_engineering/raising_errors/objectives_materials.ipynb new file mode 100644 index 00000000..d3699ec2 --- /dev/null +++ b/_sources/software_engineering/raising_errors/objectives_materials.ipynb @@ -0,0 +1,80 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# How to raise errors?\n", + "\n", + "## Learning Objectives\n", + "\n", + "After working through this topic, you should be able to:\n", + "\n", + "- Use the `raise` keyword to raise errors\n", + "- Decide when to use built-in vs. custom exceptions \n", + "- Define custom exceptions\n", + "- Explain the concept of `fail-functions`\n", + "\n", + "## Materials\n", + "\n", + "Here is the\n", + "[screencast](https://player.uni-bonn.educast.nrw/57b9f591-e18c-47aa-a2cf-5f66bf22846c).\n", + "These are the [slides](software_engineering-raising_errors.pdf).\n", + "\n", + "\n", + "## Quiz" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [ + "remove-input" + ] + }, + "outputs": [], + "source": [ + "content = {\n", + " \"How can you raise exceptions in Python?\": {\n", + " \"With the `raise` keyword\": True,\n", + " \"With the `throw` keyword\": False,\n", + " \"With the `except` keyword\": False,\n", + " \"With the `yield` keyword\": False,\n", + " },\n", + " \"What is the benefit of fail-functions?\": {\n", + " \"They tell you what is checked without cluttering the code\": True,\n", + " \"They let you re-use code for error handling\": True,\n", + " \"They are faster than raising exceptions\": False,\n", + " \"They force you to think about a good name for each check\": True,\n", + " },\n", + " \"What are benefits of custom exceptions\": {\n", + " \"They can be more explicit than the built-in exceptions\": True,\n", + " \"They are faster than built-in exceptions\": False,\n", + " \"They replace the need for good error messages\": False,\n", + " \"They show you are a good programme\": False,\n", + " },\n", + "}\n", + "\n", + "from epp_topics.quiz_utilities import display_quiz\n", + "\n", + "display_quiz(content)" + ] + } + ], + "metadata": { + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/_sources/software_engineering/which_errors_to_handle/objectives_materials.ipynb b/_sources/software_engineering/which_errors_to_handle/objectives_materials.ipynb new file mode 100644 index 00000000..7c1f7044 --- /dev/null +++ b/_sources/software_engineering/which_errors_to_handle/objectives_materials.ipynb @@ -0,0 +1,72 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Which errors to handle?\n", + "\n", + "## Learning Objectives\n", + "\n", + "After working through this topic, you should be able to:\n", + "\n", + "- Decide for which inputs you need error handling\n", + "- Explain when to use testing instead of error handling\n", + "- Decide where to do error handling\n", + "\n", + "## Materials\n", + "\n", + "Here is the\n", + "[screencast](https://player.uni-bonn.educast.nrw/b728a649-b661-48f7-b13f-d28f92eea888).\n", + "These are the [slides](software_engineering-which_errors_to_handle.pdf).\n", + "\n", + "\n", + "## Quiz" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [ + "remove-input" + ] + }, + "outputs": [], + "source": [ + "content = {\n", + " \"For which inputs of your functions should you do error handling?\": {\n", + " \"Those generated by other functions to make sure those functions work\": False,\n", + " \"Those passed in by a user\": True,\n", + " \"You should do error handling for all inputs of all functions\": False,\n", + " \"Those that use complex data structures\": False,\n", + " },\n", + " \"Where should you do error handling?\": {\n", + " \"As early as possible so users get early feedback\": True,\n", + " \"Right before you use the input\": False,\n", + " \"At the end of the function to check that the result is valid\": False,\n", + " },\n", + "}\n", + "\n", + "from epp_topics.quiz_utilities import display_quiz\n", + "\n", + "display_quiz(content)" + ] + } + ], + "metadata": { + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/_sources/software_engineering/worked_error_example/worked_example.ipynb b/_sources/software_engineering/worked_error_example/worked_example.ipynb new file mode 100644 index 00000000..1f9bb2fa --- /dev/null +++ b/_sources/software_engineering/worked_error_example/worked_example.ipynb @@ -0,0 +1,295 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Worked error handling example\n", + "\n", + "This notebook shows very thorough error handling for the functions \n", + "- `create_markdown_table`\n", + "- `convert_lod_to_dol`\n", + "- `convert_dol_to_lod`\n", + "\n", + "Such a level of error handling would be necessary if these functions are used by \n", + "a large group of users (e.g. if they are in a Python package). Whether you need this \n", + "level of error handling for functions that are only used by yourself in a single \n", + "project is debatable. But usually thorough error handling saves more time than it \n", + "costs. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def convert_lod_to_dol(lod):\n", + " \"\"\"Convert a list of dictionaries to a dictionary of lists.\n", + "\n", + " Args:\n", + " lod (list): List of dictionaries\n", + "\n", + " Returns:\n", + " dict: Dictionary of lists\n", + "\n", + " \"\"\"\n", + " _fail_if_not_list(lod)\n", + " _fail_if_list_of_wrong_types(lod)\n", + " _fail_if_list_of_dicts_with_different_keys(lod)\n", + "\n", + " keys = list(lod[0])\n", + " out = {}\n", + " for key in keys:\n", + " out[key] = [d[key] for d in lod]\n", + " return out\n", + "\n", + "\n", + "def convert_dol_to_lod(dol):\n", + " \"\"\"Convert a dictionary of lists to a list of dictionaries.\n", + "\n", + " Args:\n", + " dol (dict): Dictionary of lists\n", + "\n", + " Returns:\n", + " list: List of dictionaries\n", + "\n", + " \"\"\"\n", + " _fail_if_not_dict(dol)\n", + " _fail_if_dict_of_wrong_types(dol)\n", + " _fail_if_dict_of_lists_with_different_lengths(dol)\n", + "\n", + " keys = list(dol)\n", + " n_rows = len(dol[keys[0]])\n", + " out = []\n", + " for row in range(n_rows):\n", + " out.append({key: dol[key][row] for key in keys})\n", + " return out\n", + "\n", + "\n", + "def create_markdown_table(data):\n", + " \"\"\"Create a markdown table from a list of dictionaries or a dictionary of lists.\n", + "\n", + " Args:\n", + " data (list or dict): List of dictionaries or dictionary of lists\n", + "\n", + " Returns:\n", + " str: The Markdown table\n", + "\n", + " \"\"\"\n", + " _fail_if_neither_dict_nor_list(data)\n", + " if isinstance(data, dict):\n", + " lod = convert_dol_to_lod(data)\n", + " else:\n", + " _fail_if_list_of_wrong_types(data)\n", + " _fail_if_list_of_dicts_with_different_keys(data)\n", + " lod = data\n", + "\n", + " keys = list(lod[0])\n", + "\n", + " lines = [\n", + " _create_header(keys),\n", + " _create_separator(len(keys)),\n", + " ]\n", + "\n", + " for row in lod:\n", + " lines.append(_create_data_row(row))\n", + "\n", + " return \"\\n\".join(lines)\n", + "\n", + "\n", + "def _create_header(keys):\n", + " \"\"\"Create a header for a Markdown table.\"\"\"\n", + " header = \"|\"\n", + " for key in keys:\n", + " header += f\" {key} |\"\n", + " return header\n", + "\n", + "\n", + "def _create_separator(n_cols):\n", + " separator = \"|\"\n", + " for _ in range(n_cols):\n", + " separator += \" ------ |\"\n", + " return separator\n", + "\n", + "\n", + "def _create_data_row(row_dict):\n", + " \"\"\"Create a row of data for a Markdown table.\"\"\"\n", + " row_string = \"|\"\n", + " for key in row_dict:\n", + " row_string += f\" {row_dict[key]} |\"\n", + " return row_string\n", + "\n", + "\n", + "def _fail_if_neither_dict_nor_list(data):\n", + " if not isinstance(data, list | dict):\n", + " msg = f\"data must be a list of dicts or a dictionary of lists. Not {type(data)}\"\n", + " raise TypeError(\n", + " msg,\n", + " )\n", + "\n", + "\n", + "def _fail_if_not_list(data):\n", + " if not isinstance(data, list):\n", + " raise TypeError(\"data must be a list of dicts\")\n", + "\n", + "\n", + "def _fail_if_not_dict(data):\n", + " if not isinstance(data, dict):\n", + " raise TypeError(\"data must be a dictionary of lists\")\n", + "\n", + "\n", + "class NonTabularDataError(Exception):\n", + " \"\"\"Raised when data has the correct type but is not tabular.\"\"\"\n", + "\n", + "\n", + "\n", + "def _fail_if_list_of_wrong_types(data):\n", + " invalid_rows = []\n", + " for i, row in enumerate(data):\n", + " if not isinstance(row, dict):\n", + " invalid_rows.append(i)\n", + "\n", + " if invalid_rows:\n", + " report = \"The following rows are not dictionaries:\\n\"\n", + " for i in invalid_rows:\n", + " report += f\" Row {i} has type {type(data[i])}\\n\"\n", + " raise TypeError(report)\n", + "\n", + "\n", + "def _fail_if_list_of_dicts_with_different_keys(data):\n", + " keys = set(data[0].keys())\n", + " invalid_rows = []\n", + " for i, row in enumerate(data):\n", + " if set(row.keys()) != keys:\n", + " invalid_rows.append(i)\n", + "\n", + " if invalid_rows:\n", + " report = f\"Valid keys are: {keys}\\n\\nThe following rows have invalid keys:\\n\"\n", + "\n", + " for i in invalid_rows:\n", + " report += f\" Row {i}: {[k for k in list(data[i]) if k not in keys]}\\n\"\n", + " raise NonTabularDataError(report)\n", + "\n", + "\n", + "def _fail_if_dict_of_wrong_types(data):\n", + " invalid_cols = []\n", + " for key in data:\n", + " if not isinstance(data[key], list):\n", + " invalid_cols.append(key)\n", + "\n", + " if invalid_cols:\n", + " report = \"The following dict entries are not lists:\\n\"\n", + " for key in invalid_cols:\n", + " report += f\" Key '{key}' has a value of type {type(data[key])}\\n\"\n", + " raise TypeError(report)\n", + "\n", + "\n", + "def _fail_if_dict_of_lists_with_different_lengths(data):\n", + " length = len(data[next(iter(data.keys()))])\n", + " invalid_cols = []\n", + " for key in data:\n", + " if len(data[key]) != length:\n", + " invalid_cols.append(key)\n", + "\n", + " if invalid_cols:\n", + " report = (\n", + " f\"The correct length is {length}. The following dict entries have invalid \"\n", + " \"lengths:\\n\"\n", + " )\n", + " for key in invalid_cols:\n", + " report += f\" Key '{key}' has a value with length {len(data[key])}\\n\"\n", + " raise NonTabularDataError(report)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Recipe for good error handling\n", + "\n", + "1. Identify which inputs can potentially cause probles. Those are the inputs that:\n", + " - come directly from a user\n", + " - have not been checked in other functions \n", + "2. List everything that could go wrong with those inputs. Start with those that are \n", + "very easy to check (e.g. is data a list or dict) and continue with more specific ones \n", + "(does the dict have the right keys).\n", + "3. Write one `_fail ...` function for each of the conditions in the previous step \n", + "4. Call the `_fail ...` functions at the earliest possible moment in your code\n", + "5. Call your functions with invalid inputs and read the error messages. Are they\n", + "as helpful as they can be? Do they show too much or too little output? Try to maximize \n", + "the information content without showing anything irrelevant. \n", + "\n", + "\n", + "## Calling the functions with invalid inputs\n", + "\n", + "Call `create_markdown_table` with the inputs below to see the error messages" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "invalid_lod = [\n", + " {\"name\", \"ProgrammingGod42\"},\n", + " {\"name\": \"Kim\", \"github_name\": \"CodingKim\"},\n", + " [\"Jesse\", \"JavascriptJesse\"],\n", + "]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "invalid_lod = [\n", + " {\"name\": \"Robin\", \"github_name\": \"ProgrammingGod42\"},\n", + " {\"name\": \"Kim\", \"github_name\": \"CodingKim\"},\n", + " {\"name\": \"Jesse\", \"github_nameeeeeeeeee\": \"JavascriptJesse\"},\n", + "]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "invalid_dol = {\n", + " \"name\": (\"Robin\", \"Kim\", \"Jesse\"),\n", + " \"github_name\": [\"ProgrammingGod42\", \"CodingKim\", \"JavascriptJesse\"],\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "invalid_dol = {\n", + " \"name\": [\"Robin\", \"Kim\", \"Jesse\"],\n", + " \"github_name\": [\"ProgrammingGod42\", \"CodingKim\"],\n", + "}" + ] + } + ], + "metadata": { + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/background/content_objectives.html b/background/content_objectives.html index 95ba5b0d..9581073a 100644 --- a/background/content_objectives.html +++ b/background/content_objectives.html @@ -275,6 +275,10 @@
After working through this topic, you should be able to:
+Explain why error handling is important
Here is the +screencast. +These are the slides.
+