Sha256: d0f5ba7e0450e95467ff074349d5600c43362131c03ae7ddcd21c96ce4636f26

Contents?: true

Size: 1.14 KB

Versions: 17

Compression:

Stored size: 1.14 KB

Contents

module Polars
  module Functions
    # Return an expression representing a literal value.
    #
    # @return [Expr]
    def lit(value, dtype: nil, allow_object: nil)
      if value.is_a?(::Time) || value.is_a?(::DateTime)
        time_unit = dtype&.time_unit || "ns"
        time_zone = dtype.&time_zone
        e = lit(Utils._datetime_to_pl_timestamp(value, time_unit)).cast(Datetime.new(time_unit))
        if time_zone
          return e.dt.replace_time_zone(time_zone.to_s)
        else
          return e
        end
      elsif value.is_a?(::Date)
        return lit(::Time.utc(value.year, value.month, value.day)).cast(Date)
      elsif value.is_a?(Polars::Series)
        name = value.name
        value = value._s
        e = Utils.wrap_expr(Plr.lit(value, allow_object))
        if name == ""
          return e
        end
        return e.alias(name)
      elsif (defined?(Numo::NArray) && value.is_a?(Numo::NArray)) || value.is_a?(::Array)
        return lit(Series.new("", value))
      elsif dtype
        return Utils.wrap_expr(Plr.lit(value, allow_object)).cast(dtype)
      end

      Utils.wrap_expr(Plr.lit(value, allow_object))
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
polars-df-0.11.0-x86_64-linux lib/polars/functions/lit.rb
polars-df-0.11.0-x86_64-linux-musl lib/polars/functions/lit.rb
polars-df-0.11.0-x86_64-darwin lib/polars/functions/lit.rb
polars-df-0.11.0-arm64-darwin lib/polars/functions/lit.rb
polars-df-0.11.0-aarch64-linux lib/polars/functions/lit.rb
polars-df-0.11.0 lib/polars/functions/lit.rb
polars-df-0.10.0-x86_64-linux lib/polars/functions/lit.rb
polars-df-0.10.0-x86_64-linux-musl lib/polars/functions/lit.rb
polars-df-0.10.0-x86_64-darwin lib/polars/functions/lit.rb
polars-df-0.10.0-arm64-darwin lib/polars/functions/lit.rb
polars-df-0.10.0-aarch64-linux lib/polars/functions/lit.rb
polars-df-0.10.0 lib/polars/functions/lit.rb
polars-df-0.9.0-x86_64-linux lib/polars/functions/lit.rb
polars-df-0.9.0-x86_64-darwin lib/polars/functions/lit.rb
polars-df-0.9.0-arm64-darwin lib/polars/functions/lit.rb
polars-df-0.9.0-aarch64-linux lib/polars/functions/lit.rb
polars-df-0.9.0 lib/polars/functions/lit.rb