ursa.backends.lance¶
Lance-backed reader for StorageFormat.LANCE modalities.
Used by genuinely-event modalities (keyboard, mouse, browser, notes,
battery, location). High-density “almost-regular” streams like
pupillabs-gaze deliberately go to Zarr instead — see the
Zarr-vs-Lance rule of thumb (fixed payload + dense → Zarr; variable
payload or sparse → Lance).
Two callable surfaces:
The materialized opener wired through the temporal-class dispatcher (:func:
ursa.IrregularTimeSeries.from_uri→ backend factory) loads the whole table and populates anIrregularTimeSeriesinstance.The free-standing :class:
LazyLanceIrregularTimeSeriesexposes a column-on-access__getattr__that pushestimestamp >= t0 AND timestamp < t1filters down to DataFusion on the next read after :meth:slice. Reach for it via- func:
open_lance_irregular_lazy_freestanding(or the class directly) whenDataInterface.materialize(lazy=False)would materialize too much.
Sort-by-timestamp contract: writers MUST sort by timestamp and emit
an ursa.sorted_by="timestamp" flag in the dataset’s user metadata.
Readers warn (don’t raise) if the flag is absent — the slice still
works but the scan is unbounded.
Timestamp-unit contract: the timestamp column MUST be float64
recording-relative seconds. The reader rejects other Arrow types
(notably int64 nanoseconds) up-front via :func:_check_timestamp_column
so a writer that picks the wrong unit fails fast instead of silently
producing a series with a ~55-billion-year domain.
Module Contents¶
Classes¶
Streaming-pointer Lance reader for irregular event streams. |
Functions¶
Construct the free-standing :class: |
|
API¶
- class ursa.backends.lance.LazyLanceIrregularTimeSeries(uri: str, *, store: ursa.store.base.ObjectStore, metadata: ursa.catalog.schemas.ModalityRow | None = None)[source]¶
Streaming-pointer Lance reader for irregular event streams.
Construction reads only dataset metadata (schema + row count + sort-metadata check). Column access via
__getattr__triggers a per-column Lance scan; if :meth:slicewas called first, the scan is pushed down to a half-opentimestamp >= t0 AND timestamp < t1filter via DataFusion.Free-standing on purpose: the upstream
- Class:
temporaldata.LazyIrregularTimeSeriesmaterialization gate expectsh5py.Dataset- orzarr.Array-shaped column handles, and Lance’s column-scan model doesn’t slot in cleanly. The class exposes the same external surface (.slice(), attribute-style column access,.metadata) so callers don’t need to branch on backend type.
Initialization
- _RESERVED¶
‘frozenset(…)’
- property metadata: ursa.catalog.schemas.ModalityRow | None¶
- _fetch_column(name: str) numpy.ndarray[source]¶
Issue the Lance scan for one column with optional time pushdown.
- slice(start: float, end: float, reset_origin: bool = True) ursa.backends.lance.LazyLanceIrregularTimeSeries[source]¶
Return a new lazy view restricted to
[start, end).reset_origin=True(default) is recorded for downstream materialization — when the timestamps column is fetched, the values are shifted by-startbefore being returned, matching- Meth:
temporaldata.IrregularTimeSeries.slice’s default.
Both bounds must be finite.
inf/nanwould flow into the DataFusion filter as literalinf/nanand produce an opaque parse error deep inside Lance; we catch that here and raise a cleanValueErrorinstead.
- property timestamps: numpy.ndarray¶
Materialize the timestamp column, applying the slice-origin shift.
- ursa.backends.lance.open_lance_irregular_lazy_freestanding(uri: str, store: ursa.store.base.ObjectStore, metadata: ursa.catalog.schemas.ModalityRow | None) ursa.backends.lance.LazyLanceIrregularTimeSeries[source]¶
Construct the free-standing :class:
LazyLanceIrregularTimeSeries.NOT the dispatcher opener — that’s :func:
_open_lance_irregular_lazyabove and intentionally raises (see its docstring). This helper exists for callers (notably :meth:DataInterface.materialize) that want column-on-demand Lance access via the free-standing class rather than throughLazyIrregularTimeSeries.from_uri.
- ursa.backends.lance._open_lance_irregular_materialized(instance: Any, uri: str, *, store: ursa.store.base.ObjectStore, metadata: ursa.catalog.schemas.ModalityRow | None, max_fallback_bytes: int | None = None) None[source]¶
- ursa.backends.lance._open_lance_irregular_lazy(instance: Any, uri: str, *, store: ursa.store.base.ObjectStore, metadata: ursa.catalog.schemas.ModalityRow | None, max_fallback_bytes: int | None = None) None[source]¶