polars_online.ModelBank.save_bytes

ModelBank.save_bytes() → bytes[source]

The bytes save() writes, for a store that is not a file.

Use it to keep a state in a database or an object store, and read it back with load_bytes(). Pickle and copy.deepcopy carry a bank as these bytes.

Returns

bytes: the state, as save() writes it to a file.

Raises

RuntimeError

A call that learns is in flight on another thread.

ValueError

A refused chunk left the bank unable to go on (fit_predict(), Notes).

UnstableWarning

Under POLARS_ONLINE_WARN_UNSTABLE=1, for a formula target, as save() says.

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])
bank.fit_predict(df)
blob = bank.save_bytes()                     # to keep wherever bytes can be kept
print(po.ModelBank.load_bytes(blob).rows_fed)
400

See also