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, nulls_equal: true) ⇒ 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.
-
#head(n = 5, as_array: false) ⇒ Expr
Get the first
n
elements of 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.
-
#len ⇒ Expr
Return the number of elements in each array.
-
#max ⇒ Expr
Compute the max values of the sub-arrays.
-
#mean ⇒ Expr
Compute the mean of the values of the sub-arrays.
-
#median ⇒ Expr
Compute the median of the values of the sub-arrays.
-
#min ⇒ Expr
Compute the min values of the sub-arrays.
-
#n_unique ⇒ Expr
Count the number of unique values in every sub-arrays.
-
#reverse ⇒ Expr
Reverse the arrays in this column.
-
#shift(n = 1) ⇒ Expr
Shift array values by the given number of indices.
-
#slice(offset, length = nil, as_array: false) ⇒ Expr
Slice every subarray.
-
#sort(descending: false, nulls_last: false) ⇒ Expr
Sort the arrays in this column.
-
#std(ddof: 1) ⇒ Expr
Compute the std of the values of the sub-arrays.
-
#sum ⇒ Expr
Compute the sum values of the sub-arrays.
-
#tail(n = 5, as_array: false) ⇒ Expr
Slice the last
n
values of every sublist. -
#to_list ⇒ Expr
Convert an Array column into a List column with the same inner data type.
-
#to_struct(fields: nil) ⇒ Expr
Convert the Series of type
Array
to a Series of typeStruct
. -
#unique(maintain_order: false) ⇒ Expr
Get the unique/distinct values in the array.
-
#var(ddof: 1) ⇒ Expr
Compute the var of the values of the sub-arrays.
Instance Method Details
#all ⇒ Expr
Evaluate whether all boolean values are true for every subarray.
499 500 501 |
# File 'lib/polars/array_expr.rb', line 499 def all Utils.wrap_expr(_rbexpr.arr_all) end |
#any ⇒ Expr
Evaluate whether any boolean value is true for every subarray.
464 465 466 |
# File 'lib/polars/array_expr.rb', line 464 def any Utils.wrap_expr(_rbexpr.arr_any) end |
#arg_max ⇒ Expr
Retrieve the index of the maximum value in every sub-array.
621 622 623 |
# File 'lib/polars/array_expr.rb', line 621 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.
595 596 597 |
# File 'lib/polars/array_expr.rb', line 595 def arg_min Utils.wrap_expr(_rbexpr.arr_arg_min) end |
#contains(item, nulls_equal: true) ⇒ Expr
Check if sub-arrays contain the given item.
803 804 805 806 |
# File 'lib/polars/array_expr.rb', line 803 def contains(item, nulls_equal: true) item = Utils.parse_into_expression(item, str_as_lit: true) Utils.wrap_expr(_rbexpr.arr_contains(item, nulls_equal)) end |
#count_matches(element) ⇒ Expr
Count how often the value produced by element
occurs.
831 832 833 834 |
# File 'lib/polars/array_expr.rb', line 831 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.
773 774 775 |
# File 'lib/polars/array_expr.rb', line 773 def explode Utils.wrap_expr(_rbexpr.explode) end |
#first ⇒ Expr
Get the first value of the sub-arrays.
683 684 685 |
# File 'lib/polars/array_expr.rb', line 683 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
.
657 658 659 660 |
# File 'lib/polars/array_expr.rb', line 657 def get(index, null_on_oob: true) index = Utils.parse_into_expression(index) Utils.wrap_expr(_rbexpr.arr_get(index, null_on_oob)) end |
#head(n = 5, as_array: false) ⇒ Expr
Get the first n
elements of the sub-arrays.
135 136 137 |
# File 'lib/polars/array_expr.rb', line 135 def head(n = 5, as_array: false) slice(0, n, as_array: as_array) 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
.
745 746 747 748 |
# File 'lib/polars/array_expr.rb', line 745 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.
708 709 710 |
# File 'lib/polars/array_expr.rb', line 708 def last get(-1) end |
#len ⇒ Expr
Return the number of elements in each array.
32 33 34 |
# File 'lib/polars/array_expr.rb', line 32 def len Utils.wrap_expr(_rbexpr.arr_len) end |
#max ⇒ Expr
Compute the max values of the sub-arrays.
231 232 233 |
# File 'lib/polars/array_expr.rb', line 231 def max Utils.wrap_expr(_rbexpr.arr_max) end |
#mean ⇒ Expr
Compute the mean of the values of the sub-arrays.
327 328 329 |
# File 'lib/polars/array_expr.rb', line 327 def mean Utils.wrap_expr(_rbexpr.arr_mean) end |
#median ⇒ Expr
Compute the median of the values of the sub-arrays.
351 352 353 |
# File 'lib/polars/array_expr.rb', line 351 def median Utils.wrap_expr(_rbexpr.arr_median) end |
#min ⇒ Expr
Compute the min values of the sub-arrays.
207 208 209 |
# File 'lib/polars/array_expr.rb', line 207 def min Utils.wrap_expr(_rbexpr.arr_min) end |
#n_unique ⇒ Expr
Count the number of unique values in every sub-arrays.
405 406 407 |
# File 'lib/polars/array_expr.rb', line 405 def n_unique Utils.wrap_expr(_rbexpr.arr_n_unique) end |
#reverse ⇒ Expr
Reverse the arrays in this column.
569 570 571 |
# File 'lib/polars/array_expr.rb', line 569 def reverse Utils.wrap_expr(_rbexpr.arr_reverse) end |
#shift(n = 1) ⇒ Expr
This method is similar to the LAG
operation in SQL when the value for n
is positive. With a negative value for n
, it is similar to LEAD
.
Shift array values by the given number of indices.
913 914 915 916 |
# File 'lib/polars/array_expr.rb', line 913 def shift(n = 1) n = Utils.parse_into_expression(n) Utils.wrap_expr(_rbexpr.arr_shift(n)) end |
#slice(offset, length = nil, as_array: false) ⇒ Expr
Slice every subarray.
82 83 84 85 86 87 88 89 90 |
# File 'lib/polars/array_expr.rb', line 82 def slice( offset, length = nil, as_array: false ) offset = Utils.parse_into_expression(offset) length = !length.nil? ? Utils.parse_into_expression(length) : nil Utils.wrap_expr(_rbexpr.arr_slice(offset, length, as_array)) end |
#sort(descending: false, nulls_last: false) ⇒ Expr
Sort the arrays in this column.
543 544 545 |
# File 'lib/polars/array_expr.rb', line 543 def sort(descending: false, nulls_last: false) Utils.wrap_expr(_rbexpr.arr_sort(descending, nulls_last)) end |
#std(ddof: 1) ⇒ Expr
Compute the std of the values of the sub-arrays.
279 280 281 |
# File 'lib/polars/array_expr.rb', line 279 def std(ddof: 1) Utils.wrap_expr(_rbexpr.arr_std(ddof)) end |
#sum ⇒ Expr
Compute the sum values of the sub-arrays.
255 256 257 |
# File 'lib/polars/array_expr.rb', line 255 def sum Utils.wrap_expr(_rbexpr.arr_sum) end |
#tail(n = 5, as_array: false) ⇒ Expr
Slice the last n
values of every sublist.
182 183 184 185 |
# File 'lib/polars/array_expr.rb', line 182 def tail(n = 5, as_array: false) n = Utils.parse_into_expression(n) Utils.wrap_expr(_rbexpr.arr_tail(n, as_array)) end |
#to_list ⇒ Expr
Convert an Array column into a List column with the same inner data type.
429 430 431 |
# File 'lib/polars/array_expr.rb', line 429 def to_list Utils.wrap_expr(_rbexpr.arr_to_list) end |
#to_struct(fields: nil) ⇒ Expr
Convert the Series of type Array
to a Series of type Struct
.
861 862 863 864 865 866 867 868 869 870 871 |
# File 'lib/polars/array_expr.rb', line 861 def to_struct(fields: nil) raise Todo if fields if fields.is_a?(Enumerable) field_names = fields.to_a rbexpr = _rbexpr.arr_to_struct(nil) Utils.wrap_expr(rbexpr).struct.rename_fields(field_names) else rbexpr = _rbexpr.arr_to_struct(fields) Utils.wrap_expr(rbexpr) end end |
#unique(maintain_order: false) ⇒ Expr
Get the unique/distinct values in the array.
379 380 381 |
# File 'lib/polars/array_expr.rb', line 379 def unique(maintain_order: false) Utils.wrap_expr(_rbexpr.arr_unique(maintain_order)) end |
#var(ddof: 1) ⇒ Expr
Compute the var of the values of the sub-arrays.
303 304 305 |
# File 'lib/polars/array_expr.rb', line 303 def var(ddof: 1) Utils.wrap_expr(_rbexpr.arr_var(ddof)) end |