Method: Polars::NameExpr#keep

Defined in:
lib/polars/name_expr.rb

#keepExpr

Note:

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

Keep the original root name of the expression.

Examples:

Prevent errors due to potential duplicate column names.

df = Polars::DataFrame.new(
  {
    "a" => [1, 2],
    "b" => [3, 4]
  }
)
df.select((Polars.lit(10) / Polars.all).name.keep)
# =>
# shape: (2, 2)
# ┌──────┬──────────┐
# │ a    ┆ b        │
# │ ---  ┆ ---      │
# │ f64  ┆ f64      │
# ╞══════╪══════════╡
# │ 10.0 ┆ 3.333333 │
# │ 5.0  ┆ 2.5      │
# └──────┴──────────┘

Undo an alias operation.

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

Returns:



51
52
53
# File 'lib/polars/name_expr.rb', line 51

def keep
  Utils.wrap_expr(_rbexpr.name_keep)
end