rheon.polars.stream

Streaming transforms of a query before a bank: targets known only after a delay, windows looking back or ahead, and series that tick at their own times.

Each function takes a LazyFrame or a DataFrame and gives back the same kind, holding a bounded state in memory rather than the stream, before or beside a bank. They share three rules:

  • Frame first, the same kind back. Chain one with Polars’ own pipe, as lf.pipe(rp.stream.embargo, clock="t", delay=5.0).

  • The clock settings mean what they mean on a spec. clock and group read their columns as a spec does, and a clock parameter takes a duration on a temporal clock. session_gap is the one difference, as with_windows() says. With no clock, which only with_windows() allows, one unit is one row.

  • A stateful transform resumes with load_state and save_state, and takes chunk_size, as a bank does. embargo() is a plain Polars query with nothing to save, and takes neither. save_checkpoint() saves the states of several stages, a bank’s among them, as one file written in full or not at all, and load_checkpoint() gives each back.

function

what it does

embargo()

doubles a stream for a target known only delay after its row: each row once as a prediction at its own clock with weight 0, and once as a learn row at clock + delay, merged back into clock order. It is the delay a spec’s embargo runs inside the bank, written out in Polars, for seeing what the delay does, for a model with no embargo, and as an independent check of the bank’s own embargo.

with_windows()

adds formulas over the window operators of rheon.polars.ops (exponentially weighted means, sums, rates and quantiles looking back or ahead, and variances looking back, each with an optional hard cutoff), any number in one pass, each row out once every window over it has closed

merge()

merges streams that each run in clock order into one stream in clock order, every row kept and tagged with its stream, holding one chunk of each

refresh_time()

puts series that tick at their own times on a common grid by Barndorff-Nielsen, Hansen, Lunde & Shephard’s refresh-time rule: a grid point wherever every series has ticked at least once since the last one

save_checkpoint(), load_checkpoint()

save the states of a run’s stages, such as a grid, a window run and a bank, as one file that a crash leaves whole, old or new, and read each stage’s state back to load where it was saved

Each streams: embargo() merges two sorted copies of the same input with Polars’ merge_sorted, and the other three run as an operator of the Rust core fed one chunk at a time, read as a lazy source.

rheon.polars.stream.ROLE = '_online_role'

Column embargo() adds to say which copy of a row this is.

Columns made before a bank

Windows over the clock as columns, targets whose values arrive late, and series that tick at their own times brought onto one clock.

rheon.polars.stream.with_windows

Add columns of formulas over the window operators, computed over a stream in one pass.

rheon.polars.stream.embargo

Double a stream so that each row’s target is learned delay after its row.

rheon.polars.stream.refresh_time

Put series that tick at their own times on a common grid of refresh times.

rheon.polars.stream.merge

Merge streams that each run in clock order into one stream in clock order, every row kept.

A run’s states as one file

The states of a run’s stages, a bank’s among them, saved as one file written in full or not at all, and each stage’s state read back.

rheon.polars.stream.save_checkpoint

Save the states of a run’s stages as one file, written in full or not at all.

rheon.polars.stream.load_checkpoint

Read back the stages of a checkpoint save_checkpoint() wrote.