Skip to main content

Type stubs for Python machine learning libraries

Project description

Python type stubs for numpy, pandas and matplotlib

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

pip install data-science-types

There is also minor support for Tensorflow and Tensorflow Probability.

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 class hierarchy exactly. The goal is to have useful checks on our code. Often the actual API in the libraries is more permissive than the type signatures in our stubs; but this is (usually) a feature and not a bug.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

data-science-types-0.2.3.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

data_science_types-0.2.3-py3-none-any.whl (36.3 kB view details)

Uploaded Python 3

File details

Details for the file data-science-types-0.2.3.tar.gz.

File metadata

  • Download URL: data-science-types-0.2.3.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0.post20200106 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.6

File hashes

Hashes for data-science-types-0.2.3.tar.gz
Algorithm Hash digest
SHA256 b10b226a52762045bca3b58063d44313be8022ea441354f4ae23b399cb3addde
MD5 d44f46269bde2c0bd8d49310e8cfaad1
BLAKE2b-256 c9fbdb07cab00f93f350649e68e9e613e5859d76dcac6f5ac66abceab7dca38d

See more details on using hashes here.

File details

Details for the file data_science_types-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: data_science_types-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 36.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0.post20200106 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.6

File hashes

Hashes for data_science_types-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2b660599e99400c6fe1c5597166ce5aedfdb03629bd48738abb99791cdc49611
MD5 8cfa100248ea1b22da5a9e6b385f76f7
BLAKE2b-256 b8e8549603853edb8d30155e86570d8497fad46f618e394f754831960f36b8a0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page