Registry / testing / pandas-vet

pandas-vet

JSON →
library2023.8.2pypypiunverified

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.

pip install pandas-vet
INSTALL
IMPORT
SIG · PANDAS-VET
P
pandas-vet
testingpythonv2023.8.2
Install
1.9s avg
Import
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2023.8.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.9MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.9s · import 0.000s · 20MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pandas-vet as a flake8 plugin
No direct import needed in user code; flake8 automatically discovers installed plugins.
pandas-vet is a flake8 plugin and works by being installed in the same environment as flake8. You do not import it directly into your Python scripts.

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.
Debug
Known issues
breakingUsing `inplace=True` is strongly discouraged by pandas-vet (PD002) and increasingly by the pandas core team. It can lead to inconsistent behavior, prevent method chaining, and doesn't always provide performance benefits.
fix
Rewrite operations to return a new DataFrame/Series instead of modifying in-place. For example, `df = df.drop(columns='col_b')` instead of `df.drop(columns='col_b', inplace=True)`.
affects: All versions of pandas, pandas-vet v0.1.0+
deprecatedAccessing the underlying NumPy array using the `.values` attribute (PD011) is ambiguous and deprecated in pandas.
fix
Use `.to_numpy()` for a NumPy array or `.array` for a pandas ExtensionArray to explicitly state the desired return type. Example: `df.to_numpy()` instead of `df.values`.
affects: pandas-vet v0.2.0+
gotchapandas-vet enforces opinionated import styles and variable names. For example, not importing pandas as `import pandas as pd` (PD001) or naming a DataFrame `df` (PD901) will trigger warnings.
fix
Always use `import pandas as pd`. For DataFrames, use more descriptive variable names than `df`. If you disagree with `PD901`, it can be disabled by passing `--ignore PD901` to flake8 or by configuring your flake8 settings.
affects: PD001: pandas-vet v0.1.0+; PD901: pandas-vet v0.2.0+
deprecatedOlder methods like `.isnull` (PD003), `.notnull` (PD004), `.ix` (PD007), `.pivot` or `.unstack` (PD010), `.read_table` (PD012), and `.stack` (PD013) are flagged by pandas-vet in favor of their more explicit or recommended counterparts.
fix
Use `.isna`, `.notna`, `.loc` or `.iloc`, `.pivot_table`, `.read_csv`, and `.melt` respectively.
affects: pandas-vet v0.1.0+, v0.2.0+
Upgrade
Version history
2023.8.2latest on PyPI · released Aug 11, 2023
Audit
Dependencies
flake8requiredpandas-vet is a plugin for flake8 and requires it to run. If flake8 is not installed, it will be installed automatically with pandas-vet.
Agent activity
14 hits · last 30 days
node
12
Resources
pandas-vet — pip install pandas-vet · libregistry