Skip to main content

pandas-stubs: Public type stubs for pandas

PyPI Latest Release Conda Latest Release Package Status License Downloads Gitter Powered by NumFOCUS Code style: black Imports: isort

What is it?

These are public type stubs for pandas, following the convention of providing stubs in a separate package, as specified in PEP 561. The stubs cover the most typical use cases of pandas. In general, these stubs are narrower than what is possibly allowed by pandas, but follow a convention of suggesting best recommended practices for using pandas.

The stubs are likely incomplete in terms of covering the published API of pandas.

The stubs are tested with mypy and pyright and are currently shipped with the Visual Studio Code extension pylance.

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[Any, Any], Series[Any]]"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

And, if you use pyright:

pyright round.py

you get the following error message:

 round.py:6:40 - error: Argument of type "DataFrame" cannot be assigned to parameter "decimals" of type "int | Dict[Unknown, Unknown] | Series[Unknown]" in function "round"
    Type "DataFrame" cannot be assigned to type "int | Dict[Unknown, Unknown] | Series[Unknown]"
      "DataFrame" is incompatible with "int"
      "DataFrame" is incompatible with "Dict[Unknown, Unknown]"
      "DataFrame" is incompatible with "Series[Unknown]" (reportGeneralTypeIssues)

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

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

Version Numbering Convention

The version number x.y.z.yymmdd corresponds to a test done with pandas version x.y.z, with the stubs released on the date mm/yy/dd. It is anticipated that the stubs will be released more frequently than pandas as the stubs are expected to evolve due to more public visibility.

Where to get it

The source code is currently hosted on GitHub at: https://github.com/pandas-dev/pandas-stubs

Binary installers for the latest released version are available at the Python Package Index (PyPI) and on conda-forge.

# conda
conda install pandas-stubs
# or PyPI
pip install pandas-stubs

Dependencies

Installation from sources

  • Make sure you have python >= 3.8 installed.
  • Install poetry
# conda
conda install poetry
# or PyPI
pip install poetry
  • Install the project dependencies
poetry update -vvv
  • Build and install the distribution
poetry run poe build_dist
poetry run poe install_dist

License

BSD 3

Documentation

Documentation is a work-in-progress.

Background

These stubs are the result of a strategic effort lead by the core pandas team to integrate Microsoft type stub repository together with the VirtusLabs pandas_stubs repository.

These stubs were initially forked from the Microsoft project https://github.com/microsoft/python-type-stubs as of this commit.

We are indebted to Microsoft and that project for the initial set of public type stubs. We are also grateful for the original pandas-stubs project at https://github.com/VirtusLab/pandas-stubs that created the framework for testing the stubs.

Getting help

Ask questions and report issues on the pandas-stubs repository.

Discussion and Development

Most development discussions take place on GitHub in the pandas-stubs repository. Further, the pandas-dev mailing list can also be used for specialized discussions or design issues, and a Gitter channel is available for quick development related questions.

Contributing to pandas-stubs

All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome. See https://github.com/pandas-dev/pandas-stubs/tree/main/docs/ for instructions.

Metadata

Release files for pandas-stubs 1.4.4.220912

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.4.4.220912
File Size Uploaded Provenance Actions
pandas-stubs-1.4.4.220912.tar.gz 85.1 kB Without provenance Details for pandas-stubs-1.4.4.220912.tar.gz

Built distribution (wheel)

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

Total release size: 220.7 kB

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

Download URL pandas-stubs-1.4.4.220912.tar.gz
Size 85.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5920ffd5a09e49bfc987c4400056ffe6d9e9448c821e64c2c47a18345f8b00d7
BLAKE2b-256 checksum
How to use checksums
028f82ff62cef58f37dd1c2dbbefe17dc37ce60ba2355b7855f84741020383fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

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

Download URL pandas_stubs-1.4.4.220912-py3-none-any.whl
Size 135.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f5569bdeb57d07a8c4c6c8ccabb438155ec0c4c346bc6cf562c2fab7085e3f6
BLAKE2b-256 checksum
How to use checksums
b9f5df7f7a9b1c7567710b1f4f7cd3db4928ac10c662d4be7a632f4e8e6d9db0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Security for pandas-stubs 1.4.4.220912

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.4.4.220912 This release

2 release files No provenance

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