Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mypy/typeshed stubs for Pandas

Just checking to see if anybody listening has already generated a sort-of-working set of mypy/typeshed stubs for `pandas`. I naively ran stubgen over the local pandas install which generated some errors. I can go with what I have to start with, but was hoping someone else had pushed the ball further. (Nothing obvious turned up on GitHub, though there is an old ticket for stubs.)

like image 385
smontanaro Avatar asked Dec 12 '16 17:12

smontanaro


People also ask

What are MYPY stubs?

Mypy uses stub files stored in the typeshed repository to determine the types of standard library and third-party library functions, classes, and other definitions. You can also create your own stubs that will be used to type check your code.

What is Typeshed in Python?

Typeshed contains external type annotations for the Python standard library and Python builtins, as well as third party packages as contributed by people external to those projects. This data can e.g. be used for static analysis, type checking or type inference.

How do I add stubs to Python?

Create a stub file for your own implementationSelect File | New from the main menu, then select Python File (alternatively, use the Alt+Insert shortcut). In the New Python file dialog, select Python stub and specify the filename. The filename should be the same as the name of the implementation file.

Where do I put Pyi files?

pyi files that describe entire packages (directories containing __init__.py) should be placed in the package directory's parent directory.


2 Answers

By now (March 2021) there is a dedicated pandas stub project in progress. It is however not developed by the pandas team (thanks to @remeus for pointing that out). The data-science-types project is deprecated. On GitHub they write:

⚠️ this project has mostly stopped development ⚠️

The pandas team and the numpy team are both in the process of integrating type stubs into their codebases, and we don't see the point of competing with them.

The NumPy stubs used to be in a seperate project, but now have been merged into the main git repo:

These stubs have been merged into NumPy, and all further development will happen in the NumPy main repo. We welcome your contributions there!

like image 182
user2640045 Avatar answered Oct 02 '22 09:10

user2640045


As of June 2020, pandas doesn't have stubs yet, but there is some progress in that direction. By now, you can use the data-science-types package (on GitHub) which provides stub files for pandas, numpy and matplotlib, though it's also a work in progress.

like image 36
Nicolas Martinez Avatar answered Oct 02 '22 09:10

Nicolas Martinez