Sha256: 6072ef5b5816ad2dd3af368d070ba8a9042f955a4c9786c3c1f555441440b2b5

Contents?: true

Size: 1.2 KB

Versions: 30

Compression:

Stored size: 1.2 KB

Contents

module Polars
  # A dynamic grouper.
  #
  # This has an `.agg` method which allows you to run all polars expressions in a
  # group by context.
  class DynamicGroupBy
    def initialize(
      df,
      index_column,
      every,
      period,
      offset,
      truncate,
      include_boundaries,
      closed,
      by,
      start_by
    )
      period = Utils.parse_as_duration_string(period)
      offset = Utils.parse_as_duration_string(offset)
      every = Utils.parse_as_duration_string(every)

      @df = df
      @time_column = index_column
      @every = every
      @period = period
      @offset = offset
      @truncate = truncate
      @include_boundaries = include_boundaries
      @closed = closed
      @by = by
      @start_by = start_by
    end

    def agg(*aggs, **named_aggs)
      @df.lazy
        .group_by_dynamic(
          @time_column,
          every: @every,
          period: @period,
          offset: @offset,
          truncate: @truncate,
          include_boundaries: @include_boundaries,
          closed: @closed,
          by: @by,
          start_by: @start_by
        )
        .agg(*aggs, **named_aggs)
        .collect(no_optimization: true, string_cache: false)
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

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