Type hints for NumPy.
pip install nptyping🧊 Type hints for NumPy
🐼 Type hints for pandas.DataFrame
💡 Extensive dynamic type checks for dtypes shapes and structures
🚀 Jump to the Quickstart
Example of a hinted numpy.ndarray:
>>> from nptyping import NDArray, Int, Shape
>>> arr: NDArray[Shape["2, 2"], Int]
Example of a hinted pandas.DataFrame:
>>> from nptyping import DataFrame, Structure as S
>>> df: DataFrame[S["name: Str, x: Float, y: Float"]]
Installation
| Command | Description |
|---|---|
pip install nptyping | Install the basics |
pip install nptyping[pandas] | Install with pandas extension |
pip install nptyping[complete] | Install with all extensions |
Instance checking
Example of instance checking:
>>> import numpy as np
>>> isinstance(np.array([[1, 2], [3, 4]]), NDArray[Shape["2, 2"], Int])
True
>>> isinstance(np.array([[1., 2.], [3., 4.]]), NDArray[Shape["2, 2"], Int])
False
>>> isinstance(np.array([1, 2, 3, 4]), NDArray[Shape["2, 2"], Int])
False