Class: Polars::ListExpr
- Inherits:
-
Object
- Object
- Polars::ListExpr
- Defined in:
- lib/polars/list_expr.rb
Overview
Namespace for list related expressions.
Instance Method Summary collapse
-
#[](item) ⇒ Expr
Get the value by index in the sublists.
-
#arg_max ⇒ Expr
Retrieve the index of the maximum value in every sublist.
-
#arg_min ⇒ Expr
Retrieve the index of the minimal value in every sublist.
-
#concat(other) ⇒ Expr
Concat the arrays in a Series dtype List in linear time.
-
#contains(item) ⇒ Expr
Check if sublists contain the given item.
-
#diff(n: 1, null_behavior: "ignore") ⇒ Expr
Calculate the n-th discrete difference of every sublist.
-
#eval(expr, parallel: false) ⇒ Expr
Run any polars expression against the lists' elements.
-
#first ⇒ Expr
Get the first value of the sublists.
-
#get(index) ⇒ Expr
Get the value by index in the sublists.
-
#head(n = 5) ⇒ Expr
Slice the first
n
values of every sublist. -
#join(separator) ⇒ Expr
Join all string items in a sublist and place a separator between them.
-
#last ⇒ Expr
Get the last value of the sublists.
-
#lengths ⇒ Expr
Get the length of the arrays as
:u32
. -
#max ⇒ Expr
Compute the max value of the lists in the array.
-
#mean ⇒ Expr
Compute the mean value of the lists in the array.
-
#min ⇒ Expr
Compute the min value of the lists in the array.
-
#reverse ⇒ Expr
Reverse the arrays in the list.
-
#shift(periods = 1) ⇒ Expr
Shift values by the given period.
-
#slice(offset, length = nil) ⇒ Expr
Slice every sublist.
-
#sort(reverse: false) ⇒ Expr
Sort the arrays in the list.
-
#sum ⇒ Expr
Sum all the lists in the array.
-
#tail(n = 5) ⇒ Expr
Slice the last
n
values of every sublist. -
#to_struct(n_field_strategy: "first_non_null", name_generator: nil) ⇒ Expr
Convert the series of type
List
to a series of typeStruct
. -
#unique ⇒ Expr
Get the unique/distinct values in the list.
Instance Method Details
#[](item) ⇒ Expr
Get the value by index in the sublists.
274 275 276 |
# File 'lib/polars/list_expr.rb', line 274 def [](item) get(item) end |
#arg_max ⇒ Expr
Retrieve the index of the maximum value in every sublist.
428 429 430 |
# File 'lib/polars/list_expr.rb', line 428 def arg_max Utils.wrap_expr(_rbexpr.lst_arg_max) end |
#arg_min ⇒ Expr
Retrieve the index of the minimal value in every sublist.
402 403 404 |
# File 'lib/polars/list_expr.rb', line 402 def arg_min Utils.wrap_expr(_rbexpr.lst_arg_min) end |
#concat(other) ⇒ Expr
Concat the arrays in a Series dtype List in linear time.
224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/polars/list_expr.rb', line 224 def concat(other) if other.is_a?(Array) && ![Expr, String, Series].any? { |c| other[0].is_a?(c) } return concat(Series.new([other])) end if !other.is_a?(Array) other_list = [other] else other_list = other.dup end other_list.insert(0, Utils.wrap_expr(_rbexpr)) Polars.concat_list(other_list) end |
#contains(item) ⇒ Expr
Check if sublists contain the given item.
349 350 351 |
# File 'lib/polars/list_expr.rb', line 349 def contains(item) Utils.wrap_expr(_rbexpr.arr_contains(Utils.expr_to_lit_or_expr(item)._rbexpr)) end |
#diff(n: 1, null_behavior: "ignore") ⇒ Expr
Calculate the n-th discrete difference of every sublist.
451 452 453 |
# File 'lib/polars/list_expr.rb', line 451 def diff(n: 1, null_behavior: "ignore") Utils.wrap_expr(_rbexpr.lst_diff(n, null_behavior)) end |
#eval(expr, parallel: false) ⇒ Expr
Run any polars expression against the lists' elements.
606 607 608 |
# File 'lib/polars/list_expr.rb', line 606 def eval(expr, parallel: false) Utils.wrap_expr(_rbexpr.lst_eval(expr._rbexpr, parallel)) end |
#first ⇒ Expr
Get the first value of the sublists.
298 299 300 |
# File 'lib/polars/list_expr.rb', line 298 def first get(0) end |
#get(index) ⇒ Expr
Get the value by index in the sublists.
So index 0
would return the first item of every sublist
and index -1
would return the last item of every sublist
if an index is out of bounds, it will return a None
.
266 267 268 269 |
# File 'lib/polars/list_expr.rb', line 266 def get(index) index = Utils.expr_to_lit_or_expr(index, str_to_lit: false)._rbexpr Utils.wrap_expr(_rbexpr.lst_get(index)) end |
#head(n = 5) ⇒ Expr
Slice the first n
values of every sublist.
519 520 521 |
# File 'lib/polars/list_expr.rb', line 519 def head(n = 5) slice(0, n) end |
#join(separator) ⇒ Expr
Join all string items in a sublist and place a separator between them.
This errors if inner type of list != :str
.
376 377 378 |
# File 'lib/polars/list_expr.rb', line 376 def join(separator) Utils.wrap_expr(_rbexpr.lst_join(separator)) end |
#last ⇒ Expr
Get the last value of the sublists.
322 323 324 |
# File 'lib/polars/list_expr.rb', line 322 def last get(-1) end |
#lengths ⇒ Expr
Get the length of the arrays as :u32
.
30 31 32 |
# File 'lib/polars/list_expr.rb', line 30 def lengths Utils.wrap_expr(_rbexpr.arr_lengths) end |
#max ⇒ Expr
Compute the max value of the lists in the array.
74 75 76 |
# File 'lib/polars/list_expr.rb', line 74 def max Utils.wrap_expr(_rbexpr.lst_max) end |
#mean ⇒ Expr
Compute the mean value of the lists in the array.
118 119 120 |
# File 'lib/polars/list_expr.rb', line 118 def mean Utils.wrap_expr(_rbexpr.lst_mean) end |
#min ⇒ Expr
Compute the min value of the lists in the array.
96 97 98 |
# File 'lib/polars/list_expr.rb', line 96 def min Utils.wrap_expr(_rbexpr.lst_min) end |
#reverse ⇒ Expr
Reverse the arrays in the list.
170 171 172 |
# File 'lib/polars/list_expr.rb', line 170 def reverse Utils.wrap_expr(_rbexpr.lst_reverse) end |
#shift(periods = 1) ⇒ Expr
Shift values by the given period.
472 473 474 |
# File 'lib/polars/list_expr.rb', line 472 def shift(periods = 1) Utils.wrap_expr(_rbexpr.lst_shift(periods)) end |
#slice(offset, length = nil) ⇒ Expr
Slice every sublist.
496 497 498 499 500 |
# File 'lib/polars/list_expr.rb', line 496 def slice(offset, length = nil) offset = Utils.expr_to_lit_or_expr(offset, str_to_lit: false)._rbexpr length = Utils.expr_to_lit_or_expr(length, str_to_lit: false)._rbexpr Utils.wrap_expr(_rbexpr.lst_slice(offset, length)) end |
#sort(reverse: false) ⇒ Expr
Sort the arrays in the list.
144 145 146 |
# File 'lib/polars/list_expr.rb', line 144 def sort(reverse: false) Utils.wrap_expr(_rbexpr.lst_sort(reverse)) end |
#sum ⇒ Expr
Sum all the lists in the array.
52 53 54 |
# File 'lib/polars/list_expr.rb', line 52 def sum Utils.wrap_expr(_rbexpr.lst_sum) end |
#tail(n = 5) ⇒ Expr
Slice the last n
values of every sublist.
540 541 542 543 |
# File 'lib/polars/list_expr.rb', line 540 def tail(n = 5) offset = -Utils.expr_to_lit_or_expr(n, str_to_lit: false) slice(offset, n) end |
#to_struct(n_field_strategy: "first_non_null", name_generator: nil) ⇒ Expr
Convert the series of type List
to a series of type Struct
.
569 570 571 572 |
# File 'lib/polars/list_expr.rb', line 569 def to_struct(n_field_strategy: "first_non_null", name_generator: nil) raise Todo if name_generator Utils.wrap_expr(_rbexpr.lst_to_struct(n_field_strategy, name_generator, 0)) end |
#unique ⇒ Expr
Get the unique/distinct values in the list.
194 195 196 |
# File 'lib/polars/list_expr.rb', line 194 def unique Utils.wrap_expr(_rbexpr.lst_unique) end |