schema

Helper functions for use with NDArray - see the note in ndarray for why these are separated.

list_of_lists_schema(shape: Shape, array_type: InvalidSchema | AnySchema | NoneSchema | BoolSchema | IntSchema | FloatSchema | DecimalSchema | StringSchema | BytesSchema | DateSchema | TimeSchema | DatetimeSchema | TimedeltaSchema | LiteralSchema | EnumSchema | IsInstanceSchema | IsSubclassSchema | CallableSchema | ListSchema | TupleSchema | SetSchema | FrozenSetSchema | GeneratorSchema | DictSchema | AfterValidatorFunctionSchema | BeforeValidatorFunctionSchema | WrapValidatorFunctionSchema | PlainValidatorFunctionSchema | WithDefaultSchema | NullableSchema | UnionSchema | TaggedUnionSchema | ChainSchema | LaxOrStrictSchema | JsonOrPythonSchema | TypedDictSchema | ModelFieldsSchema | ModelSchema | DataclassArgsSchema | DataclassSchema | ArgumentsSchema | ArgumentsV3Schema | CallSchema | CustomErrorSchema | JsonSchema | UrlSchema | MultiHostUrlSchema | DefinitionsSchema | DefinitionReferenceSchema | UuidSchema | ComplexSchema) ListSchema[source]

Make a pydantic JSON schema for an array as a list of lists.

For each item in the shape, create a list schema. In the innermost schema insert the passed array_type schema.

This function is typically called from make_json_schema()

Parameters:
  • shape (Shape) – Shape determines the depth and max/min elements for each layer of list schema

  • array_type (pydantic_core.CoreSchema) – The pre-rendered pydantic core schema to use in the innermost list entry

make_json_schema(shape: Tuple[int, ...] | Any, dtype: str | type | Any | generic, _handler: CallbackGetCoreSchemaHandler) ListSchema[source]

Make a list of list pydantic core schema for an array from a shape and a dtype. Used to generate JSON schema in the containing model, but not for validation, which is handled by interfaces.

First resolves the dtype into a pydantic CoreSchema , and then uses that with list_of_lists_schema() .

Parameters:
  • shape (ShapeType) – Specification of a shape, as a tuple or an nptyping Shape

  • dtype (DtypeType) – A builtin type or numpy dtype

  • _handler – The pydantic schema generation handler (see pydantic docs). Needed to generate the schema for the dtype if we don’t know how to do it ourselves.

Returns:

pydantic_core.core_schema.ListSchema

get_validate_interface(shape: Tuple[int, ...] | Any, dtype: str | type | Any | generic) Callable[source]

Validate using a matching Interface class using its Interface.validate() method