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
Prevent subclasses, return from internal dict instead
- __call__(val: NDArrayType) NDArrayType[source]¶
Call ndarray as a validator function
- __instancecheck__(instance: Any)[source]¶
Extended type checking that determines whether
- the
typeof the given instance is one of those in
- the
but also
it satisfies the constraints set on the
NDArrayannotation
- Parameters:
instance (
typing.Any) – Thing to check!- Returns:
Trueif matches constraints,Falseotherwise.- Return type:
- class NDArray(val: NDArrayType)[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