pandas-vet

2023.8.2 · active · verified Thu Apr 16

pandas-vet is a flake8 plugin that provides opinionated linting for pandas code. It helps enforce best practices and reduce common footguns when working with pandas DataFrames and Series by flagging problematic patterns and encouraging more robust and readable code. It is actively maintained and currently at version 2023.8.2, with a regular release cadence.

Common errors

Warnings

Install

Imports

Quickstart

After installing `pandas-vet`, it automatically integrates with `flake8`. To use it, simply run `flake8` on your Python files. The example demonstrates common `pandas-vet` warnings (PD001, PD901, PD002) when run against a sample script.

# my_pandas_script.py
import pandas

df = pandas.DataFrame({
    'col_a': [i for i in range(20)],
    'col_b': [j for j in range(20, 40)]
})

df.drop(columns='col_b', inplace=True)

# Run flake8 from your terminal in the same directory
# flake8 my_pandas_script.py

# Expected output (may vary slightly based on flake8 version):
# my_pandas_script.py:2:1: PD001 pandas should always be imported as 'import pandas as pd'
# my_pandas_script.py:4:1: PD901 'df' is a bad variable name. Be kinder to your future self.
# my_pandas_script.py:7:1: PD002 'inplace = True' should be avoided; it has inconsistent behavior.

view raw JSON →