Class: Polars::ArrayExpr
- Inherits:
-
Object
- Object
- Polars::ArrayExpr
- Defined in:
- lib/polars/array_expr.rb
Overview
Namespace for array related expressions.
Instance Method Summary collapse
-
#all ⇒ Expr
Evaluate whether all boolean values are true for every subarray.
-
#any ⇒ Expr
Evaluate whether any boolean value is true for every subarray.
-
#arg_max ⇒ Expr
Retrieve the index of the maximum value in every sub-array.
-
#arg_min ⇒ Expr
Retrieve the index of the minimal value in every sub-array.
-
#contains(item) ⇒ Expr
Check if sub-arrays contain the given item.
-
#count_matches(element) ⇒ Expr
Count how often the value produced by
element
occurs. -
#explode ⇒ Expr
Returns a column with a separate row for every array element.
-
#first ⇒ Expr
Get the first value of the sub-arrays.
-
#get(index, null_on_oob: true) ⇒ Expr
Get the value by index in the sub-arrays.
-
#join(separator, ignore_nulls: true) ⇒ Expr
Join all string items in a sub-array and place a separator between them.
-
#last ⇒ Expr
Get the last value of the sub-arrays.
-
#max ⇒ Expr
Compute the max values of the sub-arrays.
-
#min ⇒ Expr
Compute the min values of the sub-arrays.
-
#reverse ⇒ Expr
Reverse the arrays in this column.
-
#sort(descending: false, nulls_last: false) ⇒ Expr
Sort the arrays in this column.
-
#sum ⇒ Expr
Compute the sum values of the sub-arrays.
-
#to_list ⇒ Expr
Convert an Array column into a List column with the same inner data type.
-
#unique(maintain_order: false) ⇒ Expr
Get the unique/distinct values in the array.
Instance Method Details
#all ⇒ Expr
Evaluate whether all boolean values are true for every subarray.
202 203 204 |
# File 'lib/polars/array_expr.rb', line 202 def all Utils.wrap_expr(_rbexpr.arr_all) end |
#any ⇒ Expr
Evaluate whether any boolean value is true for every subarray.
167 168 169 |
# File 'lib/polars/array_expr.rb', line 167 def any Utils.wrap_expr(_rbexpr.arr_any) end |
#arg_max ⇒ Expr
Retrieve the index of the maximum value in every sub-array.
324 325 326 |
# File 'lib/polars/array_expr.rb', line 324 def arg_max Utils.wrap_expr(_rbexpr.arr_arg_max) end |
#arg_min ⇒ Expr
Retrieve the index of the minimal value in every sub-array.
298 299 300 |
# File 'lib/polars/array_expr.rb', line 298 def arg_min Utils.wrap_expr(_rbexpr.arr_arg_min) end |
#contains(item) ⇒ Expr
Check if sub-arrays contain the given item.
504 505 506 507 |
# File 'lib/polars/array_expr.rb', line 504 def contains(item) item = Utils.parse_into_expression(item, str_as_lit: true) Utils.wrap_expr(_rbexpr.arr_contains(item)) end |
#count_matches(element) ⇒ Expr
Count how often the value produced by element
occurs.
532 533 534 535 |
# File 'lib/polars/array_expr.rb', line 532 def count_matches(element) element = Utils.parse_into_expression(element, str_as_lit: true) Utils.wrap_expr(_rbexpr.arr_count_matches(element)) end |
#explode ⇒ Expr
Returns a column with a separate row for every array element.
476 477 478 |
# File 'lib/polars/array_expr.rb', line 476 def explode Utils.wrap_expr(_rbexpr.explode) end |
#first ⇒ Expr
Get the first value of the sub-arrays.
386 387 388 |
# File 'lib/polars/array_expr.rb', line 386 def first get(0) end |
#get(index, null_on_oob: true) ⇒ Expr
Get the value by index in the sub-arrays.
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 nil
.
360 361 362 363 |
# File 'lib/polars/array_expr.rb', line 360 def get(index, null_on_oob: true) index = Utils.parse_into_expression(index) Utils.wrap_expr(_rbexpr.arr_get(index, null_on_oob)) end |
#join(separator, ignore_nulls: true) ⇒ Expr
Join all string items in a sub-array and place a separator between them.
This errors if inner type of array != String
.
448 449 450 451 |
# File 'lib/polars/array_expr.rb', line 448 def join(separator, ignore_nulls: true) separator = Utils.parse_into_expression(separator, str_as_lit: true) Utils.wrap_expr(_rbexpr.arr_join(separator, ignore_nulls)) end |
#last ⇒ Expr
Get the last value of the sub-arrays.
411 412 413 |
# File 'lib/polars/array_expr.rb', line 411 def last get(-1) end |
#max ⇒ Expr
Compute the max values of the sub-arrays.
56 57 58 |
# File 'lib/polars/array_expr.rb', line 56 def max Utils.wrap_expr(_rbexpr.array_max) end |
#min ⇒ Expr
Compute the min values of the sub-arrays.
32 33 34 |
# File 'lib/polars/array_expr.rb', line 32 def min Utils.wrap_expr(_rbexpr.array_min) end |
#reverse ⇒ Expr
Reverse the arrays in this column.
272 273 274 |
# File 'lib/polars/array_expr.rb', line 272 def reverse Utils.wrap_expr(_rbexpr.arr_reverse) end |
#sort(descending: false, nulls_last: false) ⇒ Expr
Sort the arrays in this column.
246 247 248 |
# File 'lib/polars/array_expr.rb', line 246 def sort(descending: false, nulls_last: false) Utils.wrap_expr(_rbexpr.arr_sort(descending, nulls_last)) end |
#sum ⇒ Expr
Compute the sum values of the sub-arrays.
80 81 82 |
# File 'lib/polars/array_expr.rb', line 80 def sum Utils.wrap_expr(_rbexpr.array_sum) end |
#to_list ⇒ Expr
Convert an Array column into a List column with the same inner data type.
132 133 134 |
# File 'lib/polars/array_expr.rb', line 132 def to_list Utils.wrap_expr(_rbexpr.arr_to_list) end |
#unique(maintain_order: false) ⇒ Expr
Get the unique/distinct values in the array.
108 109 110 |
# File 'lib/polars/array_expr.rb', line 108 def unique(maintain_order: false) Utils.wrap_expr(_rbexpr.arr_unique(maintain_order)) end |