Class: Polars::RollingGroupBy

Inherits:
Object
  • Object
show all
Defined in:
lib/polars/rolling_group_by.rb

Overview

A rolling grouper.

This has an .agg method which will allow you to run all polars expressions in a group by context.

Instance Method Summary collapse

Constructor Details

#initialize(df, index_column, period, offset, closed, group_by) ⇒ RollingGroupBy

Returns a new instance of RollingGroupBy.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/polars/rolling_group_by.rb', line 7

def initialize(
  df,
  index_column,
  period,
  offset,
  closed,
  group_by
)
  period = Utils.parse_as_duration_string(period)
  offset = Utils.parse_as_duration_string(offset)

  @df = df
  @time_column = index_column
  @period = period
  @offset = offset
  @closed = closed
  @group_by = group_by
end

Instance Method Details

#agg(*aggs, **named_aggs) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/polars/rolling_group_by.rb', line 26

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