RUVIDEO
Поделитесь видео 🙏

Python Tutorial: Why unit test?

Want to learn more? Take the full course at https://learn.datacamp.com/courses/unit-testing-for-data-science-in-python at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.

---
Hello and welcome to Unit Testing for Data Science in Python! My name is Dibya. I am a Test Automation Engineer and I will be your instructor for this course.

Consider this question. Suppose we have just implemented a Python function. How can we test whether our implementation is correct?

The easiest way is to open an interpreter, test the function on a few arguments and check whether the return value is correct. If correct, we can accept the implementation and move on. Right?

While testing on the interpreter is easy, it is actually very inefficient. This will become clear if we think about the big picture of a function's life cycle in a data science project.

The life cycle of a function typically looks like this.

We implement the function and then test it. If the tests pass, we accept the implementation.

If the tests fail, we fix any bugs that we found and test again.

Later, we might get a new feature request or we may be asked to refactor the function.

So we implement the new feature or refactor the code, and then test it again.

Alternatively, someone might discover a previously unseen bug. In that case, we fix that bug and test again.

Notice how many times a function needs to be tested during the life cycle. Every time we modify the function, either to fix bugs or to implement new features, we have to test it.

If the project continues for a few years, we might be testing the function about a hundred times, maybe more.

Let's look at an example function. It's called row_to_list(). It takes a single argument, which is a Python string.

The string is a single row in a data file which contains data on housing area and market price of the house.

The string contains the housing area in square feet, followed by a single tab, followed by the housing price in dollars and ending with a newline character.

If the string follows this format, the function returns a list of length 2, containing the housing area and the housing price.

But this data file is not clean, and some rows in this data file do not follow this format. The third row has missing area, while the penultimate row is missing the tab between the area and price. For these invalid rows, the function should return None.

To test this function, we will have to try all the arguments that we listed and check if the function returns the correct value.

Remembering that a function needs to be tested about 100 times in its life cycle, and assuming it takes 5 minutes to test each time, we will spend 8 hours just testing this function on the interpreter.

Unit tests automate this repetitive and tedious testing process. Unit tests will reduce the testing time over the life cycle of a single function to 1 hour instead of 8.

Now imagine how much time we would save when we unit test all the functions in a project!

This makes unit testing a must-have skill for productive data scientists.

This course will teach you how to write unit tests. We have created an example data science project which predicts prices from the housing area using linear regression, as we can see in the plot.

The complete code for this project, including actual implementations for functions like row_to_list(), is available in a public GitHub repository. We will share the link to the repository at the end of the course.

Here is the folder structure of this project.

During this course, we are going to write a complete unit test suite for this example project. It's going to be fun and exciting.

This will prepare you to write unit tests for your own projects.

Sounds good? Then let's get started by practicing the concepts covered in this lesson.

#Python #PythonTutorial #DataCamp #Unit #Testing #DataScience

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Python Tutorial: Why unit test?», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.