mixle.data.core module¶
DataSource – a lazy, typed, structured reference to data that yields encoder-ready records.
This is the single concept that replaces the “is it a list? a DataFrame? an RDD? a SQL cursor?” branching
scattered across call sites. A DataSource carries a Schema (logical field
types) and a SampleStructure (its exchangeability class), and knows how to
yield records() and partition itself safely.
It is purely additive: seq_encode(list) and seq_encode(rdd) are untouched fast paths;
seq_encode gains one branch that recognizes a DataSource and routes through its structure-aware
encoder, returning the same [(count, payload)] shape consumers already expect.
- class DataSource(*args, **kwargs)[source]
Bases:
ProtocolA lazy, typed, structured source of encoder-ready records.
- schema: Schema | None
- structure: SampleStructure
- records()[source]
Yield raw records compatible with an encoder’s input type.
- class MaterializedSource(data, structure=EXCHANGEABLE, schema=None)[source]
Bases:
objectAn in-memory
DataSourcewrapping aSequence– what a bare list becomes.- Parameters:
data (Sequence[Any])
structure (SampleStructure)
schema (Schema | None)
- materialize()[source]
Return the records as a list, coerced to the schema if one is set.
- partition(n, *, by=None)[source]
Split into
nstructure-safe sub-sources (group-aware for partially-exchangeable data).
- class LazySource(factory, structure=EXCHANGEABLE, schema=None, length=None)[source]
Bases:
objectA
DataSourcethat defers reading to a records factory and materializes on demand.Connectors (Parquet, SQL, CSV, …) return one of these so
open(...)does no I/O until the data is actually encoded; the records are read (and schema-coerced) once and cached.- Parameters:
factory (Any)
structure (SampleStructure)
schema (Schema | None)
length (int | None)