Sha256: de79e381bef19464352ea02256279384c6c131f91067aa2217779e4e5c4435f4

Contents?: true

Size: 1.43 KB

Versions: 30

Compression:

Stored size: 1.43 KB

Contents

module Polars
  module Functions
    # Create a range expression (or Series).
    #
    # This can be used in a `select`, `with_column`, etc. Be sure that the resulting
    # range size is equal to the length of the DataFrame you are collecting.
    #
    # @param start [Integer, Expr, Series]
    #   Lower bound of range.
    # @param stop [Integer, Expr, Series]
    #   Upper bound of range.
    # @param step [Integer]
    #   Step size of the range.
    # @param eager [Boolean]
    #   If eager evaluation is `True`, a Series is returned instead of an Expr.
    # @param dtype [Symbol]
    #   Apply an explicit integer dtype to the resulting expression (default is `Int64`).
    #
    # @return [Expr, Series]
    #
    # @example
    #   Polars.arange(0, 3, eager: true)
    #   # =>
    #   # shape: (3,)
    #   # Series: 'arange' [i64]
    #   # [
    #   #         0
    #   #         1
    #   #         2
    #   # ]
    def int_range(start, stop = nil, step: 1, eager: false, dtype: nil)
      if stop.nil?
        stop = start
        start = 0
      end

      start = Utils.parse_into_expression(start)
      stop = Utils.parse_into_expression(stop)
      dtype ||= Int64
      dtype = dtype.to_s if dtype.is_a?(Symbol)
      result = Utils.wrap_expr(Plr.int_range(start, stop, step, dtype)).alias("arange")

      if eager
        return select(result).to_series
      end

      result
    end
    alias_method :arange, :int_range
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
polars-df-0.15.0-x86_64-linux lib/polars/functions/range/int_range.rb
polars-df-0.15.0-x86_64-linux-musl lib/polars/functions/range/int_range.rb
polars-df-0.15.0-x86_64-darwin lib/polars/functions/range/int_range.rb
polars-df-0.15.0-x64-mingw-ucrt lib/polars/functions/range/int_range.rb
polars-df-0.15.0-arm64-darwin lib/polars/functions/range/int_range.rb
polars-df-0.15.0-aarch64-linux lib/polars/functions/range/int_range.rb
polars-df-0.15.0-aarch64-linux-musl lib/polars/functions/range/int_range.rb
polars-df-0.15.0 lib/polars/functions/range/int_range.rb
polars-df-0.14.0-x86_64-linux lib/polars/functions/range/int_range.rb
polars-df-0.14.0-x86_64-linux-musl lib/polars/functions/range/int_range.rb
polars-df-0.14.0-x86_64-darwin lib/polars/functions/range/int_range.rb
polars-df-0.14.0-x64-mingw-ucrt lib/polars/functions/range/int_range.rb
polars-df-0.14.0-arm64-darwin lib/polars/functions/range/int_range.rb
polars-df-0.14.0-aarch64-linux lib/polars/functions/range/int_range.rb
polars-df-0.14.0-aarch64-linux-musl lib/polars/functions/range/int_range.rb
polars-df-0.14.0 lib/polars/functions/range/int_range.rb
polars-df-0.13.0-x86_64-linux lib/polars/functions/range/int_range.rb
polars-df-0.13.0-x86_64-linux-musl lib/polars/functions/range/int_range.rb
polars-df-0.13.0-x86_64-darwin lib/polars/functions/range/int_range.rb
polars-df-0.13.0-x64-mingw-ucrt lib/polars/functions/range/int_range.rb