rheon.polars.unnest¶
- rheon.polars.unnest(frame: LazyFrame, specs: Iterable[dict[str, Any]] | ModelBank | str | PathLike[str], *, separator: str | None = None) LazyFrame[source]¶
- rheon.polars.unnest(frame: DataFrame, specs: Iterable[dict[str, Any]] | ModelBank | str | PathLike[str], *, separator: str | None = None) DataFrame
Turn each spec’s output column in a query or a frame into one column per field.
It is
frame.rheon.unnest(specs)as a plain function, so that a type checker can see it: therheonnamespaces are attached when the package is imported, which a type checker does not follow.Parameters
frameA query, which gives a query (
unnest()), or a frame, which gives a frame (unnest()).specsThe specs whose output columns to unnest: the spec dicts, a bank, or the path of a saved state.
separatorA text to name each column after its spec too, as
{spec}{separator}{name}, as for the namespace method.
Returns
A query for a query, and a frame for a frame, with each output column replaced by its fields, and each
coeflist by one named column per coefficient.Raises
TypeErrorframeis neither a query nor a frame.
Otherwise, what the namespace method raises.
Examples
This code reads
dffrom Example data:spec = rp.spec.ewridge("ridge", targets=["y"], features=["x0", "x1"], half_life=100.0) flat = rp.unnest(df.rheon.fit_predict([spec]), [spec], separator=".") print(flat.select("^ridge.coef_.*$").columns)
['ridge.coef_y_intercept', 'ridge.coef_y_x0', 'ridge.coef_y_x1']
See also
unnest(), the columns it writes, in full.rheon.spec.coef_fields(), each coefficient’s column name.