Method: Polars::Expr#to_physical

Defined in:
lib/polars/expr.rb

#to_physicalExpr

Cast to physical representation of the logical dtype.

  • :date -> :i32
  • :datetime -> :i64
  • :time -> :i64
  • :duration -> :i64
  • :cat -> :u32
  • Other data types will be left unchanged.

Examples:

Polars::DataFrame.new({"vals" => ["a", "x", nil, "a"]}).with_columns(
  [
    Polars.col("vals").cast(:cat),
    Polars.col("vals")
      .cast(:cat)
      .to_physical
      .alias("vals_physical")
  ]
)
# =>
# shape: (4, 2)
# ┌──────┬───────────────┐
# │ vals ┆ vals_physical │
# │ ---  ┆ ---           │
# │ cat  ┆ u32           │
# ╞══════╪═══════════════╡
# │ a    ┆ 0             │
# │ x    ┆ 1             │
# │ null ┆ null          │
# │ a    ┆ 0             │
# └──────┴───────────────┘

Returns:

[View source]

178
179
180
# File 'lib/polars/expr.rb', line 178

def to_physical
  _from_rbexpr(_rbexpr.to_physical)
end