Skip to main content

A flake8 plugin to lint pandas in an opinionated way.

Project description

pandas-vet

pandas-vet is a plugin for flake8 that provides opinionated linting for pandas code.

docs

Test and lint Code style: black PyPI - License

PyPI PyPI - Status PyPI - Downloads

Conda Version Conda Downloads

Basic usage

Take the following script, drop_column.py, which contains valid pandas code:

# 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.

$ 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.

# 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 page of the documentation.

Motivation

Starting with pandas 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's talk at PyCascades 2019, "Lint your code responsibly!". The package was largely developed at the PyCascades 2019 sprints.

Many of the opinions stem from Ted Petrou's excellent Minimally Sufficient Pandas. Other ideas are drawn from pandas docs or elsewhere. The Pandas in Black and White flashcards have a lot of the same opinions too.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pandas_vet-2023.8.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

pandas_vet-2023.8.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file pandas_vet-2023.8.0.tar.gz.

File metadata

  • Download URL: pandas_vet-2023.8.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.24.0

File hashes

Hashes for pandas_vet-2023.8.0.tar.gz
Algorithm Hash digest
SHA256 1531505c7d9743b370949e97e5c38c0a69682efe02d539b355629eaf32e5a0d0
MD5 9d87efc593d6d45854414c5811f3ad1a
BLAKE2b-256 64f69be63acefff178e40c26381c57200574bb3e75983890461598050e89070d

See more details on using hashes here.

File details

Details for the file pandas_vet-2023.8.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pandas_vet-2023.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4d7ae9a1d90ff01683d5e3382960b793d8990cee1ec2d3dc2c021a0c7d454b4a
MD5 4bed7496dbf1d7d0b51f19b2e947a8f5
BLAKE2b-256 17dbfddbd54f8ca008a7bc46b486a6ab6faefc3232d77b56a241403204bf7ad9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page