Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Filter by Categories
About Article
Analyze Data
Archive
Best Practices
Better Outputs
Blog
Code Optimization
Code Quality
Command Line
Daily tips
Dashboard
Data Analysis & Manipulation
Data Engineer
Data Visualization
DataFrame
Delta Lake
DevOps
DuckDB
Environment Management
Feature Engineer
Git
Jupyter Notebook
LLM
LLM
Machine Learning
Machine Learning
Machine Learning & AI
Manage Data
MLOps
Natural Language Processing
NumPy
Pandas
Polars
PySpark
Python Tips
Python Utilities
Python Utilities
Scrape Data
SQL
Testing
Time Series
Tools
Visualization
Visualization & Reporting
Workflow & Automation
Workflow Automation

Testing

pytest-sugar: Show the Failures and Errors Instantly With a Progress Bar

It can be frustrating to wait for a lot of tests to run before knowing the status of the tests. If you want to instantly see the failures and errors with a progress bar, use pytest-sugar.

pytest-sugar is a plugin for pytest. The code above shows how the outputs will look like when running pytest.

Link to pytest-sugar.

Link to previous tips on testing in Python.
Favorite

pytest-sugar: Show the Failures and Errors Instantly With a Progress Bar Read More »

DeepDiff Find Deep Differences of Python Objects

When testing the outputs of your functions, it can be frustrated to see your tests fail because of something you don’t care too much about such as:

order of items in a list

different ways to specify the same thing such as abbreviation

exact value up to the last decimal point, etc

Is there a way that you can exclude certain parts of the object from the comparison? That is when DeepDiff comes in handy.

Link to DeepDiff.

Link to my previous tips on testing.
Favorite

DeepDiff Find Deep Differences of Python Objects Read More »

pytest: Don’t Assume. Test your Python Code

When working on a data science project, don’t assume that the output will be what you expect. Test your assumption. The easiest way to do that in Python is pytest.
For example, in the code above, I use pytest to test my assumption about the output of the text. When running pytest file_name.py, pytest will run the functions that start with test_.
By running the test, I know where can my function goes wrong.
Check out other examples in my article about pytest.Favorite

pytest: Don’t Assume. Test your Python Code Read More »

Pytest Fixtures: Use the same data for different tests

Sometimes, you might want to use the same data to test different functions. If you are using pytest, use pytest fixtures to provide data to different test functions instead.
In the code above, I used the decorator @pytest.fixture to create the data I want to use many times.
Have this data as the input for any test function that uses this data!Favorite

Pytest Fixtures: Use the same data for different tests Read More »

Pytest repeat

It is a good practice to test your functions to make sure they work as expected, but sometimes you need to test 100 times until you found the rare cases when the test fails. That is when pytest-repeat comes in handy.
Yesterday, I tested with 100 instances and found 2 failed tests! I’m glad that I didn’t settle down for 10 passed tests. You can find the doc for pytest-repeat hereFavorite

Pytest repeat Read More »

Introduction to Schema: A Python Libary to Validate your Data

Your code might work with data at a certain state but might not work if your data changes. How do you detect the change in data before running into errors or encounter the drop in your model performance? That is when Schema comes in handy.
Below is the code snippet I used to validate the datatypes and the range of the values in a column. If this is what you are looking for, check out my article on how to use Schema here.Favorite

Introduction to Schema: A Python Libary to Validate your Data Read More »

0
    0
    Your Cart
    Your cart is empty
    Scroll to Top

    Work with Khuyen Tran

    Work with Khuyen Tran