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, by, check_sorted) ⇒ 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
25
26
# File 'lib/polars/rolling_group_by.rb', line 7

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

Instance Method Details

#agg(aggs) ⇒ Object



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

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