• This repository has been archived on 17/Feb/2021
  • Stars
    star
    202
  • Rank 192,520 (Top 4 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created almost 5 years ago
  • Updated over 3 years ago

Reviews

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

Repository Details

Mypy stubs, i.e., type information, for numpy, pandas and matplotlib

Mypy type stubs for NumPy, pandas, and Matplotlib

Join the chat at https://gitter.im/data-science-types/community

⚠️ 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.


This is a PEP-561-compliant stub-only package which provides type information for matplotlib, numpy and pandas. The mypy type checker (or pytype or PyCharm) can recognize the types in these packages by installing this package.

NOTE: This is a work in progress

Many functions are already typed, but a lot is still missing (NumPy and pandas are huge libraries). Chances are, you will see a message from Mypy claiming that a function does not exist when it does exist. If you encounter missing functions, we would be delighted for you to send a PR. If you are unsure of how to type a function, we can discuss it.

Installing

You can get this package from PyPI:

pip install data-science-types

To get the most up-to-date version, install it directly from GitHub:

pip install git+https://github.com/predictive-analytics-lab/data-science-types

Or clone the repository somewhere and do pip install -e ..

Examples

These are the kinds of things that can be checked:

Array creation

import numpy as np

arr1: np.ndarray[np.int64] = np.array([3, 7, 39, -3])  # OK
arr2: np.ndarray[np.int32] = np.array([3, 7, 39, -3])  # Type error
arr3: np.ndarray[np.int32] = np.array([3, 7, 39, -3], dtype=np.int32)  # OK
arr4: np.ndarray[float] = np.array([3, 7, 39, -3], dtype=float)  # Type error: the type of ndarray can not be just "float"
arr5: np.ndarray[np.float64] = np.array([3, 7, 39, -3], dtype=float)  # OK

Operations

import numpy as np

arr1: np.ndarray[np.int64] = np.array([3, 7, 39, -3])
arr2: np.ndarray[np.int64] = np.array([4, 12, 9, -1])

result1: np.ndarray[np.int64] = np.divide(arr1, arr2)  # Type error
result2: np.ndarray[np.float64] = np.divide(arr1, arr2)  # OK

compare: np.ndarray[np.bool_] = (arr1 == arr2)

Reductions

import numpy as np

arr: np.ndarray[np.float64] = np.array([[1.3, 0.7], [-43.0, 5.6]])

sum1: int = np.sum(arr)  # Type error
sum2: np.float64 = np.sum(arr)  # OK
sum3: float = np.sum(arr)  # Also OK: np.float64 is a subclass of float
sum4: np.ndarray[np.float64] = np.sum(arr, axis=0)  # OK

# the same works with np.max, np.min and np.prod

Philosophy

The goal is not to recreate the APIs exactly. The main goal is to have useful checks on our code. Often the actual APIs in the libraries is more permissive than the type signatures in our stubs; but this is (usually) a feature and not a bug.

Contributing

We always welcome contributions. All pull requests are subject to CI checks. We check for compliance with Mypy and that the file formatting conforms to our Black specification.

You can install these dev dependencies via

pip install -e '.[dev]'

This will also install NumPy, pandas, and Matplotlib to be able to run the tests.

Running CI locally (recommended)

We include a script for running the CI checks that are triggered when a PR is opened. To test these out locally, you need to install the type stubs in your environment. Typically, you would do this with

pip install -e .

Then use the check_all.sh script to run all tests:

./check_all.sh

Below we describe how to run the various checks individually, but check_all.sh should be easier to use.

Checking compliance with Mypy

The settings for Mypy are specified in the mypy.ini file in the repository. Just running

mypy tests

from the base directory should take these settings into account. We enforce 0 Mypy errors.

Formatting with black

We use Black to format the stub files. First, install black and then run

black .

from the base directory.

Pytest

python -m pytest -vv tests/

Flake8

flake8 *-stubs

License

Apache 2.0

More Repositories

1

EthicML

Package for evaluating the performance of methods which aim to increase fairness, accountability and/or transparency
Python
24
star
2

conduit

Lightweight framework for data-loading with PyTorch and harvesting the power of (PyTorch) lightning
Python
11
star
3

nifr

Null-sampling for Interpretable and Fair Representations
Jupyter Notebook
8
star
4

UniversalGP

Generic implementation of GP model
Python
8
star
5

qBOLD-VI

A Bayesian inference package for qBOLD MRI data
Python
5
star
6

okapi

[NeurIPS 2022] Okapi: Generalising Better by Making Statistical Matches Match
Python
5
star
7

Data-Domain-Fairness

Python
4
star
8

denoising

Fully-convolutional image denoiser incorporating camera ISO values as conditional information.
Python
3
star
9

ranzen

A python toolkit facilitating machine-learning experimentation.
Python
3
star
10

ecoacoustics

Jupyter Notebook
3
star
11

datasheet_generation

Jupyter Notebook
3
star
12

fescher

A foray into the world of performative prediction
Python
2
star
13

acre-cascade

Python
2
star
14

biomassters

Python
2
star
15

teext

Typing extensions extensions
Python
2
star
16

compression-subgroup

[EMNLP 2023] Are Compressed Language Models Less Subgroup Robust?
Python
2
star
17

RealPatch

Python
2
star
18

presentations

View presentations here: https://wearepal.ai/presentations/
HTML
2
star
19

landscapes

TypeScript
2
star
20

ethicml-models

Models for EthicML
Jupyter Notebook
2
star
21

hyaline

A repo with the straightforward goal of evaluating and comparing various domain-generalisation, group-robust, and distributionally-robust algorithms on common benchmarks in an attempt to gauge what progress (if any) has been made and thereby identify future avenues of research.
Python
2
star
22

missing-sources

Jupyter Notebook
1
star
23

neoconfigen

configen-fork with extended type-support
Python
1
star
24

topocluster

Python
1
star
25

landscapes-ml

Models and training routines for the 'landscapes' projects
Python
1
star
26

rhyolite

Simple creation of data classes from dictionaries.
Python
1
star
27

support-matching

Jupyter Notebook
1
star