rheon.polars.ModelBank.fit_predict_arrow

ModelBank.fit_predict_arrow(df: DataFrame) → list[ArrowStruct][source]

Learn a frame’s rows, and return each spec’s output as an Arrow array.

Use it to hand a bank’s output to a library other than Polars, or to take the output through the public Arrow PyCapsule interface, without Polars’ private series boundary (see Notes). For a frame back, use fit_predict(), the same call with the output added to the frame for you.

Warning

The Arrow output (this method, predict_arrow() and ArrowStruct) is unstable: it may change in any release without that counting as a breaking change. Under RHEON_WARN_UNSTABLE=1, each call issues UnstableWarning.

Parameters

df

The next rows of the stream, as one chunk, a Polars DataFrame, as fit_predict() takes it. Only the output is Arrow.

Returns

A list of ArrowStruct, one per spec, in the order of the bank’s specs. Each holds the spec’s output column as an Arrow struct array, with fit_predict()’s values exactly, field for field and null for null, and is named after its spec. A consumer reads it through the Arrow PyCapsule interface (__arrow_c_array__): Polars’ pl.Series, and pyarrow’s pa.array and pa.table. DuckDB reads Arrow streams instead, so give it pl.Series(s). Each struct can be read once (see Notes).

Raises

What fit_predict() raises for the same frame.

UnstableWarning

A warning, not an error: issued by each call under RHEON_WARN_UNSTABLE=1.

Examples

This code reads df from Example data:

spec = rp.spec.ewridge("ridge", targets=["y"], features=["x0", "x1"], half_life=100.0)
bank = rp.ModelBank([spec])
structs = bank.fit_predict_arrow(df)            # one per spec, as Arrow
out = df.with_columns([pl.Series(s) for s in structs])
print(out["ridge"].struct.field("pred_y").count())
396

See also

Notes

A Polars Series crosses from the extension to Python through Polars’ private _export and _import, an interface with no promise of stability, which is why ModelBank needs Polars 1.28.1 or later. The Arrow PyCapsule interface is a public standard, so a consumer of it reads the struct directly. Reading a struct hands its buffers to the consumer, so a second read raises ValueError. The struct’s Arrow field carries its spec’s name, which pl.Series gives the series it builds.