3 Writing robust code and error handling
This chapter covers
- Types of errors in Python
- How to effectively handle exceptions
- Restricting function input data types
- Making your code cleaner
In the last chapter, we discussed using source control to make it easier to track code changes and collaborate with others. As we discussed, source control is a key software engineering aspect that is incredibly useful for data scientists. Building on this foundation, we will delve further into applying software engineering concepts to data science in this chapter by discussing how to write robust code and handle errors. Suppose you’re a data scientist working on the customer churn model we discussed in the preceding chapters. While being able to easily share your code with others via source control is great, it can also be difficult to dissect someone else’s code. Making your code easy-to-read is a crucial aspect to both making it easier to collaborate with others on the same codebase, as well as making your code more maintainable in the future. One example of clean code is being more explicit about the inputs and outputs of functions (such as the data types), which is an area we’ll tackle in this chapter.