Skip to content

Parquet and Arrow IPC

Qubitium edited this page Dec 5, 2026 · 6 revisions

Parquet and Arrow IPC

Full signatures and usage: Parquet and Arrow.

Use Parquet.load(source, *, file=None, columns=None, revision=None, download=False, token=None, provider="hf") for top-level projection. Pass a local path, or a repository ID with file= to resolve a cached repository shard as load() does. Iteration and take stream rows. collect() materializes the result in order. For large multi-group shards it uses mapping windows up to 32 MiB and up to four workers with the GIL enabled or 16 with the GIL disabled. Streaming uses 8 MiB mapping windows. Projection lets a text-only calibration job skip nested message columns.

from pathlib import Path
from tempfile import TemporaryDirectory
from datashoal import Parquet

with TemporaryDirectory() as tmp:
    path = Path(tmp) / "train.parquet"
    rows = [{"id": 1, "messages": [{"role": "user", "content": "hello"}]},
            {"id": 2, "messages": []}]
    schema = {"id": "int32", "messages": [{"role": "string", "content": "string"}]}
    Parquet.save(path, rows, schema=schema, row_group_size=1)
    assert Parquet.load(path, columns=["messages"]).take(1) == [{"messages": rows[0]["messages"]}]
    assert [i for page in Parquet.load_buffers(path, "id") for i in page] == [1, 2]

Mapping lifetime

Local Parquet and Arrow streams use read-only mappings of up to 8 MiB. Independent cursors share a window while they need it. Moving past a window or closing its final cursor releases that mapping. Rows and typed page buffers own their backing data and stay valid after close. Use immutable input files or publish replacements atomically. Truncating a live mapped file in place can invalidate operating-system mappings.

Streaming can decode several small row groups concurrently and yields them in file order. It reads large groups serially. Streaming bounds read-ahead, while the memory needed to decode one page or assemble one row still depends on its contents. Full collection retains every returned Python row. Closing a cursor early cancels queued work and waits for active readers to release their windows.

Write a shard

Parquet.save(path, rows, *, schema, row_group_size=1024, compression="none") accepts an iterable of dictionaries. Give each field an explicit type: bool, int32, int64, float32, float64, binary or string. Use a one-element list for a list type and a nested dictionary for a struct. Fields are nullable. Empty lists and null lists retain distinct meanings. The writer uses PLAIN pages and publishes the finished file atomically. Select compression="gzip" for compressed output. Lower the group size to reduce writer memory.

Read supported pages

The reader handles V1 and V2 pages, PLAIN and dictionary values, RLE booleans, nested lists and structs. It supports uncompressed, Snappy and gzip pages. Zstandard requires Python 3.14+ with the standard-library Zstandard codec. Unsupported encodings and logical types, including decimal and timestamp columns, can raise an error. Select supported columns when those other fields are irrelevant.

Parquet.load_buffers(source, column, *, file=None, ...) yields a read-only, typed memoryview for each page of one flat numeric column. Values must be non-null. Consume pages individually to bound memory. Combining buffers into a single array can require a copy.

Saved Hugging Face Arrow streams

ArrowIPC.load(source, *, file=None, columns=None, ...) reads uncompressed Arrow IPC streams, including saved HF calibration shards containing text or integer lists. Supported fields include signed/unsigned integers, binary, UTF-8 and lists, including large-offset variants. File-container IPC, compressed batches and dictionary fields are outside this reader’s supported surface.

DataShoal decodes text and binary columns with its C11 accelerator when available. The Python path reads the same column types when compilation is unavailable.

ArrowIPC.sample(paths, count, *, rng, columns=None) samples across local shards without replacement. Pass an ordered sequence of paths and a seeded random.Random. It reads batch metadata to count rows, decodes selected batches, and returns the requested rows in RNG order.

Clone this wiki locally