rheon.polars.ModelBank.load_bytes

classmethod ModelBank.load_bytes(data: bytes, specs: Iterable[dict[str, Any]] | None = None, *, threads: int | None = None) → ModelBank[source]

Load a bank from the bytes save_bytes() gave.

Use it for a state kept in a store that is not a file. load() takes bytes as well, with the same checks.

Parameters

data

The bytes save_bytes() returned, or a bytearray or memoryview of them.

specs

The specs you expect the bytes to hold, checked as load() checks them. None, the default, takes their specs unchecked.

threads

The loaded bank’s threads, as ModelBank takes it.

Returns

A ModelBank holding the saved state.

Raises

ValueError and TypeError

As load() raises them, for bytes that are not a bank this build loads, and for a threads it refuses. TypeError also when data is not bytes, a bytearray or a memoryview.

UnstableWarning

Under RHEON_WARN_UNSTABLE=1, for bytes holding a formula target, as save() says.

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])
bank.fit_predict(df)
again = rp.ModelBank.load_bytes(bank.save_bytes(), specs=[spec])
print(again.rows_fed)
400

See also