Sha256: 91099bfd8245d5d6ed61e46a3b4190fba4d902e17f1994d453d9477319b584a5

Contents?: true

Size: 911 Bytes

Versions: 6

Compression:

Stored size: 911 Bytes

Contents

module Polars
  # A rolling grouper.
  #
  # This has an `.agg` method which will allow you to run all polars expressions in a
  # group by context.
  class RollingGroupBy
    def initialize(
      df,
      index_column,
      period,
      offset,
      closed,
      by,
      check_sorted
    )
      period = Utils._timedelta_to_pl_duration(period)
      offset = Utils._timedelta_to_pl_duration(offset)

      @df = df
      @time_column = index_column
      @period = period
      @offset = offset
      @closed = closed
      @by = by
      @check_sorted = check_sorted
    end

    def agg(*aggs, **named_aggs)
      @df.lazy
        .group_by_rolling(
          index_column: @time_column, period: @period, offset: @offset, closed: @closed, by: @by, check_sorted: @check_sorted
        )
        .agg(*aggs, **named_aggs)
        .collect(no_optimization: true, string_cache: false)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
polars-df-0.11.0-x86_64-linux lib/polars/rolling_group_by.rb
polars-df-0.11.0-x86_64-linux-musl lib/polars/rolling_group_by.rb
polars-df-0.11.0-x86_64-darwin lib/polars/rolling_group_by.rb
polars-df-0.11.0-arm64-darwin lib/polars/rolling_group_by.rb
polars-df-0.11.0-aarch64-linux lib/polars/rolling_group_by.rb
polars-df-0.11.0 lib/polars/rolling_group_by.rb