Skip to main content

Type hints for Numpy

Project description

|PyPI version| |Build Status|

nptyping
========

Type hints for `Numpy`!

Installation
''''''''''''

::

pip install nptyping

Usage
'''''

Use the `nptyping` type hints like the regular type hints from `typing`:

.. code:: python

from nptyping import Array


def func1(arr: Array[int]): # A numpy.ndarray that contains numbers
...

You can also define the shape of an array:

.. code:: python

Array[str, 3, 2] # 3 rows and 2 columns
Array[str, 3] # 3 rows and an undefined number of columns
Array[str, 3, ...] # 3 rows and an undefined number of columns
Array[str, ..., 2] # an undefined number of rows and 2 columns

Heterogeneous arrays are supported as well:

.. code:: python

Array[int, float, str] # int, float and str on columns 1, 2 and 3 resp.
Array[int, float, str, ...] # int, float and str on columns 1, 2 and 3 resp.
Array[int, float, str, 3] # 3 rows and int, float and str on columns 1, 2 and 3 resp.

`nptyping` also supports instance checks:

.. code:: python

import numpy
from nptyping import Array


arr = numpy.array([[1, 2],
[3, 4],
[5, 6]])

isinstance(arr, Array[int, 3, 2]) # True
isinstance(arr, Array[str, 3, 2]) # False
isinstance(arr, Array[int, 3, ...]) # True
isinstance(arr, Array[int, 3, 6]) # False

Also for heterogeneous arrays:

.. code:: python

import numpy
from nptyping import Array


arr = np.array([(1, 2.0, '3'),
(4, 5.0, '6')],
dtype=[('a', int), ('b', float), ('c', str)])

isinstance(arr, Array[int, float, str]) # True
isinstance(arr, Array[float, float, str]) # False
isinstance(arr, Array[int, float, str, 2]) # True


.. include:: HISTORY.rst


.. |PyPI version| image:: https://badge.fury.io/py/nptyping.svg
:target: https://badge.fury.io/py/nptyping

.. |Build Status| image:: https://api.travis-ci.org/ramonhagenaars/nptyping.svg?branch=master
:target: https://travis-ci.org/ramonhagenaars/nptyping

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

nptyping-0.2.0.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nptyping-0.2.0-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file nptyping-0.2.0.tar.gz.

File metadata

  • Download URL: nptyping-0.2.0.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.1

File hashes

Hashes for nptyping-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8823b7422be989751b9bfdba9155fa3ab06d98db9e57678f0c9a1dae07f452ac
MD5 7b37a8ae04614b7d6a3b608b02d70f75
BLAKE2b-256 9c7f8003c6713bf3751acad97a87b8bd7b97104cd3be1dbddc5a29d895e3179e

See more details on using hashes here.

File details

Details for the file nptyping-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: nptyping-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 2.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.1

File hashes

Hashes for nptyping-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f2f8f8b2987ce01731b5ef3a8b9ab2fbc4bf79fde1d57f5287049def379320cc
MD5 422aef840b701b4c31d44386afce6e2b
BLAKE2b-256 a50f9b44a1866c7911d03329669d82d2ebb1b8e6dac15803fdb6588549a44193

See more details on using hashes here.

Supported by

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