Skip to main content

Logo

Pandas Stubs

Collection of pandas stub files initially generated using stubgen, fixed when necessary and then partially completed.

CI PyPi version PyPI Downloads Conda Downloads Python support License
VirtusLab PyPI package PyPI download month PyPI download month PyPI pyversions GitHub license

Motivation

Provide rudimentary coverage of pandas code by static type checking, to alleviate problems mentioned in the following issues 14468, 26766. This approach was taken to achieve accelerated development - compared to refactoring existing Pandas codebase creating stub files is relatively uninhibited.

Due to extensive pandas API, quality of the proposed annotations is, for the most part, not suitable for integration into original codebase, but they can be very useful as a way of achieving some type safety during development.

Installation

The easiest way is using PyPI. This will add .pyi files to pandas package location, which will be removed when uninstalling:

pip install pandas-stubs

Another way to install is using Conda:

conda install -c conda-forge pandas-stubs 

Alternatively, if you want a cleaner PYTHONPATH or wish to modify the annotations, manual options are:

  • cloning the repository along with the files, or
  • including it as a submodule to your project repository,

and then configuring a type checker with the correct paths.

Usage

Let’s take this example piece of code in file round.py

import pandas as pd

decimals = pd.DataFrame({'TSLA': 2, 'AMZN': 1})
prices = pd.DataFrame(data={'date': ['2021-08-13', '2021-08-07', '2021-08-21'],
                            'TSLA': [720.13, 716.22, 731.22], 'AMZN': [3316.50, 3200.50, 3100.23]})
rounded_prices = prices.round(decimals=decimals)

Mypy won't see any issues with that, but after installing pandas-stubs and running it again:

mypy round.py

we get the following error message:

round.py:6: error: Argument "decimals" to "round" of "DataFrame" has incompatible type "DataFrame"; expected "Union[int, Dict[Union[int, str], int], Series]"

And after confirming with the docs we can fix the code:

decimals = pd.Series({'TSLA': 2, 'AMZN': 1})

Version Compatibility

The aim of the current release is to cover the most common parts of the 1.2.0 API, however it can provide partial functionality for other version as well. Future versions will cover new Pandas releases.

Versioning

The versions follow a pattern MAJOR.MINOR.PATCH.STUB_VERSION where the first three parts correspond to a specific pandas API version, while STUB_VERSION is used to distinguish between the versions of the stubs themselves.

Type checkers

As of now mypy is the only type checker the stubs were tested with.

Development

Testing using tox

Tox will automatically run all types of tests mentioned further. It will create isolated temporary environments for each declared version of Python and install pandas-stubs like it would normally be installed when using pip or conda.

Usage is as simple as:

tox

Last few lines of the output should look like this (assuming all Python versions are available):

  pep8: commands succeeded
  py36: commands succeeded
  py37: commands succeeded
  py38: commands succeeded
  py39: commands succeeded

Partial testing

Test the stub files internal consistency:

mypy --config-file mypy.ini third_party/3/pandas

Test the stub files against actual code examples (this will use the stubs from the third_party/3/pandas dir):

mypy --config-file mypy.ini tests/snippets

Test the installed stub files against actual code examples. You'll need to install the library beforehand - the .pyi files from your env will be used:

mypy --config-file mypy_env.ini tests/snippets

Test if the code examples work, when actually ran with pandas:

pytests tests/snippets

Disclaimer

This project provides additional functionality for pandas library. Pandas is available under it's own license.

This project is not owned, endorsed, or sponsored by any of AQR Capital Management, NumFOCUS, LLC, Lambda Foundry, Inc. and PyData Development Team.

Release files for pandas-stubs 1.2.0.58

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pandas-stubs 1.2.0.58
File Size Uploaded
pandas-stubs-1.2.0.58.tar.gz 95.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pandas-stubs 1.2.0.58
File Interpreter ABI Platform
pandas_stubs-1.2.0.58-py3-none-any.whl Python 3 none any Details

Total release size: 258.4 kB

Release files / pandas-stubs-1.2.0.58.tar.gz

Download URL pandas-stubs-1.2.0.58.tar.gz
Size 95.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f0e0e70887f85a5895887bdf7cee34e3881d5c7f95457304e8a9287401ae4be8
BLAKE2b-256 checksum
How to use checksums
56a78f9a856f5cc726f28f6d2c59c7be01d09b774ca26c06384b8260bf1a7d2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.10

Release files / pandas_stubs-1.2.0.58-py3-none-any.whl

Download URL pandas_stubs-1.2.0.58-py3-none-any.whl
Size 162.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4497e8ce506e29b202955ebc653d181833a9745076bc911c2111e09095988440
BLAKE2b-256 checksum
How to use checksums
750b291e84a3bacf1a3043dcac7a403e9a92747a127e5a87aaaaf64697cdafd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.10

Release history Release notifications | RSS feed

This release

1.2.0.58 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page