Skip to main content

A flake8 plugin to lint pandas in an opinionated way

Project description

pandas-vet

Build Status PyPI - License

PyPI PyPI - Status PyPI - Downloads

Conda Version Conda Downloads

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

It began as a project during the PyCascades 2019 sprints.

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!".

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.

Installation

pandas-vet is a plugin for flake8. If you don't have flake8 already, it will install automatically when you install pandas-vet.

The plugin is on PyPI and can be installed with:

pip install pandas-vet

It can also be installed with conda:

conda install -c conda-forge pandas-vet

pandas-vet is tested under Python 3.5 and 3.6 and should work with later versions as well.

Usage

Once installed successfully in an environment that also has flake8 installed, pandas-vet should run whenever flake8 is run.

$ flake8 ...

See the flake8 docs for more information.

For a full list of implemented warnings, see the list below.

Contributing

pandas-vet is still in the very early stages. Contributions are welcome from the community on code, tests, docs, and just about anything else.

Code of Conduct

Because this project started during the PyCascades 2019 sprints, we adopt the PyCascades minimal expectation that we "Be excellent to each another". Beyond that, we follow the Python Software Foundation's Community Code of Conduct.

Steps to contributing

  1. Please submit an issue (or draft PR) first describing the types of changes you'd like to implement.

  2. Fork the repo and create a new branch for your enhancement/fix.

  3. Write code, docs, etc.

  4. We use pytest and flake8 to validate our codebase. The TravisCI integration will complain on pull requests if there are any failing tests or lint violations. To check these locally, run the following commands:

pytest tests
flake8 pandas_vet setup.py tests --exclude tests/data
  1. Push to your forked repo.

  2. Submit pull request to the parent repo from your branch. Be sure to write a clear message and reference the Issue # that relates to your pull request.

  3. Feel good about giving back to open source projects.

How to add a check to the linter

  1. Write tests. At a minimum, you should have test cases where the linter should catch "bad" pandas and test cases where the linter should allow "good" pandas.

  2. Write your check function in /pandas-vet/__init__.py.

  3. Run flake8 and pytest on the linter itself (see Steps to contributing)

Contributors

PyCascades 2019 sprints team

Other awesome contributors

  • Earl Clark
  • Leandro Leites

List of warnings

PD001: pandas should always be imported as 'import pandas as pd'

PD002: 'inplace = True' should be avoided; it has inconsistent behavior

PD003: '.isna' is preferred to '.isnull'; functionality is equivalent

PD004: '.notna' is preferred to '.notnull'; functionality is equivalent

PD005: Use arithmetic operator instead of method

PD006: Use comparison operator instead of method

PD007: '.ix' is deprecated; use more explicit '.loc' or '.iloc'

PD008: Use '.loc' instead of '.at'. If speed is important, use numpy.

PD009: Use '.iloc' instead of '.iat'. If speed is important, use numpy.

PD010 '.pivot_table' is preferred to '.pivot' or '.unstack'; provides same functionality

PD011 Use '.array' or '.to_array()' instead of '.values'; 'values' is ambiguous

PDO12 '.read_csv' is preferred to '.read_table'; provides same functionality

PD013 '.melt' is preferred to '.stack'; provides same functionality

PD015 Use '.merge' method instead of 'pd.merge' function. They have equivalent functionality.

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-0.2.1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

pandas_vet-0.2.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file pandas-vet-0.2.1.tar.gz.

File metadata

  • Download URL: pandas-vet-0.2.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for pandas-vet-0.2.1.tar.gz
Algorithm Hash digest
SHA256 f4e32167a948bc8553c15dd5ae7d4de2651f8cc3d7a370de358e9c061197c033
MD5 0e8cefff776ae842dc0c1d4786ca82fc
BLAKE2b-256 8f1f303c087960b43c4abc05a9a4b44b7e3d1619ab9bd35711686a7fe515b9b9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pandas_vet-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for pandas_vet-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 983b66acd81363be8a520b57f2aa6b45e29dfc91bab9269b8dd3db389ae7de2b
MD5 adc53bb0d65bb16454ba91538bf8fa9f
BLAKE2b-256 2153d031fd623fde85f554c73d87c431ad4cf5d929d89c1cd728ab5e4d145a52

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