polars_online.ModelBank.skip_learned¶
- ModelBank.skip_learned(frame: DataFrame) DataFrame[source]¶
- ModelBank.skip_learned(frame: LazyFrame) LazyFrame
The rows of a frame or query that the bank has not learned.
Use it to resume a saved bank on input that overlaps what the bank learned before it was saved, such as a rerun of the day or a file that overlaps the last one. A loaded bank goes on from the next row, so the overlap steps each group’s clock back, which
fit_predict()refuses unlessrestart_after_step_backreads it as a new start. Without a clock in any spec, pass the bank only the rows after the last one it learned.Parameters
frameThe input, a
DataFrameor aLazyFrame, holding each spec’s clock column andgroupcolumn.
Returns
frame’s rows that the bank has not learned, of the same type, in the same order: aLazyFramestays lazy. A row is kept when, in every spec that reads a clock, its clock is after its group’s last clock, its group is one that spec has not seen, or its clock is null. A null clock is left forfit_predict()to judge. A row at its group’s last clock counts as learned.Raises
ValueErrorNo spec reads a clock, so there is no position on a clock to resume from.
WrongTypeErrorA clock column is not a number, a
Date, aDatetimeor aDuration, or a clock is temporal in the frame and was numeric in the bank, or the other way round. It is both aTypeErrorand aValueError.ColumnNotFoundErrorA spec’s clock or group column is not in the frame. It is both a
ValueErrorand Polars’ColumnNotFoundError.TypeErrorframeis neither aDataFramenor aLazyFrame, such as a dict.
Examples
This code reads
dffrom Example data:spec = po.spec.ewridge( "m", targets=["y"], features=["x0"], clock="t", half_life=50.0, gap_cap=10.0 ) saved = po.ModelBank([spec]) saved.fit_predict(df.head(300)) # the stream as far as the save saved.save("bank.state") bank = po.ModelBank.load("bank.state") rerun = df # the whole day again: its first 300 rows overlap out = bank.fit_predict(bank.skip_learned(rerun)) print(f"{out.height} rows learned, from t = {out['t'][0]}")
100 rows learned, from t = 300.0
See also
load(), which loads the saved bank.
Notes
The comparison is exact. A temporal clock is compared in the integer nanoseconds the bank keeps, whatever its unit or time zone, and an integer clock in integers. Since a row at its group’s last clock counts as learned, a stream that repeats a clock value and was saved between two rows with that value loses the later ones.