polars_online.ArrowStruct

class polars_online.ArrowStruct

Bases: object

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

Use it to read a bank’s output without Polars, from ModelBank.fit_predict_arrow and ModelBank.predict_arrow, which return one per spec. For the output as Polars columns, use ModelBank.fit_predict and ModelBank.predict.

Warning

The Arrow output is unstable: it may change in any release without that counting as a breaking change. Its input still arrives as a Polars frame, since the path that would take Arrow in is not built, so the pair is not yet in its final form. Under POLARS_ONLINE_WARN_UNSTABLE=1, the calls that return one issue polars_online.UnstableWarning.

Examples

This code reads df from Example data:

spec = po.spec.ewridge("ridge", targets=["y"], features=["x0", "x1"], half_life=100.0)
bank = po.ModelBank([spec])
(struct,) = bank.fit_predict_arrow(df)        # one ArrowStruct per spec
column = pl.Series(struct.name, struct)        # read once, through __arrow_c_array__
print(struct.name, column.len())
ridge 400

See also

  • ModelBank.fit_predict_arrow and ModelBank.predict_arrow, which return it.

Notes

A consumer, such as pl.Series or pyarrow’s pa.array, calls __arrow_c_array__ and takes ownership of the two C structures it returns. DuckDB reads only __arrow_c_stream__, so give it pl.Series(struct). Reading the array hands its buffers to the consumer, so a second read raises ValueError rather than hand out buffers already given away.

name

The spec this struct is the output of. The capsule carries the field name, but pl.Series(obj) does not read it, so the caller names the series itself.