• Stars
    star
    117
  • Rank 291,070 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 4 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pandas type stubs. Helps you type-check your code.

Logo

Pandas Stubs

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

Announcement - pandas_stubs moved! This repository is now deprecated!

As of July 2022 pandas_stubs package is no longer sourced from here but instead from a repository owned and maintained by the core pandas team: https://github.com/pandas-dev/pandas-stubs

This is result of a strategic effort lead by the core pandas team to integrate Microsoft type stub repository together with the current pandas_stubs repository.

All future development will take place in the new repository and both the PyPI and CondaForge distributions will be sourced from there.

If you're having any problems with the current package please try switching over, and report any issues on the new Github page. It's available both on PyPI and conda-forge.

Related issue: 172

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

This works only for legacy versions. Any version higher than shown here will install a version from the new repository.

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==1.2.0.62

Another way to install is using Conda:

conda install -c conda-forge pandas-stubs=1.2.0.62

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

More Repositories

1

git-machete

Probably the sharpest git repository organizer & rebase/merge workflow automation tool you've ever seen
Python
828
star
2

scala-cli

Scala CLI is a command-line tool to interact with the Scala language. It lets you compile, run, test, and package your Scala code (and more!)
Scala
500
star
3

graphbuddy

Graph Buddy helps you to understand the code better
HTML
143
star
4

render

Universal data-driven template for generating textual output, as a static binary and a library
Go
139
star
5

iskra

Typesafe wrapper for Apache Spark DataFrame API
Scala
129
star
6

git-machete-intellij-plugin

Probably the sharpest git repository organizer & rebase/merge workflow automation tool you've ever seen
Java
128
star
7

unicorn

Small Slick library for type-safe id handling
Scala
112
star
8

Inkuire

Hoogle-like searches for Scala 3 and Kotlin
Scala
90
star
9

besom

Besom - a Pulumi SDK for Scala. Also, incidentally, a broom made of twigs tied round a stick. Brooms and besoms are used for protection, to ward off evil spirits, and cleansing of ritual spaces.
Scala
89
star
10

avocADO

Safe compile-time parallelization of for-comprehensions for Scala 3
Scala
83
star
11

jenkins-operator

Kubernetes native Jenkins Operator, moved to https://github.com/jenkinsci/kubernetes-operator
Go
82
star
12

scala-yaml

Scala
75
star
13

pretty-stacktraces

Scala
57
star
14

bazel-steward

A bot to keep Bazel dependencies up to date
Kotlin
56
star
15

tetrisly-react

Tetrisly offers user-friendly components designed for effortless integration. Plus, it's fully compatible with Tetrisly for Figma with a seamless design and development experience in mind.
TypeScript
39
star
16

crypt

Universal cryptographic tool with AWS KMS, GCP KMS, GnuPG and Azure Key Vault support
Go
32
star
17

infrastructure-as-types

Infrastructure as Types - modern infrastructure declaration and deployment toolkit
Scala
26
star
18

ide-probe

Scala
26
star
19

beholder

Small slick lib for create views on on database
Scala
26
star
20

akka-serialization-helper

Serialization toolbox for Akka messages, events and persistent state that helps achieve compile-time guarantee on serializability. No more errors in the runtime!
Scala
26
star
21

activator-play-advanced-slick

Typesafe Activator template for advanced play-slick project
HTML
20
star
22

kubedrainer

Simple Kubernetes Node Drainer
Go
20
star
23

strapi-plugin-content-manager-extension-hierarchical

strapi-plugin-content-manager-extension-hierarchical
JavaScript
16
star
24

contextbuddy

Platform documentation
CSS
15
star
25

scala-packager

Scala
12
star
26

using_directives

Java
12
star
27

community-build3

Scala
11
star
28

vss

Scala
10
star
29

coursier-m1

A small repo to release coursier using self-hosted Mac M1 runner
Shell
10
star
30

ReactSphere-reactive-beyond-hype

Repo for presentation on ReactSphere: Reactive beyond hype
HCL
8
star
31

akka-workshop-client

Base code for akka workshop.
Scala
8
star
32

pekko-serialization-helper

Serialization toolbox for Pekko messages, events and persistent state that helps achieve compile-time guarantee on serializability. No more errors in the runtime!
Scala
8
star
33

scala-snippet-checker

TypeScript
7
star
34

scala-compose

Scala
6
star
35

pyspark-workshop

HTML
6
star
36

codetale

CodeTale - documentation & issue tracking
Dockerfile
6
star
37

genesis

Common sbt settings for sbt-based projects
Scala
5
star
38

data_lake_navigation_atlas

Code for blogpost Navigation in the data lake using Atlas
Scala
5
star
39

kleisli-examples

Examples from blog post on Kleisli arrows
Scala
5
star
40

ddd-public-materials

All public materials for community prepared by The DDD guild from Virtuslab
Kotlin
5
star
41

scg-cli

scg-cli is a CLI tool for Semantic Code Graph analysis
Scala
5
star
42

tips

CSS
4
star
43

go-extended

Things missing or not belonging in the standard library
Go
3
star
44

mesos-on-vagrant

Just a Vagrant file and Ansible playbook for deploying Mesos cluster for testing
3
star
45

scala-workshop

Scala
3
star
46

talk-scala-akka-play

Introductory talk to Scala, Akka and Play! framework
JavaScript
3
star
47

base-types-kt

Library with common types for Kotlin supporting domain-driven functional programming
Kotlin
3
star
48

Edison-BlinkOnboard

Example Akka system for blinking LED at Intel Edison
Scala
3
star
49

jira-stats

Exports some metrics from jira via REST api - currently calculated dev days per ticket
Go
2
star
50

runscope-agent

Containerized Runscope Agent (Dockerfile)
Makefile
2
star
51

homebrew-cloud

This repository contains a collection of Homebrew formulas.
Ruby
2
star
52

scala-cli-packages

Shell
2
star
53

ide-probe-tests

Scala
2
star
54

spark_sql_under_the_hood

Code for blogpost: Spark SQL under the hood
Scala
2
star
55

homebrew-scala-cli

Ruby
1
star
56

scalacamp

ScalaCamp.pl site source code
HTML
1
star
57

homebrew-git-machete

1
star
58

gpki

Git Public Key Infrastructure
Python
1
star
59

scala-workshop-bootstrap

Shell
1
star
60

jenkins-operator-assets

Hosting Jenkins Operator assests like images or CSS files.
CSS
1
star
61

virtusity-workshop-graphql

TypeScript
1
star
62

dokka-site

Kotlin
1
star
63

kibana-rpm-packaging

1
star
64

kubectl-deploy

Simple kubectl plugin for rendering and applying Kubernetes manifests
Go
1
star
65

scala-cli.g8

Scala
1
star
66

akka-http-kubernetes.g8

Scala
1
star
67

homebrew-scala-experimental

Ruby
1
star
68

scg-scala

Scala compiler plugin for Semantic Code Graph generation
Scala
1
star
69

Ariadne-Bootloader

A little less unfinished TFTP bootloader for Arduino Leonardo Ethernet
Arduino
1
star
70

ScalaTastiesScrapper

Scala
1
star
71

aws-cli

Yet Another Dockerized AWS CLI
Makefile
1
star
72

shuttlecraft

Scala
1
star