mixle.data.schema module¶
Schema and logical types – the bridge between external data and the Python types encoders expect.
A deliberately small, closed logical type system (not an open type algebra). Each FieldType
knows its canonical NumPy dtype and how to coerce a raw value into the Python object the existing
DataSequenceEncoder already consumes (a label for Categorical, an np.ndarray for Vector,
…). A Schema is an ordered tuple of named Field s; it can be derived from a model
(formalizing the fields/sources duck-probe in the DataFrame adapter) and used to conform raw
records (coerce + validate) before encoding – the thing connectors silently get wrong today.
- class FieldType[source]
Bases:
objectBase logical type: a canonical NumPy dtype plus a coercion to the encoder-ready Python value.
- numpy_dtype
alias of
float64
- class Real[source]
Bases:
FieldTypeA real-valued scalar.
- numpy_dtype
alias of
float64
- class Count[source]
Bases:
FieldTypeA non-negative integer count.
- numpy_dtype
alias of
int64
- class Categorical(categories=None, numpy_dtype=<class 'numpy.object_'>)[source]
Bases:
FieldTypeA categorical label, optionally over a fixed set of
categories.- numpy_dtype
alias of
object_
- class Vector(dim=None, numpy_dtype=<class 'numpy.float64'>)[source]
Bases:
FieldTypeA fixed- or free-length real vector.
- numpy_dtype
alias of
float64
- class Timestamp[source]
Bases:
FieldTypeA point in time (datetime / numpy datetime64 / ISO string / POSIX seconds).
- numpy_dtype: Any = dtype('<M8[ns]')
- class Optional(inner=<factory>)[source]
Bases:
FieldTypeA value that may be missing (
Nonepasses through; otherwise the inner type coerces).- Parameters:
inner (FieldType)
- inner: FieldType
- property numpy_dtype: Any
Double-precision floating-point number type, compatible with Python
floatand Cdouble.- Character code:
'd'- Canonical name:
numpy.double
- Alias on this platform (Linux x86_64):
numpy.float64: 64-bit precision floating-point number type: sign bit, 11 bits exponent, 52 bits mantissa.
- class Nested(schema, numpy_dtype=<class 'numpy.object_'>)[source]
Bases:
FieldTypeA sub-record with its own
Schema.- Parameters:
schema (Schema)
numpy_dtype (Any)
- schema: Schema
- numpy_dtype
alias of
object_
- class Field(name, type)[source]
Bases:
objectA named, typed column.
- Parameters:
name (str)
type (FieldType)
- name: str
- type: FieldType
- class Schema(fields)[source]
Bases:
objectAn ordered set of typed fields.
- Parameters:
fields (tuple[Field, ...])
- fields: tuple[Field, ...]
- conform_record(record)[source]
Coerce one record (a scalar for a 1-field schema, else a tuple/dict) to the schema’s types.
- conform(records)[source]
Coerce every record in
recordsto this schema (raising clear errors on mismatch).
- static for_model(model)[source]
Best-effort schema a model expects, from its
fields/sources+ child distributions.Formalizes the duck-probe in the DataFrame adapter: a record/composite model exposes
fieldsandsourcesplus child distributions whose support fixes each field’s logical type; a bare leaf yields a single field typed by its support (discrete -> Count, continuous -> Real, …).- Parameters:
model (Any)
- Return type:
Schema