rheon.polars.ModelBank.groups¶
- ModelBank.groups(spec: str | int | None = None) DataFrame[source]¶
The groups the bank holds a model for, one row for each spec and group.
Use it to see which groups a bank has learned, such as a bank loaded from a state file, and to find the groups that have gone quiet, whose models stay in the bank until
drop_groups()removes them.Parameters
specA spec’s name or position, which narrows the table to that spec.
None, the default, lists every spec.
Returns
A
DataFramewith one row for each spec and group, in the bank’s spec order, each spec’s groups sorted by key: integer keys as numbers, text keys as text, the null group first. Its columns:spec,groupThe spec’s name, and the group key as a string:
""for a spec without agroupcolumn, and null for the rows whose key was null. ADatetimekey with a time zone is written as its instant’s UTC wall time.rows_fedThe rows the bank routed to the group, skipped rows included, as
summary()counts them.clock_lastThe group’s last clock value, exactly, in the clock column’s own type: a
Datetimein its unit and time zone, aDate, aDuration, an integer clock in its own width, and aFloat64for a float clock (the typeemit_clocksgivesscored_clock). It is null before the group’s first row, and on a spec without a clock. The column is aFloat64of nulls only when no spec read has a clock.
Raises
KeyErrorspecis a name the bank does not hold. The message lists the names.IndexErrorspecis a position the bank does not hold.ValueErrorspecisNoneand the specs read clocks of different types, which oneclock_lastcolumn cannot hold. Read such a bank one spec at a time.
Examples
This code reads
dffrom Example data:spec = rp.spec.ewridge( "ridge", targets=["y"], features=["x0"], group="stock_id", clock="ts", gap_cap="5m", half_life="1h", ) bank = rp.ModelBank([spec]) bank.fit_predict(df) print(bank.groups()) # the groups with no row in the last 2 minutes of the stream cutoff = pl.lit(df["ts"].max()) - pl.duration(minutes=2) quiet = bank.groups().filter(pl.col("clock_last") < cutoff) print(bank.drop_groups(quiet["group"]))
shape: (4, 4) ┌───────┬───────┬──────────┬─────────────────────┐ │ spec ┆ group ┆ rows_fed ┆ clock_last │ │ --- ┆ --- ┆ --- ┆ --- │ │ str ┆ str ┆ i64 ┆ datetime[μs] │ ╞═══════╪═══════╪══════════╪═════════════════════╡ │ ridge ┆ b0 ┆ 100 ┆ 2024-01-02 16:06:00 │ │ ridge ┆ b1 ┆ 100 ┆ 2024-01-02 16:07:00 │ │ ridge ┆ b2 ┆ 100 ┆ 2024-01-02 16:08:00 │ │ ridge ┆ b3 ┆ 100 ┆ 2024-01-02 16:09:00 │ └───────┴───────┴──────────┴─────────────────────┘ 1
See also
drop_groups(), which removes groups’ models.summary(), which counts each group’s rows by what happened to them.closed_groups(), for the groupsgroup_closeends.