https://github.com/deppen8/pandas-vet
A plugin for Flake8 that checks pandas code
https://github.com/deppen8/pandas-vet
flake8 flake8-plugin linter pandas python
Last synced: 2 months ago
JSON representation
A plugin for Flake8 that checks pandas code
- Host: GitHub
- URL: https://github.com/deppen8/pandas-vet
- Owner: deppen8
- License: mit
- Created: 2019-02-25T05:19:51.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2023-08-11T17:41:30.000Z (about 2 years ago)
- Last Synced: 2025-04-13T19:48:42.648Z (7 months ago)
- Topics: flake8, flake8-plugin, linter, pandas, python
- Language: Python
- Homepage: https://pandas-vet.readthedocs.io
- Size: 169 KB
- Stars: 170
- Watchers: 4
- Forks: 18
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-data-analysis - PandasVet - Code style validator for Pandas (similar to ESLint). (🐍 Python / Useful Python Tools for Data Analysis)
- awesome-data-analysis - PandasVet - Code style validator for Pandas (similar to ESLint). (🐍 Python / Useful Python Tools for Data Analysis)
- best-of-python-dev - GitHub - 22% open · ⏱️ 11.08.2023): (Linters & Style Checkers)
- awesome-flake8-extensions - pandas-vet - Plugin that provides opinionated linting for Pandas code. (Library-specific checks)
README
# pandas-vet
`pandas-vet` is a plugin for `flake8` that provides opinionated linting for `pandas` code.
[](https://pandas-vet.readthedocs.io/en/latest/?badge=stable)
[](https://github.com/deppen8/pandas-vet/actions/workflows/testing.yml)
[](https://github.com/psf/black)
[](https://github.com/deppen8/pandas-vet/blob/main/LICENSE)
[](https://pypi.org/project/pandas-vet/)
[](https://pypi.org/project/pandas-vet/)
[](https://pypi.org/project/pandas-vet/)
[](https://anaconda.org/conda-forge/pandas-vet)
[](https://anaconda.org/conda-forge/pandas-vet)
## Basic usage
Take the following script, `drop_column.py`, which contains valid pandas code:
```python
# drop_column.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)
```
With `pandas-vet` installed, if we run Flake8 on this script, we will see three warnings raised.
```bash
$ flake8 drop_column.py
./drop_column.py:2:1: PD001 pandas should always be imported as 'import pandas as pd'
./drop_column.py:4:1: PD901 'df' is a bad variable name. Be kinder to your future self.
./drop_column.py:7:1: PD002 'inplace = True' should be avoided; it has inconsistent behavior
```
We can use these to improve the code.
```python
# pandastic_drop_column.py
import pandas as pd
ab_dataset = pd.DataFrame({
'col_a': [i for i in range(20)],
'col_b': [j for j in range(20, 40)]
})
a_dataset = ab_dataset.drop(columns='col_b')
```
For a full list, see the [Supported warnings](https://pandas-vet.readthedocs.io/en/stable/guides/warnings.html) page of the documentation.
## Motivation
Starting with [pandas](https://pandas.pydata.org/) can be daunting. The usual internet help sites are littered with different ways to do the same thing and some features that the pandas docs themselves discourage live on in the API. `pandas-vet` is (hopefully) a way to help make pandas a little more friendly for newcomers by taking some opinionated stances about pandas best practices. It is designed to help users reduce the pandas universe.
The idea to create a linter was sparked by [Ania Kapuścińska](https://twitter.com/lambdanis)'s talk at PyCascades 2019, ["Lint your code responsibly!"](https://youtu.be/hAnCiTpxXPg?t=21814). The package was largely developed at the PyCascades 2019 sprints.
Many of the opinions stem from [Ted Petrou's](https://twitter.com/TedPetrou) excellent [Minimally Sufficient Pandas](https://medium.com/dunder-data/minimally-sufficient-pandas-a8e67f2a2428). Other ideas are drawn from pandas docs or elsewhere. The [Pandas in Black and White](https://deppen8.github.io/pandas-bw/) flashcards have a lot of the same opinions too.