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: the rheon namespaces are attached when the package is imported, which a type checker does not follow.

Parameters

frame

A query, which gives a query (unnest()), or a frame, which gives a frame (unnest()).

specs

The specs whose output columns to unnest: the spec dicts, a bank, or the path of a saved state.

separator

A 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 coef list by one named column per coefficient.

Raises

TypeError

frame is neither a query nor a frame.

Otherwise, what the namespace method raises.

Examples

This code reads df from 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