Sha256: 66361dff3c58e37a5a681848898402ca90663d7bbd5af7d48b2b55736b0aff86

Contents?: true

Size: 977 Bytes

Versions: 5

Compression:

Stored size: 977 Bytes

Contents

module Polars
  module Functions
    # Start a "when, then, otherwise" expression.
    #
    # @return [When]
    #
    # @example
    #   df = Polars::DataFrame.new({"foo" => [1, 3, 4], "bar" => [3, 4, 0]})
    #   df.with_column(Polars.when(Polars.col("foo") > 2).then(Polars.lit(1)).otherwise(Polars.lit(-1)))
    #   # =>
    #   # shape: (3, 3)
    #   # ┌─────┬─────┬─────────┐
    #   # │ foo ┆ bar ┆ literal │
    #   # │ --- ┆ --- ┆ ---     │
    #   # │ i64 ┆ i64 ┆ i32     │
    #   # ╞═════╪═════╪═════════╡
    #   # │ 1   ┆ 3   ┆ -1      │
    #   # │ 3   ┆ 4   ┆ 1       │
    #   # │ 4   ┆ 0   ┆ 1       │
    #   # └─────┴─────┴─────────┘
    def when(expr)
      expr = Utils.expr_to_lit_or_expr(expr)
      pw = Plr.when(expr._rbexpr)
      When.new(pw)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
polars-df-0.9.0-x86_64-linux lib/polars/functions/whenthen.rb
polars-df-0.9.0-x86_64-darwin lib/polars/functions/whenthen.rb
polars-df-0.9.0-arm64-darwin lib/polars/functions/whenthen.rb
polars-df-0.9.0-aarch64-linux lib/polars/functions/whenthen.rb
polars-df-0.9.0 lib/polars/functions/whenthen.rb