Class: Polars::Expr
- Inherits:
-
Object
- Object
- Polars::Expr
- Defined in:
- lib/polars/expr.rb
Overview
Expressions that can be used in various contexts.
Instance Method Summary collapse
-
#! ⇒ Expr
Performs boolean not.
-
#!=(other) ⇒ Expr
Not equal.
-
#%(other) ⇒ Expr
Returns the modulo.
-
#&(other) ⇒ Expr
Bitwise AND.
-
#*(other) ⇒ Expr
Performs multiplication.
-
#**(power) ⇒ Expr
Raises to the power of exponent.
-
#+(other) ⇒ Expr
Performs addition.
-
#-(other) ⇒ Expr
Performs subtraction.
-
#-@ ⇒ Expr
Performs negation.
-
#/(other) ⇒ Expr
Performs division.
-
#<(other) ⇒ Expr
Less than.
-
#<=(other) ⇒ Expr
Less than or equal.
-
#==(other) ⇒ Expr
Equal.
-
#>(other) ⇒ Expr
Greater than.
-
#>=(other) ⇒ Expr
Greater than or equal.
-
#^(other) ⇒ Expr
Bitwise XOR.
-
#_hash(seed = 0, seed_1 = nil, seed_2 = nil, seed_3 = nil) ⇒ Expr
Hash the elements in the selection.
-
#abs ⇒ Expr
Compute absolute values.
-
#agg_groups ⇒ Expr
Get the group indexes of the group by operation.
-
#alias(name) ⇒ Expr
Rename the output of an expression.
-
#all(drop_nulls: true) ⇒ Boolean
Check if all boolean values in a Boolean column are
true. -
#any(drop_nulls: true) ⇒ Boolean
Check if any boolean value in a Boolean column is
true. -
#append(other, upcast: true) ⇒ Expr
Append expressions.
-
#approx_unique ⇒ Expr
Approx count unique values.
-
#arccos ⇒ Expr
Compute the element-wise value for the inverse cosine.
-
#arccosh ⇒ Expr
Compute the element-wise value for the inverse hyperbolic cosine.
-
#arcsin ⇒ Expr
Compute the element-wise value for the inverse sine.
-
#arcsinh ⇒ Expr
Compute the element-wise value for the inverse hyperbolic sine.
-
#arctan ⇒ Expr
Compute the element-wise value for the inverse tangent.
-
#arctanh ⇒ Expr
Compute the element-wise value for the inverse hyperbolic tangent.
-
#arg_max ⇒ Expr
Get the index of the maximal value.
-
#arg_min ⇒ Expr
Get the index of the minimal value.
-
#arg_sort(reverse: false, nulls_last: false) ⇒ Expr
Get the index values that would sort this column.
-
#arg_unique ⇒ Expr
Get index of first unique value.
-
#argsort(reverse: false, nulls_last: false) ⇒ expr
Get the index values that would sort this column.
-
#arr ⇒ ArrayExpr
Create an object namespace of all array related methods.
-
#backward_fill(limit: nil) ⇒ Expr
Fill missing values with the next to be seen values.
-
#bin ⇒ BinaryExpr
Create an object namespace of all binary related methods.
-
#bottom_k(k: 5) ⇒ Expr
Return the
ksmallest elements. -
#cast(dtype, strict: true) ⇒ Expr
Cast between data types.
-
#cat ⇒ CatExpr
Create an object namespace of all categorical related methods.
-
#ceil ⇒ Expr
Rounds up to the nearest integer value.
-
#clip(lower_bound, upper_bound) ⇒ Expr
Set values outside the given boundaries to the boundary value.
-
#clip_max(upper_bound) ⇒ Expr
Clip (limit) the values in an array to a
maxboundary. -
#clip_min(lower_bound) ⇒ Expr
Clip (limit) the values in an array to a
minboundary. -
#cos ⇒ Expr
Compute the element-wise value for the cosine.
-
#cosh ⇒ Expr
Compute the element-wise value for the hyperbolic cosine.
-
#count ⇒ Expr
Count the number of values in this expression.
-
#cum_count(reverse: false) ⇒ Expr
(also: #cumcount)
Get an array with the cumulative count computed at every element.
-
#cum_max(reverse: false) ⇒ Expr
(also: #cummax)
Get an array with the cumulative max computed at every element.
-
#cum_min(reverse: false) ⇒ Expr
(also: #cummin)
Get an array with the cumulative min computed at every element.
-
#cum_prod(reverse: false) ⇒ Expr
(also: #cumprod)
Get an array with the cumulative product computed at every element.
-
#cum_sum(reverse: false) ⇒ Expr
(also: #cumsum)
Get an array with the cumulative sum computed at every element.
-
#cumulative_eval(expr, min_periods: 1, parallel: false) ⇒ Expr
Run an expression over a sliding window that increases
1slot every iteration. -
#cut(breaks, labels: nil, left_closed: false, include_breaks: false) ⇒ Expr
Bin continuous values into discrete categories.
-
#diff(n: 1, null_behavior: "ignore") ⇒ Expr
Calculate the n-th discrete difference.
-
#dot(other) ⇒ Expr
Compute the dot/inner product between two Expressions.
-
#drop_nans ⇒ Expr
Drop floating point NaN values.
-
#drop_nulls ⇒ Expr
Drop null values.
-
#dt ⇒ DateTimeExpr
Create an object namespace of all datetime related methods.
-
#entropy(base: 2, normalize: true) ⇒ Expr
Computes the entropy.
-
#ewm_mean(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, min_periods: 1, ignore_nulls: true) ⇒ Expr
Exponentially-weighted moving average.
-
#ewm_std(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_periods: 1, ignore_nulls: true) ⇒ Expr
Exponentially-weighted moving standard deviation.
-
#ewm_var(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_periods: 1, ignore_nulls: true) ⇒ Expr
Exponentially-weighted moving variance.
-
#exclude(columns) ⇒ Expr
Exclude certain columns from a wildcard/regex selection.
-
#exp ⇒ Expr
Compute the exponential, element-wise.
-
#explode ⇒ Expr
Explode a list or utf8 Series.
-
#extend_constant(value, n) ⇒ Expr
Extend the Series with given number of values.
-
#fill_nan(fill_value) ⇒ Expr
Fill floating point NaN value with a fill value.
-
#fill_null(value = nil, strategy: nil, limit: nil) ⇒ Expr
Fill null values using the specified value or strategy.
-
#filter(predicate) ⇒ Expr
Filter a single column.
-
#first ⇒ Expr
Get the first value.
-
#flatten ⇒ Expr
Explode a list or utf8 Series.
-
#floor ⇒ Expr
Rounds down to the nearest integer value.
-
#floordiv(other) ⇒ Expr
Performs floor division.
-
#forward_fill(limit: nil) ⇒ Expr
Fill missing values with the latest seen values.
-
#gather(indices) ⇒ Expr
(also: #take)
Take values by index.
-
#gather_every(n, offset = 0) ⇒ Expr
(also: #take_every)
Take every nth value in the Series and return as a new Series.
-
#head(n = 10) ⇒ Expr
Get the first
nrows. -
#implode ⇒ Expr
Aggregate to list.
-
#interpolate(method: "linear") ⇒ Expr
Fill nulls with linear interpolation over missing values.
-
#is_between(start, _end, closed: "both") ⇒ Expr
Check if this expression is between start and end.
-
#is_duplicated ⇒ Expr
Get mask of duplicated values.
-
#is_finite ⇒ Expr
Returns a boolean Series indicating which values are finite.
-
#is_first_distinct ⇒ Expr
(also: #is_first)
Get a mask of the first unique value.
-
#is_in(other) ⇒ Expr
(also: #in?)
Check if elements of this expression are present in the other Series.
-
#is_infinite ⇒ Expr
Returns a boolean Series indicating which values are infinite.
-
#is_nan ⇒ Expr
Returns a boolean Series indicating which values are NaN.
-
#is_not ⇒ Expr
Negate a boolean expression.
-
#is_not_nan ⇒ Expr
Returns a boolean Series indicating which values are not NaN.
-
#is_not_null ⇒ Expr
Returns a boolean Series indicating which values are not null.
-
#is_null ⇒ Expr
Returns a boolean Series indicating which values are null.
-
#is_unique ⇒ Expr
Get mask of unique values.
-
#keep_name ⇒ Expr
Keep the original root name of the expression.
-
#kurtosis(fisher: true, bias: true) ⇒ Expr
Compute the kurtosis (Fisher or Pearson) of a dataset.
-
#last ⇒ Expr
Get the last value.
-
#len ⇒ Expr
(also: #length)
Count the number of values in this expression.
-
#limit(n = 10) ⇒ Expr
Get the first
nrows. -
#list ⇒ ListExpr
Create an object namespace of all list related methods.
-
#log(base = Math::E) ⇒ Expr
Compute the logarithm to a given base.
-
#log10 ⇒ Expr
Compute the base 10 logarithm of the input array, element-wise.
-
#lower_bound ⇒ Expr
Calculate the lower bound.
-
#map_alias(&f) ⇒ Expr
Rename the output of an expression by mapping a function over the root name.
-
#max ⇒ Expr
Get maximum value.
-
#mean ⇒ Expr
Get mean value.
-
#median ⇒ Expr
Get median value using linear interpolation.
-
#meta ⇒ MetaExpr
Create an object namespace of all meta related expression methods.
-
#min ⇒ Expr
Get minimum value.
-
#mode ⇒ Expr
Compute the most occurring value(s).
-
#n_unique ⇒ Expr
Count unique values.
-
#name ⇒ NameExpr
Create an object namespace of all expressions that modify expression names.
-
#nan_max ⇒ Expr
Get maximum value, but propagate/poison encountered NaN values.
-
#nan_min ⇒ Expr
Get minimum value, but propagate/poison encountered NaN values.
-
#null_count ⇒ Expr
Count null values.
-
#over(expr) ⇒ Expr
Apply window function over a subgroup.
-
#pct_change(n: 1) ⇒ Expr
Computes percentage change between values.
-
#peak_max ⇒ Expr
Get a boolean mask of the local maximum peaks.
-
#peak_min ⇒ Expr
Get a boolean mask of the local minimum peaks.
-
#pow(exponent) ⇒ Expr
Raise expression to the power of exponent.
-
#prefix(prefix) ⇒ Expr
Add a prefix to the root column name of the expression.
-
#product ⇒ Expr
Compute the product of an expression.
-
#qcut(quantiles, labels: nil, left_closed: false, allow_duplicates: false, include_breaks: false) ⇒ Expr
Bin continuous values into discrete categories based on their quantiles.
-
#quantile(quantile, interpolation: "nearest") ⇒ Expr
Get quantile value.
-
#rank(method: "average", reverse: false, seed: nil) ⇒ Expr
Assign ranks to data, dealing with ties appropriately.
-
#rechunk ⇒ Expr
Create a single chunk of memory for this Series.
-
#reinterpret(signed: false) ⇒ Expr
Reinterpret the underlying bits as a signed/unsigned integer.
-
#repeat_by(by) ⇒ Expr
Repeat the elements in this Series as specified in the given expression.
-
#reshape(dims) ⇒ Expr
Reshape this Expr to a flat Series or a Series of Lists.
-
#reverse ⇒ Expr
Reverse the selection.
-
#rle ⇒ Expr
Get the lengths of runs of identical values.
-
#rle_id ⇒ Expr
Map values to run IDs.
-
#rolling_max(window_size, weights: nil, min_periods: nil, center: false, by: nil, closed: "left") ⇒ Expr
Apply a rolling max (moving max) over the values in this array.
-
#rolling_mean(window_size, weights: nil, min_periods: nil, center: false, by: nil, closed: "left") ⇒ Expr
Apply a rolling mean (moving mean) over the values in this array.
-
#rolling_median(window_size, weights: nil, min_periods: nil, center: false, by: nil, closed: "left", warn_if_unsorted: true) ⇒ Expr
Compute a rolling median.
-
#rolling_min(window_size, weights: nil, min_periods: nil, center: false, by: nil, closed: "left") ⇒ Expr
Apply a rolling min (moving min) over the values in this array.
-
#rolling_quantile(quantile, interpolation: "nearest", window_size: 2, weights: nil, min_periods: nil, center: false, by: nil, closed: "left", warn_if_unsorted: true) ⇒ Expr
Compute a rolling quantile.
-
#rolling_skew(window_size, bias: true) ⇒ Expr
Compute a rolling skew.
-
#rolling_std(window_size, weights: nil, min_periods: nil, center: false, by: nil, closed: "left", ddof: 1, warn_if_unsorted: true) ⇒ Expr
Compute a rolling standard deviation.
-
#rolling_sum(window_size, weights: nil, min_periods: nil, center: false, by: nil, closed: "left") ⇒ Expr
Apply a rolling sum (moving sum) over the values in this array.
-
#rolling_var(window_size, weights: nil, min_periods: nil, center: false, by: nil, closed: "left", ddof: 1, warn_if_unsorted: true) ⇒ Expr
Compute a rolling variance.
-
#round(decimals = 0) ⇒ Expr
Round underlying floating point data by
decimalsdigits. -
#sample(frac: nil, with_replacement: true, shuffle: false, seed: nil, n: nil) ⇒ Expr
Sample from this expression.
-
#search_sorted(element, side: "any") ⇒ Expr
Find indices where elements should be inserted to maintain order.
-
#set_sorted(descending: false) ⇒ Expr
Flags the expression as 'sorted'.
-
#shift(n = 1, fill_value: nil) ⇒ Expr
Shift the values by a given period.
-
#shift_and_fill(periods, fill_value) ⇒ Expr
Shift the values by a given period and fill the resulting null values.
-
#shrink_dtype ⇒ Expr
Shrink numeric columns to the minimal required datatype.
-
#shuffle(seed: nil) ⇒ Expr
Shuffle the contents of this expr.
-
#sign ⇒ Expr
Compute the element-wise indication of the sign.
-
#sin ⇒ Expr
Compute the element-wise value for the sine.
-
#sinh ⇒ Expr
Compute the element-wise value for the hyperbolic sine.
-
#skew(bias: true) ⇒ Expr
Compute the sample skewness of a data set.
-
#slice(offset, length = nil) ⇒ Expr
Get a slice of this expression.
-
#sort(reverse: false, nulls_last: false) ⇒ Expr
Sort this column.
-
#sort_by(by, reverse: false) ⇒ Expr
Sort this column by the ordering of another column, or multiple other columns.
-
#sqrt ⇒ Expr
Compute the square root of the elements.
-
#std(ddof: 1) ⇒ Expr
Get standard deviation.
-
#str ⇒ StringExpr
Create an object namespace of all string related methods.
-
#struct ⇒ StructExpr
Create an object namespace of all struct related methods.
-
#suffix(suffix) ⇒ Expr
Add a suffix to the root column name of the expression.
-
#sum ⇒ Expr
Get sum value.
-
#tail(n = 10) ⇒ Expr
Get the last
nrows. -
#tan ⇒ Expr
Compute the element-wise value for the tangent.
-
#tanh ⇒ Expr
Compute the element-wise value for the hyperbolic tangent.
-
#to_physical ⇒ Expr
Cast to physical representation of the logical dtype.
-
#to_s ⇒ String
(also: #inspect)
Returns a string representing the Expr.
-
#top_k(k: 5) ⇒ Expr
Return the
klargest elements. -
#unique(maintain_order: false) ⇒ Expr
Get unique values of this expression.
-
#unique_counts ⇒ Expr
Return a count of the unique values in the order of appearance.
-
#upper_bound ⇒ Expr
Calculate the upper bound.
-
#value_counts(multithreaded: false, sort: false) ⇒ Expr
Count all unique values and create a struct mapping value to count.
-
#var(ddof: 1) ⇒ Expr
Get variance.
-
#where(predicate) ⇒ Expr
Filter a single column.
-
#|(other) ⇒ Expr
Bitwise OR.
Instance Method Details
#!=(other) ⇒ Expr
Not equal.
116 117 118 |
# File 'lib/polars/expr.rb', line 116 def !=(other) wrap_expr(_rbexpr.neq(_to_expr(other)._rbexpr)) end |
#%(other) ⇒ Expr
Returns the modulo.
81 82 83 |
# File 'lib/polars/expr.rb', line 81 def %(other) wrap_expr(_rbexpr % _to_rbexpr(other)) end |
#&(other) ⇒ Expr
Bitwise AND.
32 33 34 |
# File 'lib/polars/expr.rb', line 32 def &(other) wrap_expr(_rbexpr._and(_to_rbexpr(other))) end |
#*(other) ⇒ Expr
Performs multiplication.
60 61 62 |
# File 'lib/polars/expr.rb', line 60 def *(other) wrap_expr(_rbexpr * _to_rbexpr(other)) end |
#**(power) ⇒ Expr
Raises to the power of exponent.
88 89 90 |
# File 'lib/polars/expr.rb', line 88 def **(power) pow(power) end |
#+(other) ⇒ Expr
Performs addition.
46 47 48 |
# File 'lib/polars/expr.rb', line 46 def +(other) wrap_expr(_rbexpr + _to_rbexpr(other)) end |
#-(other) ⇒ Expr
Performs subtraction.
53 54 55 |
# File 'lib/polars/expr.rb', line 53 def -(other) wrap_expr(_rbexpr - _to_rbexpr(other)) end |
#-@ ⇒ Expr
Performs negation.
144 145 146 |
# File 'lib/polars/expr.rb', line 144 def -@ Utils.lit(0) - self end |
#/(other) ⇒ Expr
Performs division.
67 68 69 |
# File 'lib/polars/expr.rb', line 67 def /(other) wrap_expr(_rbexpr / _to_rbexpr(other)) end |
#<(other) ⇒ Expr
Less than.
123 124 125 |
# File 'lib/polars/expr.rb', line 123 def <(other) wrap_expr(_rbexpr.lt(_to_expr(other)._rbexpr)) end |
#<=(other) ⇒ Expr
Less than or equal.
102 103 104 |
# File 'lib/polars/expr.rb', line 102 def <=(other) wrap_expr(_rbexpr.lt_eq(_to_expr(other)._rbexpr)) end |
#==(other) ⇒ Expr
Equal.
109 110 111 |
# File 'lib/polars/expr.rb', line 109 def ==(other) wrap_expr(_rbexpr.eq(_to_expr(other)._rbexpr)) end |
#>(other) ⇒ Expr
Greater than.
130 131 132 |
# File 'lib/polars/expr.rb', line 130 def >(other) wrap_expr(_rbexpr.gt(_to_expr(other)._rbexpr)) end |
#>=(other) ⇒ Expr
Greater than or equal.
95 96 97 |
# File 'lib/polars/expr.rb', line 95 def >=(other) wrap_expr(_rbexpr.gt_eq(_to_expr(other)._rbexpr)) end |
#^(other) ⇒ Expr
Bitwise XOR.
25 26 27 |
# File 'lib/polars/expr.rb', line 25 def ^(other) wrap_expr(_rbexpr._xor(_to_rbexpr(other))) end |
#_hash(seed = 0, seed_1 = nil, seed_2 = nil, seed_3 = nil) ⇒ Expr
Hash the elements in the selection.
The hash value is of type :u64.
3236 3237 3238 3239 3240 3241 3242 |
# File 'lib/polars/expr.rb', line 3236 def _hash(seed = 0, seed_1 = nil, seed_2 = nil, seed_3 = nil) k0 = seed k1 = seed_1.nil? ? seed : seed_1 k2 = seed_2.nil? ? seed : seed_2 k3 = seed_3.nil? ? seed : seed_3 wrap_expr(_rbexpr._hash(k0, k1, k2, k3)) end |
#abs ⇒ Expr
Compute absolute values.
4156 4157 4158 |
# File 'lib/polars/expr.rb', line 4156 def abs wrap_expr(_rbexpr.abs) end |
#agg_groups ⇒ Expr
Get the group indexes of the group by operation.
Should be used in aggregation context only.
703 704 705 |
# File 'lib/polars/expr.rb', line 703 def agg_groups wrap_expr(_rbexpr.agg_groups) end |
#alias(name) ⇒ Expr
Rename the output of an expression.
327 328 329 |
# File 'lib/polars/expr.rb', line 327 def alias(name) wrap_expr(_rbexpr._alias(name)) end |
#all(drop_nulls: true) ⇒ Boolean
Check if all boolean values in a Boolean column are true.
This method is an expression - not to be confused with
Polars.all which is a function to select all columns.
226 227 228 |
# File 'lib/polars/expr.rb', line 226 def all(drop_nulls: true) wrap_expr(_rbexpr.all(drop_nulls)) end |
#any(drop_nulls: true) ⇒ Boolean
Check if any boolean value in a Boolean column is true.
201 202 203 |
# File 'lib/polars/expr.rb', line 201 def any(drop_nulls: true) wrap_expr(_rbexpr.any(drop_nulls)) end |
#append(other, upcast: true) ⇒ Expr
Append expressions.
This is done by adding the chunks of other to this Series.
817 818 819 820 |
# File 'lib/polars/expr.rb', line 817 def append(other, upcast: true) other = Utils.expr_to_lit_or_expr(other) wrap_expr(_rbexpr.append(other._rbexpr, upcast)) end |
#approx_unique ⇒ Expr
Approx count unique values.
This is done using the HyperLogLog++ algorithm for cardinality estimation.
2086 2087 2088 |
# File 'lib/polars/expr.rb', line 2086 def approx_unique wrap_expr(_rbexpr.approx_n_unique) end |
#arccos ⇒ Expr
Compute the element-wise value for the inverse cosine.
4649 4650 4651 |
# File 'lib/polars/expr.rb', line 4649 def arccos wrap_expr(_rbexpr.arccos) end |
#arccosh ⇒ Expr
Compute the element-wise value for the inverse hyperbolic cosine.
4769 4770 4771 |
# File 'lib/polars/expr.rb', line 4769 def arccosh wrap_expr(_rbexpr.arccosh) end |
#arcsin ⇒ Expr
Compute the element-wise value for the inverse sine.
4629 4630 4631 |
# File 'lib/polars/expr.rb', line 4629 def arcsin wrap_expr(_rbexpr.arcsin) end |
#arcsinh ⇒ Expr
Compute the element-wise value for the inverse hyperbolic sine.
4749 4750 4751 |
# File 'lib/polars/expr.rb', line 4749 def arcsinh wrap_expr(_rbexpr.arcsinh) end |
#arctan ⇒ Expr
Compute the element-wise value for the inverse tangent.
4669 4670 4671 |
# File 'lib/polars/expr.rb', line 4669 def arctan wrap_expr(_rbexpr.arctan) end |
#arctanh ⇒ Expr
Compute the element-wise value for the inverse hyperbolic tangent.
4789 4790 4791 |
# File 'lib/polars/expr.rb', line 4789 def arctanh wrap_expr(_rbexpr.arctanh) end |
#arg_max ⇒ Expr
Get the index of the maximal value.
1447 1448 1449 |
# File 'lib/polars/expr.rb', line 1447 def arg_max wrap_expr(_rbexpr.arg_max) end |
#arg_min ⇒ Expr
Get the index of the minimal value.
1471 1472 1473 |
# File 'lib/polars/expr.rb', line 1471 def arg_min wrap_expr(_rbexpr.arg_min) end |
#arg_sort(reverse: false, nulls_last: false) ⇒ Expr
Get the index values that would sort this column.
1423 1424 1425 |
# File 'lib/polars/expr.rb', line 1423 def arg_sort(reverse: false, nulls_last: false) wrap_expr(_rbexpr.arg_sort(reverse, nulls_last)) end |
#arg_unique ⇒ Expr
Get index of first unique value.
2151 2152 2153 |
# File 'lib/polars/expr.rb', line 2151 def arg_unique wrap_expr(_rbexpr.arg_unique) end |
#argsort(reverse: false, nulls_last: false) ⇒ expr
Get the index values that would sort this column.
Alias for #arg_sort.
4189 4190 4191 |
# File 'lib/polars/expr.rb', line 4189 def argsort(reverse: false, nulls_last: false) arg_sort(reverse: reverse, nulls_last: nulls_last) end |
#arr ⇒ ArrayExpr
Create an object namespace of all array related methods.
5309 5310 5311 |
# File 'lib/polars/expr.rb', line 5309 def arr ArrayExpr.new(self) end |
#backward_fill(limit: nil) ⇒ Expr
Fill missing values with the next to be seen values.
1827 1828 1829 |
# File 'lib/polars/expr.rb', line 1827 def backward_fill(limit: nil) wrap_expr(_rbexpr.backward_fill(limit)) end |
#bin ⇒ BinaryExpr
Create an object namespace of all binary related methods.
5316 5317 5318 |
# File 'lib/polars/expr.rb', line 5316 def bin BinaryExpr.new(self) end |
#bottom_k(k: 5) ⇒ Expr
Return the k smallest elements.
If 'reverse: true` the smallest elements will be given.
1391 1392 1393 1394 |
# File 'lib/polars/expr.rb', line 1391 def bottom_k(k: 5) k = Utils.parse_as_expression(k) wrap_expr(_rbexpr.bottom_k(k)) end |
#cast(dtype, strict: true) ⇒ Expr
Cast between data types.
1238 1239 1240 1241 |
# File 'lib/polars/expr.rb', line 1238 def cast(dtype, strict: true) dtype = Utils.rb_type_to_dtype(dtype) wrap_expr(_rbexpr.cast(dtype, strict)) end |
#cat ⇒ CatExpr
Create an object namespace of all categorical related methods.
5323 5324 5325 |
# File 'lib/polars/expr.rb', line 5323 def cat CatExpr.new(self) end |
#ceil ⇒ Expr
Rounds up to the nearest integer value.
Only works on floating point Series.
1117 1118 1119 |
# File 'lib/polars/expr.rb', line 1117 def ceil wrap_expr(_rbexpr.ceil) end |
#clip(lower_bound, upper_bound) ⇒ Expr
Set values outside the given boundaries to the boundary value.
Only works for numeric and temporal columns. If you want to clip other data
types, consider writing a when-then-otherwise expression.
4411 4412 4413 4414 4415 4416 4417 4418 4419 |
# File 'lib/polars/expr.rb', line 4411 def clip(lower_bound, upper_bound) if !lower_bound.nil? lower_bound = Utils.parse_as_expression(lower_bound, str_as_lit: true) end if !upper_bound.nil? upper_bound = Utils.parse_as_expression(upper_bound, str_as_lit: true) end wrap_expr(_rbexpr.clip(lower_bound, upper_bound)) end |
#clip_max(upper_bound) ⇒ Expr
Clip (limit) the values in an array to a max boundary.
Only works for numerical types.
If you want to clip other dtypes, consider writing a "when, then, otherwise"
expression. See when for more information.
4479 4480 4481 |
# File 'lib/polars/expr.rb', line 4479 def clip_max(upper_bound) clip(nil, upper_bound) end |
#clip_min(lower_bound) ⇒ Expr
Clip (limit) the values in an array to a min boundary.
Only works for numerical types.
If you want to clip other dtypes, consider writing a "when, then, otherwise"
expression. See when for more information.
4448 4449 4450 |
# File 'lib/polars/expr.rb', line 4448 def clip_min(lower_bound) clip(lower_bound, nil) end |
#cos ⇒ Expr
Compute the element-wise value for the cosine.
4589 4590 4591 |
# File 'lib/polars/expr.rb', line 4589 def cos wrap_expr(_rbexpr.cos) end |
#cosh ⇒ Expr
Compute the element-wise value for the hyperbolic cosine.
4709 4710 4711 |
# File 'lib/polars/expr.rb', line 4709 def cosh wrap_expr(_rbexpr.cosh) end |
#count ⇒ Expr
Count the number of values in this expression.
723 724 725 726 727 |
# File 'lib/polars/expr.rb', line 723 def count warn "`Expr#count` will exclude null values in 0.9.0. Use `Expr#length` instead." # wrap_expr(_rbexpr.count) wrap_expr(_rbexpr.len) end |
#cum_count(reverse: false) ⇒ Expr Also known as: cumcount
Get an array with the cumulative count computed at every element.
Counting from 0 to len
1066 1067 1068 |
# File 'lib/polars/expr.rb', line 1066 def cum_count(reverse: false) wrap_expr(_rbexpr.cum_count(reverse)) end |
#cum_max(reverse: false) ⇒ Expr Also known as: cummax
Get an array with the cumulative max computed at every element.
1032 1033 1034 |
# File 'lib/polars/expr.rb', line 1032 def cum_max(reverse: false) wrap_expr(_rbexpr.cum_max(reverse)) end |
#cum_min(reverse: false) ⇒ Expr Also known as: cummin
Get an array with the cumulative min computed at every element.
1000 1001 1002 |
# File 'lib/polars/expr.rb', line 1000 def cum_min(reverse: false) wrap_expr(_rbexpr.cum_min(reverse)) end |
#cum_prod(reverse: false) ⇒ Expr Also known as: cumprod
Dtypes in :i8, :u8, :i16, and :u16 are cast to
:i64 before summing to prevent overflow issues.
Get an array with the cumulative product computed at every element.
968 969 970 |
# File 'lib/polars/expr.rb', line 968 def cum_prod(reverse: false) wrap_expr(_rbexpr.cum_prod(reverse)) end |
#cum_sum(reverse: false) ⇒ Expr Also known as: cumsum
Dtypes in :i8, :u8, :i16, and :u16 are cast to
:i64 before summing to prevent overflow issues.
Get an array with the cumulative sum computed at every element.
932 933 934 |
# File 'lib/polars/expr.rb', line 932 def cum_sum(reverse: false) wrap_expr(_rbexpr.cum_sum(reverse)) end |
#cumulative_eval(expr, min_periods: 1, parallel: false) ⇒ Expr
This functionality is experimental and may change without it being considered a breaking change.
This can be really slow as it can have O(n^2) complexity. Don't use this
for operations that visit all elements.
Run an expression over a sliding window that increases 1 slot every iteration.
5204 5205 5206 5207 5208 |
# File 'lib/polars/expr.rb', line 5204 def cumulative_eval(expr, min_periods: 1, parallel: false) wrap_expr( _rbexpr.cumulative_eval(expr._rbexpr, min_periods, parallel) ) end |
#cut(breaks, labels: nil, left_closed: false, include_breaks: false) ⇒ Expr
Bin continuous values into discrete categories.
2534 2535 2536 |
# File 'lib/polars/expr.rb', line 2534 def cut(breaks, labels: nil, left_closed: false, include_breaks: false) wrap_expr(_rbexpr.cut(breaks, labels, left_closed, include_breaks)) end |
#diff(n: 1, null_behavior: "ignore") ⇒ Expr
Calculate the n-th discrete difference.
4282 4283 4284 |
# File 'lib/polars/expr.rb', line 4282 def diff(n: 1, null_behavior: "ignore") wrap_expr(_rbexpr.diff(n, null_behavior)) end |
#dot(other) ⇒ Expr
Compute the dot/inner product between two Expressions.
1171 1172 1173 1174 |
# File 'lib/polars/expr.rb', line 1171 def dot(other) other = Utils.expr_to_lit_or_expr(other, str_to_lit: false) wrap_expr(_rbexpr.dot(other._rbexpr)) end |
#drop_nans ⇒ Expr
Drop floating point NaN values.
897 898 899 |
# File 'lib/polars/expr.rb', line 897 def drop_nans wrap_expr(_rbexpr.drop_nans) end |
#drop_nulls ⇒ Expr
Drop null values.
870 871 872 |
# File 'lib/polars/expr.rb', line 870 def drop_nulls wrap_expr(_rbexpr.drop_nulls) end |
#dt ⇒ DateTimeExpr
Create an object namespace of all datetime related methods.
5330 5331 5332 |
# File 'lib/polars/expr.rb', line 5330 def dt DateTimeExpr.new(self) end |
#entropy(base: 2, normalize: true) ⇒ Expr
Computes the entropy.
Uses the formula -sum(pk * log(pk) where pk are discrete probabilities.
5157 5158 5159 |
# File 'lib/polars/expr.rb', line 5157 def entropy(base: 2, normalize: true) wrap_expr(_rbexpr.entropy(base, normalize)) end |
#ewm_mean(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, min_periods: 1, ignore_nulls: true) ⇒ Expr
Exponentially-weighted moving average.
4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 |
# File 'lib/polars/expr.rb', line 4921 def ewm_mean( com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, min_periods: 1, ignore_nulls: true ) alpha = _prepare_alpha(com, span, half_life, alpha) wrap_expr(_rbexpr.ewm_mean(alpha, adjust, min_periods, ignore_nulls)) end |
#ewm_std(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_periods: 1, ignore_nulls: true) ⇒ Expr
Exponentially-weighted moving standard deviation.
4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 |
# File 'lib/polars/expr.rb', line 4952 def ewm_std( com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_periods: 1, ignore_nulls: true ) alpha = _prepare_alpha(com, span, half_life, alpha) wrap_expr(_rbexpr.ewm_std(alpha, adjust, bias, min_periods, ignore_nulls)) end |
#ewm_var(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_periods: 1, ignore_nulls: true) ⇒ Expr
Exponentially-weighted moving variance.
4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 |
# File 'lib/polars/expr.rb', line 4984 def ewm_var( com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_periods: 1, ignore_nulls: true ) alpha = _prepare_alpha(com, span, half_life, alpha) wrap_expr(_rbexpr.ewm_var(alpha, adjust, bias, min_periods, ignore_nulls)) end |
#exclude(columns) ⇒ Expr
Exclude certain columns from a wildcard/regex selection.
You may also use regexes in the exclude list. They must start with ^ and end
with $.
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/polars/expr.rb', line 368 def exclude(columns) if columns.is_a?(::String) columns = [columns] return wrap_expr(_rbexpr.exclude(columns)) elsif !columns.is_a?(::Array) columns = [columns] return wrap_expr(_rbexpr.exclude_dtype(columns)) end if !columns.all? { |a| a.is_a?(::String) } || !columns.all? { |a| Utils.is_polars_dtype(a) } raise ArgumentError, "input should be all string or all DataType" end if columns[0].is_a?(::String) wrap_expr(_rbexpr.exclude(columns)) else wrap_expr(_rbexpr.exclude_dtype(columns)) end end |
#exp ⇒ Expr
Compute the exponential, element-wise.
292 293 294 |
# File 'lib/polars/expr.rb', line 292 def exp wrap_expr(_rbexpr.exp) end |
#explode ⇒ Expr
Explode a list or utf8 Series.
This means that every item is expanded to a new row.
2933 2934 2935 |
# File 'lib/polars/expr.rb', line 2933 def explode wrap_expr(_rbexpr.explode) end |
#extend_constant(value, n) ⇒ Expr
Extend the Series with given number of values.
5024 5025 5026 |
# File 'lib/polars/expr.rb', line 5024 def extend_constant(value, n) wrap_expr(_rbexpr.extend_constant(value, n)) end |
#fill_nan(fill_value) ⇒ Expr
Fill floating point NaN value with a fill value.
1766 1767 1768 1769 |
# File 'lib/polars/expr.rb', line 1766 def fill_nan(fill_value) fill_value = Utils.expr_to_lit_or_expr(fill_value, str_to_lit: true) wrap_expr(_rbexpr.fill_nan(fill_value._rbexpr)) end |
#fill_null(value = nil, strategy: nil, limit: nil) ⇒ Expr
Fill null values using the specified value or strategy.
To interpolate over null values see interpolate.
1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 |
# File 'lib/polars/expr.rb', line 1726 def fill_null(value = nil, strategy: nil, limit: nil) if !value.nil? && !strategy.nil? raise ArgumentError, "cannot specify both 'value' and 'strategy'." elsif value.nil? && strategy.nil? raise ArgumentError, "must specify either a fill 'value' or 'strategy'" elsif ["forward", "backward"].include?(strategy) && !limit.nil? raise ArgumentError, "can only specify 'limit' when strategy is set to 'backward' or 'forward'" end if !value.nil? value = Utils.expr_to_lit_or_expr(value, str_to_lit: true) wrap_expr(_rbexpr.fill_null(value._rbexpr)) else wrap_expr(_rbexpr.fill_null_with_strategy(strategy, limit)) end end |
#filter(predicate) ⇒ Expr
Filter a single column.
Mostly useful in an aggregation context. If you want to filter on a DataFrame
level, use LazyFrame#filter.
2717 2718 2719 |
# File 'lib/polars/expr.rb', line 2717 def filter(predicate) wrap_expr(_rbexpr.filter(predicate._rbexpr)) end |
#first ⇒ Expr
Get the first value.
2199 2200 2201 |
# File 'lib/polars/expr.rb', line 2199 def first wrap_expr(_rbexpr.first) end |
#flatten ⇒ Expr
Explode a list or utf8 Series. This means that every item is expanded to a new row.
Alias for #explode.
2906 2907 2908 |
# File 'lib/polars/expr.rb', line 2906 def flatten wrap_expr(_rbexpr.explode) end |
#floor ⇒ Expr
Rounds down to the nearest integer value.
Only works on floating point Series.
1092 1093 1094 |
# File 'lib/polars/expr.rb', line 1092 def floor wrap_expr(_rbexpr.floor) end |
#floordiv(other) ⇒ Expr
Performs floor division.
74 75 76 |
# File 'lib/polars/expr.rb', line 74 def floordiv(other) wrap_expr(_rbexpr.floordiv(_to_rbexpr(other))) end |
#forward_fill(limit: nil) ⇒ Expr
Fill missing values with the latest seen values.
1797 1798 1799 |
# File 'lib/polars/expr.rb', line 1797 def forward_fill(limit: nil) wrap_expr(_rbexpr.forward_fill(limit)) end |
#gather(indices) ⇒ Expr Also known as: take
Take values by index.
1595 1596 1597 1598 1599 1600 1601 1602 |
# File 'lib/polars/expr.rb', line 1595 def gather(indices) if indices.is_a?(::Array) indices_lit = Polars.lit(Series.new("", indices, dtype: :u32)) else indices_lit = Utils.expr_to_lit_or_expr(indices, str_to_lit: false) end wrap_expr(_rbexpr.gather(indices_lit._rbexpr)) end |
#gather_every(n, offset = 0) ⇒ Expr Also known as: take_every
Take every nth value in the Series and return as a new Series.
2955 2956 2957 |
# File 'lib/polars/expr.rb', line 2955 def gather_every(n, offset = 0) wrap_expr(_rbexpr.gather_every(n, offset)) end |
#head(n = 10) ⇒ Expr
Get the first n rows.
2981 2982 2983 |
# File 'lib/polars/expr.rb', line 2981 def head(n = 10) wrap_expr(_rbexpr.head(n)) end |
#implode ⇒ Expr
Aggregate to list.
5260 5261 5262 |
# File 'lib/polars/expr.rb', line 5260 def implode wrap_expr(_rbexpr.implode) end |
#interpolate(method: "linear") ⇒ Expr
Fill nulls with linear interpolation over missing values.
Can also be used to regrid data to a new grid - see examples below.
3337 3338 3339 |
# File 'lib/polars/expr.rb', line 3337 def interpolate(method: "linear") wrap_expr(_rbexpr.interpolate(method)) end |
#is_between(start, _end, closed: "both") ⇒ Expr
Check if this expression is between start and end.
3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 |
# File 'lib/polars/expr.rb', line 3184 def is_between(start, _end, closed: "both") start = Utils.expr_to_lit_or_expr(start, str_to_lit: false) _end = Utils.expr_to_lit_or_expr(_end, str_to_lit: false) case closed when "none" (self > start) & (self < _end) when "both" (self >= start) & (self <= _end) when "right" (self > start) & (self <= _end) when "left" (self >= start) & (self < _end) else raise ArgumentError, "closed must be one of 'left', 'right', 'both', or 'none'" end end |
#is_duplicated ⇒ Expr
Get mask of duplicated values.
2356 2357 2358 |
# File 'lib/polars/expr.rb', line 2356 def is_duplicated wrap_expr(_rbexpr.is_duplicated) end |
#is_finite ⇒ Expr
Returns a boolean Series indicating which values are finite.
576 577 578 |
# File 'lib/polars/expr.rb', line 576 def is_finite wrap_expr(_rbexpr.is_finite) end |
#is_first_distinct ⇒ Expr Also known as: is_first
Get a mask of the first unique value.
2333 2334 2335 |
# File 'lib/polars/expr.rb', line 2333 def is_first_distinct wrap_expr(_rbexpr.is_first_distinct) end |
#is_in(other) ⇒ Expr Also known as: in?
Check if elements of this expression are present in the other Series.
3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 |
# File 'lib/polars/expr.rb', line 3069 def is_in(other) if other.is_a?(::Array) if other.length == 0 other = Polars.lit(nil) else other = Polars.lit(Series.new(other)) end else other = Utils.expr_to_lit_or_expr(other, str_to_lit: false) end wrap_expr(_rbexpr.is_in(other._rbexpr)) end |
#is_infinite ⇒ Expr
Returns a boolean Series indicating which values are infinite.
602 603 604 |
# File 'lib/polars/expr.rb', line 602 def is_infinite wrap_expr(_rbexpr.is_infinite) end |
#is_nan ⇒ Expr
Floating point NaN (Not A Number) should not be confused
with missing data represented as nil.
Returns a boolean Series indicating which values are NaN.
635 636 637 |
# File 'lib/polars/expr.rb', line 635 def is_nan wrap_expr(_rbexpr.is_nan) end |
#is_not ⇒ Expr
Negate a boolean expression.
492 493 494 |
# File 'lib/polars/expr.rb', line 492 def is_not wrap_expr(_rbexpr.is_not) end |
#is_not_nan ⇒ Expr
Floating point NaN (Not A Number) should not be confused
with missing data represented as nil.
Returns a boolean Series indicating which values are not NaN.
668 669 670 |
# File 'lib/polars/expr.rb', line 668 def is_not_nan wrap_expr(_rbexpr.is_not_nan) end |
#is_not_null ⇒ Expr
Returns a boolean Series indicating which values are not null.
550 551 552 |
# File 'lib/polars/expr.rb', line 550 def is_not_null wrap_expr(_rbexpr.is_not_null) end |
#is_null ⇒ Expr
Returns a boolean Series indicating which values are null.
521 522 523 |
# File 'lib/polars/expr.rb', line 521 def is_null wrap_expr(_rbexpr.is_null) end |
#is_unique ⇒ Expr
Get mask of unique values.
2305 2306 2307 |
# File 'lib/polars/expr.rb', line 2305 def is_unique wrap_expr(_rbexpr.is_unique) end |
#keep_name ⇒ Expr
Keep the original root name of the expression.
410 411 412 |
# File 'lib/polars/expr.rb', line 410 def keep_name name.keep end |
#kurtosis(fisher: true, bias: true) ⇒ Expr
Compute the kurtosis (Fisher or Pearson) of a dataset.
Kurtosis is the fourth central moment divided by the square of the variance. If Fisher's definition is used, then 3.0 is subtracted from the result to give 0.0 for a normal distribution. If bias is False then the kurtosis is calculated using k statistics to eliminate bias coming from biased moment estimators
4380 4381 4382 |
# File 'lib/polars/expr.rb', line 4380 def kurtosis(fisher: true, bias: true) wrap_expr(_rbexpr.kurtosis(fisher, bias)) end |
#last ⇒ Expr
Get the last value.
2219 2220 2221 |
# File 'lib/polars/expr.rb', line 2219 def last wrap_expr(_rbexpr.last) end |
#len ⇒ Expr Also known as: length
Count the number of values in this expression.
745 746 747 |
# File 'lib/polars/expr.rb', line 745 def len wrap_expr(_rbexpr.len) end |
#limit(n = 10) ⇒ Expr
Get the first n rows.
Alias for #head.
3018 3019 3020 |
# File 'lib/polars/expr.rb', line 3018 def limit(n = 10) head(n) end |
#list ⇒ ListExpr
Create an object namespace of all list related methods.
5302 5303 5304 |
# File 'lib/polars/expr.rb', line 5302 def list ListExpr.new(self) end |
#log(base = Math::E) ⇒ Expr
Compute the logarithm to a given base.
5118 5119 5120 |
# File 'lib/polars/expr.rb', line 5118 def log(base = Math::E) wrap_expr(_rbexpr.log(base)) end |
#log10 ⇒ Expr
Compute the base 10 logarithm of the input array, element-wise.
270 271 272 |
# File 'lib/polars/expr.rb', line 270 def log10 log(10) end |
#lower_bound ⇒ Expr
Calculate the lower bound.
Returns a unit Series with the lowest value possible for the dtype of this expression.
4502 4503 4504 |
# File 'lib/polars/expr.rb', line 4502 def lower_bound wrap_expr(_rbexpr.lower_bound) end |
#map_alias(&f) ⇒ Expr
Rename the output of an expression by mapping a function over the root name.
452 453 454 |
# File 'lib/polars/expr.rb', line 452 def map_alias(&f) name.map(&f) end |
#max ⇒ Expr
Get maximum value.
1900 1901 1902 |
# File 'lib/polars/expr.rb', line 1900 def max wrap_expr(_rbexpr.max) end |
#mean ⇒ Expr
Get mean value.
2004 2005 2006 |
# File 'lib/polars/expr.rb', line 2004 def mean wrap_expr(_rbexpr.mean) end |
#median ⇒ Expr
Get median value using linear interpolation.
2024 2025 2026 |
# File 'lib/polars/expr.rb', line 2024 def median wrap_expr(_rbexpr.median) end |
#meta ⇒ MetaExpr
Create an object namespace of all meta related expression methods.
5337 5338 5339 |
# File 'lib/polars/expr.rb', line 5337 def MetaExpr.new(self) end |
#min ⇒ Expr
Get minimum value.
1920 1921 1922 |
# File 'lib/polars/expr.rb', line 1920 def min wrap_expr(_rbexpr.min) end |
#mode ⇒ Expr
Compute the most occurring value(s).
Can return multiple Values.
1200 1201 1202 |
# File 'lib/polars/expr.rb', line 1200 def mode wrap_expr(_rbexpr.mode) end |
#n_unique ⇒ Expr
Count unique values.
2064 2065 2066 |
# File 'lib/polars/expr.rb', line 2064 def n_unique wrap_expr(_rbexpr.n_unique) end |
#name ⇒ NameExpr
Create an object namespace of all expressions that modify expression names.
5344 5345 5346 |
# File 'lib/polars/expr.rb', line 5344 def name NameExpr.new(self) end |
#nan_max ⇒ Expr
Get maximum value, but propagate/poison encountered NaN values.
1940 1941 1942 |
# File 'lib/polars/expr.rb', line 1940 def nan_max wrap_expr(_rbexpr.nan_max) end |
#nan_min ⇒ Expr
Get minimum value, but propagate/poison encountered NaN values.
1960 1961 1962 |
# File 'lib/polars/expr.rb', line 1960 def nan_min wrap_expr(_rbexpr.nan_min) end |
#null_count ⇒ Expr
Count null values.
2111 2112 2113 |
# File 'lib/polars/expr.rb', line 2111 def null_count wrap_expr(_rbexpr.null_count) end |
#over(expr) ⇒ Expr
Apply window function over a subgroup.
This is similar to a group by + aggregation + self join. Or similar to window functions in Postgres.
2282 2283 2284 2285 |
# File 'lib/polars/expr.rb', line 2282 def over(expr) rbexprs = Utils.selection_to_rbexpr_list(expr) wrap_expr(_rbexpr.over(rbexprs)) end |
#pct_change(n: 1) ⇒ Expr
Computes percentage change between values.
Percentage change (as fraction) between current element and most-recent
non-null element at least n period(s) before the current element.
Computes the change from the previous row by default.
4318 4319 4320 4321 |
# File 'lib/polars/expr.rb', line 4318 def pct_change(n: 1) n = Utils.parse_as_expression(n) wrap_expr(_rbexpr.pct_change(n)) end |
#peak_max ⇒ Expr
Get a boolean mask of the local maximum peaks.
2380 2381 2382 |
# File 'lib/polars/expr.rb', line 2380 def peak_max wrap_expr(_rbexpr.peak_max) end |
#peak_min ⇒ Expr
Get a boolean mask of the local minimum peaks.
2404 2405 2406 |
# File 'lib/polars/expr.rb', line 2404 def peak_min wrap_expr(_rbexpr.peak_min) end |
#pow(exponent) ⇒ Expr
Raise expression to the power of exponent.
3041 3042 3043 3044 |
# File 'lib/polars/expr.rb', line 3041 def pow(exponent) exponent = Utils.expr_to_lit_or_expr(exponent) wrap_expr(_rbexpr.pow(exponent._rbexpr)) end |
#prefix(prefix) ⇒ Expr
Add a prefix to the root column name of the expression.
417 418 419 |
# File 'lib/polars/expr.rb', line 417 def prefix(prefix) name.prefix(prefix) end |
#product ⇒ Expr
Compute the product of an expression.
2044 2045 2046 |
# File 'lib/polars/expr.rb', line 2044 def product wrap_expr(_rbexpr.product) end |
#qcut(quantiles, labels: nil, left_closed: false, allow_duplicates: false, include_breaks: false) ⇒ Expr
Bin continuous values into discrete categories based on their quantiles.
2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 |
# File 'lib/polars/expr.rb', line 2615 def qcut(quantiles, labels: nil, left_closed: false, allow_duplicates: false, include_breaks: false) if quantiles.is_a?(Integer) rbexpr = _rbexpr.qcut_uniform( quantiles, labels, left_closed, allow_duplicates, include_breaks ) else rbexpr = _rbexpr.qcut( quantiles, labels, left_closed, allow_duplicates, include_breaks ) end wrap_expr(rbexpr) end |
#quantile(quantile, interpolation: "nearest") ⇒ Expr
Get quantile value.
2477 2478 2479 2480 |
# File 'lib/polars/expr.rb', line 2477 def quantile(quantile, interpolation: "nearest") quantile = Utils.expr_to_lit_or_expr(quantile, str_to_lit: false) wrap_expr(_rbexpr.quantile(quantile._rbexpr, interpolation)) end |
#rank(method: "average", reverse: false, seed: nil) ⇒ Expr
Assign ranks to data, dealing with ties appropriately.
4251 4252 4253 |
# File 'lib/polars/expr.rb', line 4251 def rank(method: "average", reverse: false, seed: nil) wrap_expr(_rbexpr.rank(method, reverse, seed)) end |
#rechunk ⇒ Expr
Create a single chunk of memory for this Series.
843 844 845 |
# File 'lib/polars/expr.rb', line 843 def rechunk wrap_expr(_rbexpr.rechunk) end |
#reinterpret(signed: false) ⇒ Expr
Reinterpret the underlying bits as a signed/unsigned integer.
This operation is only allowed for 64bit integers. For lower bits integers, you can safely use that cast operation.
3274 3275 3276 |
# File 'lib/polars/expr.rb', line 3274 def reinterpret(signed: false) wrap_expr(_rbexpr.reinterpret(signed)) end |
#repeat_by(by) ⇒ Expr
Repeat the elements in this Series as specified in the given expression.
The repeated elements are expanded into a List.
3113 3114 3115 3116 |
# File 'lib/polars/expr.rb', line 3113 def repeat_by(by) by = Utils.expr_to_lit_or_expr(by, str_to_lit: false) wrap_expr(_rbexpr.repeat_by(by._rbexpr)) end |
#reshape(dims) ⇒ Expr
Reshape this Expr to a flat Series or a Series of Lists.
4815 4816 4817 |
# File 'lib/polars/expr.rb', line 4815 def reshape(dims) wrap_expr(_rbexpr.reshape(dims)) end |
#reverse ⇒ Expr
Reverse the selection.
1834 1835 1836 |
# File 'lib/polars/expr.rb', line 1834 def reverse wrap_expr(_rbexpr.reverse) end |
#rle ⇒ Expr
Get the lengths of runs of identical values.
2650 2651 2652 |
# File 'lib/polars/expr.rb', line 2650 def rle wrap_expr(_rbexpr.rle) end |
#rle_id ⇒ Expr
Map values to run IDs.
Similar to RLE, but it maps each value to an ID corresponding to the run into which it falls. This is especially useful when you want to define groups by runs of identical values rather than the values themselves.
2678 2679 2680 |
# File 'lib/polars/expr.rb', line 2678 def rle_id wrap_expr(_rbexpr.rle_id) end |
#rolling_max(window_size, weights: nil, min_periods: nil, center: false, by: nil, closed: "left") ⇒ Expr
This functionality is experimental and may change without it being considered a breaking change.
If you want to compute multiple aggregation statistics over the same dynamic
window, consider using group_by_rolling this method can cache the window size
computation.
Apply a rolling max (moving max) over the values in this array.
A window of length window_size will traverse the array. The values that fill
this window will (optionally) be multiplied with the weights given by the
weight vector. The resulting values will be aggregated to their sum.
3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 |
# File 'lib/polars/expr.rb', line 3501 def rolling_max( window_size, weights: nil, min_periods: nil, center: false, by: nil, closed: "left" ) window_size, min_periods = _prepare_rolling_window_args( window_size, min_periods ) wrap_expr( _rbexpr.rolling_max( window_size, weights, min_periods, center, by, closed ) ) end |
#rolling_mean(window_size, weights: nil, min_periods: nil, center: false, by: nil, closed: "left") ⇒ Expr
This functionality is experimental and may change without it being considered a breaking change.
If you want to compute multiple aggregation statistics over the same dynamic
window, consider using group_by_rolling this method can cache the window size
computation.
Apply a rolling mean (moving mean) over the values in this array.
A window of length window_size will traverse the array. The values that fill
this window will (optionally) be multiplied with the weights given by the
weight vector. The resulting values will be aggregated to their sum.
3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 |
# File 'lib/polars/expr.rb', line 3590 def rolling_mean( window_size, weights: nil, min_periods: nil, center: false, by: nil, closed: "left" ) window_size, min_periods = _prepare_rolling_window_args( window_size, min_periods ) wrap_expr( _rbexpr.rolling_mean( window_size, weights, min_periods, center, by, closed ) ) end |
#rolling_median(window_size, weights: nil, min_periods: nil, center: false, by: nil, closed: "left", warn_if_unsorted: true) ⇒ Expr
This functionality is experimental and may change without it being considered a breaking change.
If you want to compute multiple aggregation statistics over the same dynamic
window, consider using group_by_rolling this method can cache the window size
computation.
Compute a rolling median.
3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 |
# File 'lib/polars/expr.rb', line 3946 def rolling_median( window_size, weights: nil, min_periods: nil, center: false, by: nil, closed: "left", warn_if_unsorted: true ) window_size, min_periods = _prepare_rolling_window_args( window_size, min_periods ) wrap_expr( _rbexpr.rolling_median( window_size, weights, min_periods, center, by, closed, warn_if_unsorted ) ) end |
#rolling_min(window_size, weights: nil, min_periods: nil, center: false, by: nil, closed: "left") ⇒ Expr
This functionality is experimental and may change without it being considered a breaking change.
If you want to compute multiple aggregation statistics over the same dynamic
window, consider using group_by_rolling this method can cache the window size
computation.
Apply a rolling min (moving min) over the values in this array.
A window of length window_size will traverse the array. The values that fill
this window will (optionally) be multiplied with the weights given by the
weight vector. The resulting values will be aggregated to their sum.
3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 |
# File 'lib/polars/expr.rb', line 3412 def rolling_min( window_size, weights: nil, min_periods: nil, center: false, by: nil, closed: "left" ) window_size, min_periods = _prepare_rolling_window_args( window_size, min_periods ) wrap_expr( _rbexpr.rolling_min( window_size, weights, min_periods, center, by, closed ) ) end |
#rolling_quantile(quantile, interpolation: "nearest", window_size: 2, weights: nil, min_periods: nil, center: false, by: nil, closed: "left", warn_if_unsorted: true) ⇒ Expr
This functionality is experimental and may change without it being considered a breaking change.
If you want to compute multiple aggregation statistics over the same dynamic
window, consider using group_by_rolling this method can cache the window size
computation.
Compute a rolling quantile.
4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 |
# File 'lib/polars/expr.rb', line 4036 def rolling_quantile( quantile, interpolation: "nearest", window_size: 2, weights: nil, min_periods: nil, center: false, by: nil, closed: "left", warn_if_unsorted: true ) window_size, min_periods = _prepare_rolling_window_args( window_size, min_periods ) wrap_expr( _rbexpr.rolling_quantile( quantile, interpolation, window_size, weights, min_periods, center, by, closed, warn_if_unsorted ) ) end |
#rolling_skew(window_size, bias: true) ⇒ Expr
Compute a rolling skew.
4129 4130 4131 |
# File 'lib/polars/expr.rb', line 4129 def rolling_skew(window_size, bias: true) wrap_expr(_rbexpr.rolling_skew(window_size, bias)) end |
#rolling_std(window_size, weights: nil, min_periods: nil, center: false, by: nil, closed: "left", ddof: 1, warn_if_unsorted: true) ⇒ Expr
This functionality is experimental and may change without it being considered a breaking change.
If you want to compute multiple aggregation statistics over the same dynamic
window, consider using group_by_rolling this method can cache the window size
computation.
Compute a rolling standard deviation.
A window of length window_size will traverse the array. The values that fill
this window will (optionally) be multiplied with the weights given by the
weight vector. The resulting values will be aggregated to their sum.
3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 |
# File 'lib/polars/expr.rb', line 3768 def rolling_std( window_size, weights: nil, min_periods: nil, center: false, by: nil, closed: "left", ddof: 1, warn_if_unsorted: true ) window_size, min_periods = _prepare_rolling_window_args( window_size, min_periods ) wrap_expr( _rbexpr.rolling_std( window_size, weights, min_periods, center, by, closed, ddof, warn_if_unsorted ) ) end |
#rolling_sum(window_size, weights: nil, min_periods: nil, center: false, by: nil, closed: "left") ⇒ Expr
This functionality is experimental and may change without it being considered a breaking change.
If you want to compute multiple aggregation statistics over the same dynamic
window, consider using group_by_rolling this method can cache the window size
computation.
Apply a rolling sum (moving sum) over the values in this array.
A window of length window_size will traverse the array. The values that fill
this window will (optionally) be multiplied with the weights given by the
weight vector. The resulting values will be aggregated to their sum.
3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 |
# File 'lib/polars/expr.rb', line 3679 def rolling_sum( window_size, weights: nil, min_periods: nil, center: false, by: nil, closed: "left" ) window_size, min_periods = _prepare_rolling_window_args( window_size, min_periods ) wrap_expr( _rbexpr.rolling_sum( window_size, weights, min_periods, center, by, closed ) ) end |
#rolling_var(window_size, weights: nil, min_periods: nil, center: false, by: nil, closed: "left", ddof: 1, warn_if_unsorted: true) ⇒ Expr
This functionality is experimental and may change without it being considered a breaking change.
If you want to compute multiple aggregation statistics over the same dynamic
window, consider using group_by_rolling this method can cache the window size
computation.
Compute a rolling variance.
A window of length window_size will traverse the array. The values that fill
this window will (optionally) be multiplied with the weights given by the
weight vector. The resulting values will be aggregated to their sum.
3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 |
# File 'lib/polars/expr.rb', line 3859 def rolling_var( window_size, weights: nil, min_periods: nil, center: false, by: nil, closed: "left", ddof: 1, warn_if_unsorted: true ) window_size, min_periods = _prepare_rolling_window_args( window_size, min_periods ) wrap_expr( _rbexpr.rolling_var( window_size, weights, min_periods, center, by, closed, ddof, warn_if_unsorted ) ) end |
#round(decimals = 0) ⇒ Expr
Round underlying floating point data by decimals digits.
1143 1144 1145 |
# File 'lib/polars/expr.rb', line 1143 def round(decimals = 0) wrap_expr(_rbexpr.round(decimals)) end |
#sample(frac: nil, with_replacement: true, shuffle: false, seed: nil, n: nil) ⇒ Expr
Sample from this expression.
4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 |
# File 'lib/polars/expr.rb', line 4878 def sample( frac: nil, with_replacement: true, shuffle: false, seed: nil, n: nil ) if !n.nil? && !frac.nil? raise ArgumentError, "cannot specify both `n` and `frac`" end if !n.nil? && frac.nil? n = Utils.parse_as_expression(n) return wrap_expr(_rbexpr.sample_n(n, with_replacement, shuffle, seed)) end if frac.nil? frac = 1.0 end frac = Utils.parse_as_expression(frac) wrap_expr( _rbexpr.sample_frac(frac, with_replacement, shuffle, seed) ) end |
#search_sorted(element, side: "any") ⇒ Expr
Find indices where elements should be inserted to maintain order.
1504 1505 1506 1507 |
# File 'lib/polars/expr.rb', line 1504 def search_sorted(element, side: "any") element = Utils.expr_to_lit_or_expr(element, str_to_lit: false) wrap_expr(_rbexpr.search_sorted(element._rbexpr, side)) end |
#set_sorted(descending: false) ⇒ Expr
This can lead to incorrect results if this Series is not sorted!!
Use with care!
Flags the expression as 'sorted'.
Enables downstream code to user fast paths for sorted arrays.
5235 5236 5237 |
# File 'lib/polars/expr.rb', line 5235 def set_sorted(descending: false) wrap_expr(_rbexpr.set_sorted_flag(descending)) end |
#shift(n = 1, fill_value: nil) ⇒ Expr
Shift the values by a given period.
1629 1630 1631 1632 1633 1634 1635 |
# File 'lib/polars/expr.rb', line 1629 def shift(n = 1, fill_value: nil) if !fill_value.nil? fill_value = Utils.parse_as_expression(fill_value, str_as_lit: true) end n = Utils.parse_as_expression(n) wrap_expr(_rbexpr.shift(n, fill_value)) end |
#shift_and_fill(periods, fill_value) ⇒ Expr
Shift the values by a given period and fill the resulting null values.
1661 1662 1663 |
# File 'lib/polars/expr.rb', line 1661 def shift_and_fill(periods, fill_value) shift(periods, fill_value: fill_value) end |
#shrink_dtype ⇒ Expr
Shrink numeric columns to the minimal required datatype.
Shrink to the dtype needed to fit the extrema of this Series.
This can be used to reduce memory pressure.
5295 5296 5297 |
# File 'lib/polars/expr.rb', line 5295 def shrink_dtype wrap_expr(_rbexpr.shrink_dtype) end |
#shuffle(seed: nil) ⇒ Expr
Shuffle the contents of this expr.
4841 4842 4843 4844 4845 4846 |
# File 'lib/polars/expr.rb', line 4841 def shuffle(seed: nil) if seed.nil? seed = rand(10000) end wrap_expr(_rbexpr.shuffle(seed)) end |
#sign ⇒ Expr
Compute the element-wise indication of the sign.
4549 4550 4551 |
# File 'lib/polars/expr.rb', line 4549 def sign wrap_expr(_rbexpr.sign) end |
#sin ⇒ Expr
Compute the element-wise value for the sine.
4569 4570 4571 |
# File 'lib/polars/expr.rb', line 4569 def sin wrap_expr(_rbexpr.sin) end |
#sinh ⇒ Expr
Compute the element-wise value for the hyperbolic sine.
4689 4690 4691 |
# File 'lib/polars/expr.rb', line 4689 def sinh wrap_expr(_rbexpr.sinh) end |
#skew(bias: true) ⇒ Expr
Compute the sample skewness of a data set.
For normally distributed data, the skewness should be about zero. For
unimodal continuous distributions, a skewness value greater than zero means
that there is more weight in the right tail of the distribution. The
function skewtest can be used to determine if the skewness value
is close enough to zero, statistically speaking.
4348 4349 4350 |
# File 'lib/polars/expr.rb', line 4348 def skew(bias: true) wrap_expr(_rbexpr.skew(bias)) end |
#slice(offset, length = nil) ⇒ Expr
Get a slice of this expression.
778 779 780 781 782 783 784 785 786 |
# File 'lib/polars/expr.rb', line 778 def slice(offset, length = nil) if !offset.is_a?(Expr) offset = Polars.lit(offset) end if !length.is_a?(Expr) length = Polars.lit(length) end wrap_expr(_rbexpr.slice(offset._rbexpr, length._rbexpr)) end |
#sort(reverse: false, nulls_last: false) ⇒ Expr
Sort this column. In projection/ selection context the whole column is sorted.
If used in a group by context, the groups are sorted.
1314 1315 1316 |
# File 'lib/polars/expr.rb', line 1314 def sort(reverse: false, nulls_last: false) wrap_expr(_rbexpr.sort_with(reverse, nulls_last)) end |
#sort_by(by, reverse: false) ⇒ Expr
Sort this column by the ordering of another column, or multiple other columns.
In projection/ selection context the whole column is sorted. If used in a group by context, the groups are sorted.
1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 |
# File 'lib/polars/expr.rb', line 1551 def sort_by(by, reverse: false) if !by.is_a?(::Array) by = [by] end if !reverse.is_a?(::Array) reverse = [reverse] end by = Utils.selection_to_rbexpr_list(by) wrap_expr(_rbexpr.sort_by(by, reverse)) end |
#sqrt ⇒ Expr
Compute the square root of the elements.
248 249 250 |
# File 'lib/polars/expr.rb', line 248 def sqrt self**0.5 end |
#std(ddof: 1) ⇒ Expr
Get standard deviation.
1857 1858 1859 |
# File 'lib/polars/expr.rb', line 1857 def std(ddof: 1) wrap_expr(_rbexpr.std(ddof)) end |
#str ⇒ StringExpr
Create an object namespace of all string related methods.
5351 5352 5353 |
# File 'lib/polars/expr.rb', line 5351 def str StringExpr.new(self) end |
#struct ⇒ StructExpr
Create an object namespace of all struct related methods.
5358 5359 5360 |
# File 'lib/polars/expr.rb', line 5358 def struct StructExpr.new(self) end |
#suffix(suffix) ⇒ Expr
Add a suffix to the root column name of the expression.
424 425 426 |
# File 'lib/polars/expr.rb', line 424 def suffix(suffix) name.suffix(suffix) end |
#sum ⇒ Expr
Dtypes in :i8, :u8, :i16, and :u16 are cast to
:i64 before summing to prevent overflow issues.
Get sum value.
1984 1985 1986 |
# File 'lib/polars/expr.rb', line 1984 def sum wrap_expr(_rbexpr.sum) end |
#tail(n = 10) ⇒ Expr
Get the last n rows.
3006 3007 3008 |
# File 'lib/polars/expr.rb', line 3006 def tail(n = 10) wrap_expr(_rbexpr.tail(n)) end |
#tan ⇒ Expr
Compute the element-wise value for the tangent.
4609 4610 4611 |
# File 'lib/polars/expr.rb', line 4609 def tan wrap_expr(_rbexpr.tan) end |
#tanh ⇒ Expr
Compute the element-wise value for the hyperbolic tangent.
4729 4730 4731 |
# File 'lib/polars/expr.rb', line 4729 def tanh wrap_expr(_rbexpr.tanh) end |
#to_physical ⇒ Expr
Cast to physical representation of the logical dtype.
:date->:i32:datetime->:i64:time->:i64:duration->:i64:cat->:u32- Other data types will be left unchanged.
181 182 183 |
# File 'lib/polars/expr.rb', line 181 def to_physical wrap_expr(_rbexpr.to_physical) end |
#to_s ⇒ String Also known as: inspect
Returns a string representing the Expr.
17 18 19 |
# File 'lib/polars/expr.rb', line 17 def to_s _rbexpr.to_str end |
#top_k(k: 5) ⇒ Expr
Return the k largest elements.
If 'reverse: true` the smallest elements will be given.
1352 1353 1354 1355 |
# File 'lib/polars/expr.rb', line 1352 def top_k(k: 5) k = Utils.parse_as_expression(k) wrap_expr(_rbexpr.top_k(k)) end |
#unique(maintain_order: false) ⇒ Expr
Get unique values of this expression.
2175 2176 2177 2178 2179 2180 2181 |
# File 'lib/polars/expr.rb', line 2175 def unique(maintain_order: false) if maintain_order wrap_expr(_rbexpr.unique_stable) else wrap_expr(_rbexpr.unique) end end |
#unique_counts ⇒ Expr
Return a count of the unique values in the order of appearance.
This method differs from value_counts in that it does not return the
values, only the counts and might be faster
5093 5094 5095 |
# File 'lib/polars/expr.rb', line 5093 def unique_counts wrap_expr(_rbexpr.unique_counts) end |
#upper_bound ⇒ Expr
Calculate the upper bound.
Returns a unit Series with the highest value possible for the dtype of this expression.
4525 4526 4527 |
# File 'lib/polars/expr.rb', line 4525 def upper_bound wrap_expr(_rbexpr.upper_bound) end |
#value_counts(multithreaded: false, sort: false) ⇒ Expr
Count all unique values and create a struct mapping value to count.
5060 5061 5062 |
# File 'lib/polars/expr.rb', line 5060 def value_counts(multithreaded: false, sort: false) wrap_expr(_rbexpr.value_counts(multithreaded, sort)) end |
#var(ddof: 1) ⇒ Expr
Get variance.
1880 1881 1882 |
# File 'lib/polars/expr.rb', line 1880 def var(ddof: 1) wrap_expr(_rbexpr.var(ddof)) end |
#where(predicate) ⇒ Expr
Filter a single column.
Alias for #filter.
2755 2756 2757 |
# File 'lib/polars/expr.rb', line 2755 def where(predicate) filter(predicate) end |
#|(other) ⇒ Expr
Bitwise OR.
39 40 41 |
# File 'lib/polars/expr.rb', line 39 def |(other) wrap_expr(_rbexpr._or(_to_rbexpr(other))) end |