polars.Expr.keep_name#

Expr.keep_name() Self[source]#

Keep the original root name of the expression.

Deprecated since version 0.19.12: This method has been renamed to name.keep().

See also

alias

Notes

Due to implementation constraints, this method can only be called as the last expression in a chain.

Examples

Undo an alias operation.

>>> df = pl.DataFrame(
...     {
...         "a": [1, 2],
...         "b": [3, 4],
...     }
... )
>>> df.with_columns((pl.col("a") * 9).alias("c").name.keep())
shape: (2, 2)
┌─────┬─────┐
│ a   ┆ b   │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 9   ┆ 3   │
│ 18  ┆ 4   │
└─────┴─────┘

Prevent errors due to duplicate column names.

>>> df.select((pl.lit(10) / pl.all()).name.keep())
shape: (2, 2)
┌──────┬──────────┐
│ a    ┆ b        │
│ ---  ┆ ---      │
│ f64  ┆ f64      │
╞══════╪══════════╡
│ 10.0 ┆ 3.333333 │
│ 5.0  ┆ 2.5      │
└──────┴──────────┘