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: 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 | 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_typeschema.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 schemaarray_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 withlist_of_lists_schema().Potentially Fragile
Uses a private method from the handler to flatten out nested definitions (e.g. when dtype is a pydantic model) so that they are present in the generated schema directly rather than as references. Otherwise, at the time __get_pydantic_json_schema__ is called, the definition references are lost.
- Parameters:
shape (ShapeType) – Specification of a shape, as a tuple or an nptyping
Shapedtype (DtypeType) – A builtin type or numpy dtype
_handler – The pydantic schema generation handler (see pydantic docs)
- Returns:
pydantic_core.core_schema.ListSchema