rheon

Streaming and online regression models.

The names that need no dataframe library: the model builders (rheon.spec), the Gram tools (rheon.gram), the correlation tools (rheon.corr), the library’s errors and warnings, and the versions. The Polars interface (the model bank, the frame namespaces, the window operators and the scoring functions) is rheon.polars, which re-exports every name here.

Streaming and online regression models for Polars.

One Rust core, run three ways, with the same numbers from each:

  1. inside a Polars query: lf.rheon.fit_predict(specs) is a query that feeds its rows through a bank when it runs, and df.rheon.fit_predict(specs) fits a frame already in memory;

  2. ModelBank, a model bank fed one chunk at a time, whose memory grows with the models’ state and never with the number of rows that have passed. Handed a query, it reads the query a chunk at a time (ModelBank.fit_predict_batches(), ModelBank.fit());

  3. the rheon command line: Parquet, Arrow IPC, CSV or NDJSON in and out, with the state saved and resumed between runs (docs/RUNNER.md).

A spec names a model and the columns it reads (rheon.spec). Every way in takes a list of specs and writes one output column per spec. A target is a column, a column under a name of its own (target()), or a formula target, an expression over the window operators that looks ahead. To fit a target computed from its own row’s columns, such as a price against the mid, make the column with Polars’ with_columns in the query before the bank.

The modules around the bank:

module

what it does

rheon.polars.eval

scores a bank’s output

rheon.gram

solves and diagnoses the Grams a bank exports

rheon.polars.stream

transforms a query: targets whose values arrive late, series that tick at their own times, and exponentially weighted means, sums, rates, variances and quantiles looking back or ahead

rheon.polars.ops

the window operators that rheon.polars.stream.with_windows() computes, and that a formula target is built from

rheon.corr

repairs and reads correlation matrices

rheon.polars.sim

simulates streams whose truth is known

Errors follow one contract throughout, and each docstring says which part of it applies:

what went wrong

the exception

a file that cannot be read or written

the OSError subclass for what went wrong (FileNotFoundError, PermissionError, …), with the path in the message

a value that is refused: a spec parameter, a config key, what a column holds

ValueError, naming the spec and the parameter or column

a column a spec reads that the frame does not have

ColumnNotFoundError, naming the spec, the column’s role and the column: Polars’ ColumnNotFoundError and a ValueError both, so either except catches it

a spec’s output column that a scoring function’s frame does not have

OutputColumnNotFoundError, a ColumnNotFoundError

a wrong type

TypeError; for a column of a type its role cannot take, or a value of the wrong type in a spec, its subclass WrongTypeError

a value out of range, or a combination of settings refused

ValueError; for a combination, its subclass RefusedValueError

a spec name or position a bank does not have

KeyError or IndexError

a bank fed from two threads at once

RuntimeError

Subclasses of this library’s own. WrongTypeError is a TypeError, RefusedValueError a ValueError and OutputColumnNotFoundError a ColumnNotFoundError, each with the one parent the table above gives its problem, so catch the class the table names.

Inside a running Polars query the same exception arrives wrapped in Polars’ ComputeError under py-polars 1.x, carrying its message, and as itself under 2.0: how a query wraps an error is Polars’ to change. A run the bank refuses, or one abandoned before its last row, never replaces a state file. A refused chunk leaves a bank as it was, apart from the two cases ModelBank.fit_predict() names.

See also

The model bank

Run a model bank over a query, a frame or chunks you feed it, and turn the output column it adds into columns, or hand it over as Arrow. Give a target’s output fields a name of your own, or write a target as a formula that looks ahead. Read the compiled extension’s version, the version of the state files it writes, and the number of threads a bank runs on.

rheon.polars.ModelBank

A set of models fitted together over the same rows, fed one chunk at a time.

rheon.polars.fit_predict

Add each spec’s output column to a query’s or a frame’s rows, learning them.

rheon.polars.predict

Predict a query’s or a frame’s rows from a bank as it stands, learning nothing.

rheon.polars.unnest

Turn each spec’s output column in a query or a frame into one column per field.

rheon.target

Name a target column’s output fields after a name of your own.

rheon.Target

A target column under a name of its own, written as a table.

rheon.FormulaTarget

A formula target, written as a table.

rheon.ArrowStruct

One spec’s output column, as an Arrow struct array a consumer reads once.

rheon.thread_pool_size

The number of threads a bank given this threads argument runs on.

rheon.native_version

The version of the compiled extension, which equals rheon.__version__ in a consistent install.

rheon.schema_version

The version of the state file’s layout that this build writes.

Errors

This library’s own errors, each also a subclass of the built-in or Polars class a handler may already catch.

rheon.ColumnNotFoundError

The error raised when a column a call reads is not in its input.

rheon.OutputColumnNotFoundError

The error raised when a spec’s output column is not in the frame a scoring function reads.

rheon.WrongTypeError

The error raised for a value of the wrong type.

rheon.RefusedValueError

The error raised for a refused value.

Warnings

RheonWarning, and the warnings the library issues, each a subclass of it.

rheon.RheonWarning

The base class of every warning this library issues.

rheon.ReadinessWarning

A warning that a model is not ready, or may never become ready.

rheon.polars.OrderNotGuaranteedWarning

A warning that Polars may change the row order of a query a bank or a window run reads.

rheon.polars.ConsumedSourceWarning

A warning that a query whose source is written in Python may give its rows only once.

rheon.RheonDeprecationWarning

A warning that a name still read is on its way out.

rheon.UnstableWarning

A warning that a part of the API not yet promised to stay the same was used.