ndarray

Extension of nptyping NDArray for pydantic that allows for JSON-Schema serialization

Note

This module should only have the NDArray class in it, because the type stub ndarray.pyi is only created for NDArray . Otherwise, type checkers will complain about using any helper functions elsewhere - those all belong in numpydantic.schema .

Keeping with nptyping’s style, NDArrayMeta is in this module even if it’s excluded from the type stub.

class NDArrayMeta(name: str, *args: Any, **kwargs: Any)[source]

Hooking into nptyping’s array metaclass to override methods pending completion of the transition away from nptyping

__instancecheck__(instance: Any)[source]

Extended type checking that determines whether

  1. the type of the given instance is one of those in

    Interface.input_types()

but also

  1. it satisfies the constraints set on the NDArray annotation

Parameters:

instance (typing.Any) – Thing to check!

Returns:

True if matches constraints, False otherwise.

Return type:

bool

class NDArray(*_: Any, **__: Any)[source]

Constrained array type allowing npytyping syntax for dtype and shape validation and serialization.

This class is not intended to be instantiated or used for type checking, it implements the ``__get_pydantic_core_schema__` method to invoke the relevant interface for validation and serialization.

References