ListArray¶
Overview¶
ListArray is a row-oriented container for variable-length list cells.
It is the natural public container for list-valued blosc2.CTable
columns, but it is also useful on its own whenever you want typed,
row-addressable list data.
Internally, ListArray uses one of two lower-level backends:
blosc2.BatchArrayfor append/scan-oriented workloadsblosc2.ObjectArrayfor simpler row-level replacement semantics
Quick example¶
import blosc2
arr = blosc2.ListArray(
item_spec=blosc2.string(max_length=16),
nullable=True,
storage="batch",
urlpath="ingredients.b2b",
mode="w",
)
arr.append(["salt", "sugar"])
arr.append([])
arr.append(None)
print(arr[0])
print(arr[1:])
reopened = blosc2.open("ingredients.b2b", mode="r")
print(type(reopened).__name__)
Note
Returned Python lists are detached values. Mutating them locally does not write back to the container; reassign the whole cell instead.
- class blosc2.ListArray(spec: ListSpec | None = None, *, item_spec: SchemaSpec | None = None, nullable: bool = False, storage: str = 'batch', serializer: str = 'msgpack', batch_rows: int | None = None, items_per_block: int | None = None, _from_schunk=None, **kwargs: Any)[source]¶
A row-oriented container for list-valued data.
Backed internally by either
blosc2.ObjectArrayorblosc2.BatchArray.- Attributes:
batch_rowsTarget number of rows per persisted batch, if configured.
cbytesCompressed byte size reported by the backend.
contiguousWhether the backing store is contiguous on disk.
cparamsCompression parameters of the underlying container.
cratioCompression ratio reported by the backend.
dparamsDecompression parameters of the underlying container.
infoHuman-readable information reporter for this array.
info_itemsItems used by
infoto render this array’s summary.items_per_blockMaximum number of list cells per internal compressed block.
metaFixed-length metadata mapping for the underlying container.
nbytesUncompressed byte size reported by the backend.
schunkUnderlying
blosc2.SChunkused by the backend.urlpathPath of the persistent backing store, or
Nonefor memory-only arrays.vlmetaVariable-length metadata mapping for the underlying container.
Methods
append(value)Append one list cell and return the new number of rows.
close()Flush pending rows and close the logical container.
copy(**kwargs)Return a copy, optionally with different storage arguments.
extend(values, *[, validate])Append multiple list cells.
extend_arrow(arrow_array)Append a PyArrow list array without materializing Python cells.
flush()Persist any pending rows when using the batch backend.
from_arrow(arrow_array, *[, item_spec, ...])Build a ListArray from a PyArrow list or chunked list array.
to_arrow()Return the data as a PyArrow list array.
Serialize the underlying container to a contiguous C-frame.
Constructors¶
- __init__(spec: ListSpec | None = None, *, item_spec: SchemaSpec | None = None, nullable: bool = False, storage: str = 'batch', serializer: str = 'msgpack', batch_rows: int | None = None, items_per_block: int | None = None, _from_schunk=None, **kwargs: Any) None[source]¶
Create a list-valued container.
Parameters may be supplied either as a complete
specor as anitem_specplus list/storage options. Storage-related keyword arguments are passed toblosc2.Storage.
- classmethod from_arrow(arrow_array, *, item_spec: SchemaSpec | None = None, nullable: bool = True, storage: str = 'batch', serializer: str = 'msgpack', batch_rows: int | None = None, items_per_block: int | None = None, **kwargs: Any) ListArray[source]¶
Build a ListArray from a PyArrow list or chunked list array.
Row Interface¶
Mutation¶
Context Manager¶
Public Members¶