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
-
#!=(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 ⇒ Boolean
Check if all boolean values in a Boolean column are
true
. -
#any ⇒ Boolean
Check if any boolean value in a Boolean column is
true
. -
#append(other, upcast: true) ⇒ Expr
Append expressions.
-
#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 ⇒ ListExpr
Create an object namespace of all list related methods.
-
#backward_fill(limit: nil) ⇒ Expr
Fill missing values with the next to be seen values.
-
#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(min_val, max_val) ⇒ Expr
Clip (limit) the values in an array to a
min
andmax
boundary. -
#clip_max(max_val) ⇒ Expr
Clip (limit) the values in an array to a
max
boundary. -
#clip_min(min_val) ⇒ Expr
Clip (limit) the values in an array to a
min
boundary. -
#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.
-
#cumcount(reverse: false) ⇒ Expr
Get an array with the cumulative count computed at every element.
-
#cummax(reverse: false) ⇒ Expr
Get an array with the cumulative max computed at every element.
-
#cummin(reverse: false) ⇒ Expr
Get an array with the cumulative min computed at every element.
-
#cumprod(reverse: false) ⇒ Expr
Get an array with the cumulative product computed at every element.
-
#cumsum(reverse: false) ⇒ Expr
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
1
slot every iteration. -
#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) ⇒ Expr
Exponentially-weighted moving average.
-
#ewm_std(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_periods: 1) ⇒ Expr
Exponentially-weighted moving standard deviation.
-
#ewm_var(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_periods: 1) ⇒ 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.
-
#head(n = 10) ⇒ Expr
Get the first
n
rows. -
#interpolate(method: "linear") ⇒ Expr
Fill nulls with linear interpolation over missing values.
-
#is_between(start, _end, include_bounds: false) ⇒ 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 ⇒ Expr
Get a mask of the first unique value.
-
#is_in(other) ⇒ Expr
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
Count the number of values in this expression.
-
#limit(n = 10) ⇒ Expr
Get the first
n
rows. -
#list ⇒ Expr
Aggregate to list.
-
#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.
-
#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.
-
#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.
-
#quantile(quantile, interpolation: "nearest") ⇒ Expr
Get quantile value.
-
#rank(method: "average", reverse: false) ⇒ 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.
-
#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") ⇒ 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") ⇒ 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") ⇒ 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") ⇒ Expr
Compute a rolling variance.
-
#round(decimals = 0) ⇒ Expr
Round underlying floating point data by
decimals
digits. -
#sample(frac: nil, with_replacement: true, shuffle: false, seed: nil, n: nil) ⇒ Expr
Sample from this expression.
-
#search_sorted(element) ⇒ Expr
Find indices where elements should be inserted to maintain order.
-
#shift(periods = 1) ⇒ 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
n
rows. -
#take(indices) ⇒ Expr
Take values by index.
-
#take_every(n) ⇒ Expr
Take every nth value in the Series and return as a new Series.
-
#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, reverse: false) ⇒ Expr
Return the
k
largest 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.
137 138 139 |
# File 'lib/polars/expr.rb', line 137 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
.
3048 3049 3050 3051 3052 3053 3054 |
# File 'lib/polars/expr.rb', line 3048 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.
4015 4016 4017 |
# File 'lib/polars/expr.rb', line 4015 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.
734 735 736 |
# File 'lib/polars/expr.rb', line 734 def agg_groups wrap_expr(_rbexpr.agg_groups) end |
#alias(name) ⇒ Expr
Rename the output of an expression.
331 332 333 |
# File 'lib/polars/expr.rb', line 331 def alias(name) wrap_expr(_rbexpr._alias(name)) end |
#all ⇒ 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.
222 223 224 |
# File 'lib/polars/expr.rb', line 222 def all wrap_expr(_rbexpr.all) end |
#any ⇒ Boolean
Check if any boolean value in a Boolean column is true
.
197 198 199 |
# File 'lib/polars/expr.rb', line 197 def any wrap_expr(_rbexpr.any) end |
#append(other, upcast: true) ⇒ Expr
Append expressions.
This is done by adding the chunks of other
to this Series
.
849 850 851 852 |
# File 'lib/polars/expr.rb', line 849 def append(other, upcast: true) other = Utils.expr_to_lit_or_expr(other) wrap_expr(_rbexpr.append(other._rbexpr, upcast)) end |
#arccos ⇒ Expr
Compute the element-wise value for the inverse cosine.
4532 4533 4534 |
# File 'lib/polars/expr.rb', line 4532 def arccos wrap_expr(_rbexpr.arccos) end |
#arccosh ⇒ Expr
Compute the element-wise value for the inverse hyperbolic cosine.
4652 4653 4654 |
# File 'lib/polars/expr.rb', line 4652 def arccosh wrap_expr(_rbexpr.arccosh) end |
#arcsin ⇒ Expr
Compute the element-wise value for the inverse sine.
4512 4513 4514 |
# File 'lib/polars/expr.rb', line 4512 def arcsin wrap_expr(_rbexpr.arcsin) end |
#arcsinh ⇒ Expr
Compute the element-wise value for the inverse hyperbolic sine.
4632 4633 4634 |
# File 'lib/polars/expr.rb', line 4632 def arcsinh wrap_expr(_rbexpr.arcsinh) end |
#arctan ⇒ Expr
Compute the element-wise value for the inverse tangent.
4552 4553 4554 |
# File 'lib/polars/expr.rb', line 4552 def arctan wrap_expr(_rbexpr.arctan) end |
#arctanh ⇒ Expr
Compute the element-wise value for the inverse hyperbolic tangent.
4672 4673 4674 |
# File 'lib/polars/expr.rb', line 4672 def arctanh wrap_expr(_rbexpr.arctanh) end |
#arg_max ⇒ Expr
Get the index of the maximal value.
1489 1490 1491 |
# File 'lib/polars/expr.rb', line 1489 def arg_max wrap_expr(_rbexpr.arg_max) end |
#arg_min ⇒ Expr
Get the index of the minimal value.
1513 1514 1515 |
# File 'lib/polars/expr.rb', line 1513 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.
1465 1466 1467 |
# File 'lib/polars/expr.rb', line 1465 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.
2192 2193 2194 |
# File 'lib/polars/expr.rb', line 2192 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.
4050 4051 4052 |
# File 'lib/polars/expr.rb', line 4050 def argsort(reverse: false, nulls_last: false) arg_sort(reverse: reverse, nulls_last: nulls_last) end |
#arr ⇒ ListExpr
Create an object namespace of all list related methods.
5208 5209 5210 |
# File 'lib/polars/expr.rb', line 5208 def arr ListExpr.new(self) end |
#backward_fill(limit: nil) ⇒ Expr
Fill missing values with the next to be seen values.
1887 1888 1889 |
# File 'lib/polars/expr.rb', line 1887 def backward_fill(limit: nil) wrap_expr(_rbexpr.backward_fill(limit)) end |
#cast(dtype, strict: true) ⇒ Expr
Cast between data types.
1301 1302 1303 1304 |
# File 'lib/polars/expr.rb', line 1301 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.
5215 5216 5217 |
# File 'lib/polars/expr.rb', line 5215 def cat CatExpr.new(self) end |
#ceil ⇒ Expr
Rounds up to the nearest integer value.
Only works on floating point Series.
1174 1175 1176 |
# File 'lib/polars/expr.rb', line 1174 def ceil wrap_expr(_rbexpr.ceil) end |
#clip(min_val, max_val) ⇒ Expr
Clip (limit) the values in an array to a min
and 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.
4290 4291 4292 |
# File 'lib/polars/expr.rb', line 4290 def clip(min_val, max_val) wrap_expr(_rbexpr.clip(min_val, max_val)) end |
#clip_max(max_val) ⇒ 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.
4358 4359 4360 |
# File 'lib/polars/expr.rb', line 4358 def clip_max(max_val) wrap_expr(_rbexpr.clip_max(max_val)) end |
#clip_min(min_val) ⇒ 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.
4324 4325 4326 |
# File 'lib/polars/expr.rb', line 4324 def clip_min(min_val) wrap_expr(_rbexpr.clip_min(min_val)) end |
#cos ⇒ Expr
Compute the element-wise value for the cosine.
4472 4473 4474 |
# File 'lib/polars/expr.rb', line 4472 def cos wrap_expr(_rbexpr.cos) end |
#cosh ⇒ Expr
Compute the element-wise value for the hyperbolic cosine.
4592 4593 4594 |
# File 'lib/polars/expr.rb', line 4592 def cosh wrap_expr(_rbexpr.cosh) end |
#count ⇒ Expr
Count the number of values in this expression.
754 755 756 |
# File 'lib/polars/expr.rb', line 754 def count wrap_expr(_rbexpr.count) end |
#cumcount(reverse: false) ⇒ Expr
Get an array with the cumulative count computed at every element.
Counting from 0 to len
1118 1119 1120 |
# File 'lib/polars/expr.rb', line 1118 def cumcount(reverse: false) wrap_expr(_rbexpr.cumcount(reverse)) end |
#cummax(reverse: false) ⇒ Expr
Get an array with the cumulative max computed at every element.
1082 1083 1084 |
# File 'lib/polars/expr.rb', line 1082 def cummax(reverse: false) wrap_expr(_rbexpr.cummax(reverse)) end |
#cummin(reverse: false) ⇒ Expr
Get an array with the cumulative min computed at every element.
1048 1049 1050 |
# File 'lib/polars/expr.rb', line 1048 def cummin(reverse: false) wrap_expr(_rbexpr.cummin(reverse)) end |
#cumprod(reverse: false) ⇒ Expr
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.
1014 1015 1016 |
# File 'lib/polars/expr.rb', line 1014 def cumprod(reverse: false) wrap_expr(_rbexpr.cumprod(reverse)) end |
#cumsum(reverse: false) ⇒ Expr
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.
976 977 978 |
# File 'lib/polars/expr.rb', line 976 def cumsum(reverse: false) wrap_expr(_rbexpr.cumsum(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.
5108 5109 5110 5111 5112 |
# File 'lib/polars/expr.rb', line 5108 def cumulative_eval(expr, min_periods: 1, parallel: false) wrap_expr( _rbexpr.cumulative_eval(expr._rbexpr, min_periods, parallel) ) end |
#diff(n: 1, null_behavior: "ignore") ⇒ Expr
Calculate the n-th discrete difference.
4153 4154 4155 |
# File 'lib/polars/expr.rb', line 4153 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.
1231 1232 1233 1234 |
# File 'lib/polars/expr.rb', line 1231 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.
938 939 940 |
# File 'lib/polars/expr.rb', line 938 def drop_nans wrap_expr(_rbexpr.drop_nans) end |
#drop_nulls ⇒ Expr
Drop null values.
909 910 911 |
# File 'lib/polars/expr.rb', line 909 def drop_nulls wrap_expr(_rbexpr.drop_nulls) end |
#dt ⇒ DateTimeExpr
Create an object namespace of all datetime related methods.
5222 5223 5224 |
# File 'lib/polars/expr.rb', line 5222 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.
5057 5058 5059 |
# File 'lib/polars/expr.rb', line 5057 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) ⇒ Expr
Exponentially-weighted moving average.
4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 |
# File 'lib/polars/expr.rb', line 4810 def ewm_mean( com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, min_periods: 1 ) alpha = _prepare_alpha(com, span, half_life, alpha) wrap_expr(_rbexpr.ewm_mean(alpha, adjust, min_periods)) end |
#ewm_std(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_periods: 1) ⇒ Expr
Exponentially-weighted moving standard deviation.
4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 |
# File 'lib/polars/expr.rb', line 4842 def ewm_std( com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_periods: 1 ) alpha = _prepare_alpha(com, span, half_life, alpha) wrap_expr(_rbexpr.ewm_std(alpha, adjust, bias, min_periods)) end |
#ewm_var(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_periods: 1) ⇒ Expr
Exponentially-weighted moving variance.
4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 |
# File 'lib/polars/expr.rb', line 4875 def ewm_var( com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_periods: 1 ) alpha = _prepare_alpha(com, span, half_life, alpha) wrap_expr(_rbexpr.ewm_var(alpha, adjust, bias, min_periods)) 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 $
.
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/polars/expr.rb', line 374 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.
294 295 296 |
# File 'lib/polars/expr.rb', line 294 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.
2766 2767 2768 |
# File 'lib/polars/expr.rb', line 2766 def explode wrap_expr(_rbexpr.explode) end |
#extend_constant(value, n) ⇒ Expr
Extend the Series with given number of values.
4918 4919 4920 |
# File 'lib/polars/expr.rb', line 4918 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.
1822 1823 1824 1825 |
# File 'lib/polars/expr.rb', line 1822 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.
1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 |
# File 'lib/polars/expr.rb', line 1780 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
.
2529 2530 2531 |
# File 'lib/polars/expr.rb', line 2529 def filter(predicate) wrap_expr(_rbexpr.filter(predicate._rbexpr)) end |
#first ⇒ Expr
Get the first value.
2241 2242 2243 |
# File 'lib/polars/expr.rb', line 2241 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.
2734 2735 2736 |
# File 'lib/polars/expr.rb', line 2734 def flatten wrap_expr(_rbexpr.explode) end |
#floor ⇒ Expr
Rounds down to the nearest integer value.
Only works on floating point Series.
1146 1147 1148 |
# File 'lib/polars/expr.rb', line 1146 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.
1855 1856 1857 |
# File 'lib/polars/expr.rb', line 1855 def forward_fill(limit: nil) wrap_expr(_rbexpr.forward_fill(limit)) end |
#head(n = 10) ⇒ Expr
Get the first n
rows.
2817 2818 2819 |
# File 'lib/polars/expr.rb', line 2817 def head(n = 10) wrap_expr(_rbexpr.head(n)) 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.
3155 3156 3157 |
# File 'lib/polars/expr.rb', line 3155 def interpolate(method: "linear") wrap_expr(_rbexpr.interpolate(method)) end |
#is_between(start, _end, include_bounds: false) ⇒ Expr
Check if this expression is between start and end.
2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 |
# File 'lib/polars/expr.rb', line 2998 def is_between(start, _end, include_bounds: false) if include_bounds == false || include_bounds == [false, false] ((self > start) & (self < _end)).alias("is_between") elsif include_bounds == true || include_bounds == [true, true] ((self >= start) & (self <= _end)).alias("is_between") elsif include_bounds == [false, true] ((self > start) & (self <= _end)).alias("is_between") elsif include_bounds == [true, false] ((self >= start) & (self < _end)).alias("is_between") else raise ArgumentError, "include_bounds should be a bool or [bool, bool]." end end |
#is_duplicated ⇒ Expr
Get mask of duplicated values.
2415 2416 2417 |
# File 'lib/polars/expr.rb', line 2415 def is_duplicated wrap_expr(_rbexpr.is_duplicated) end |
#is_finite ⇒ Expr
Returns a boolean Series indicating which values are finite.
597 598 599 |
# File 'lib/polars/expr.rb', line 597 def is_finite wrap_expr(_rbexpr.is_finite) end |
#is_first ⇒ Expr
Get a mask of the first unique value.
2391 2392 2393 |
# File 'lib/polars/expr.rb', line 2391 def is_first wrap_expr(_rbexpr.is_first) end |
#is_in(other) ⇒ Expr
Check if elements of this expression are present in the other Series.
2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 |
# File 'lib/polars/expr.rb', line 2912 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.
624 625 626 |
# File 'lib/polars/expr.rb', line 624 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.
661 662 663 |
# File 'lib/polars/expr.rb', line 661 def is_nan wrap_expr(_rbexpr.is_nan) end |
#is_not ⇒ Expr
Negate a boolean expression.
504 505 506 |
# File 'lib/polars/expr.rb', line 504 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.
698 699 700 |
# File 'lib/polars/expr.rb', line 698 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.
570 571 572 |
# File 'lib/polars/expr.rb', line 570 def is_not_null wrap_expr(_rbexpr.is_not_null) end |
#is_null ⇒ Expr
Returns a boolean Series indicating which values are null.
537 538 539 |
# File 'lib/polars/expr.rb', line 537 def is_null wrap_expr(_rbexpr.is_null) end |
#is_unique ⇒ Expr
Get mask of unique values.
2359 2360 2361 |
# File 'lib/polars/expr.rb', line 2359 def is_unique wrap_expr(_rbexpr.is_unique) end |
#keep_name ⇒ Expr
Keep the original root name of the expression.
417 418 419 |
# File 'lib/polars/expr.rb', line 417 def keep_name wrap_expr(_rbexpr.keep_name) 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
4254 4255 4256 |
# File 'lib/polars/expr.rb', line 4254 def kurtosis(fisher: true, bias: true) wrap_expr(_rbexpr.kurtosis(fisher, bias)) end |
#last ⇒ Expr
Get the last value.
2261 2262 2263 |
# File 'lib/polars/expr.rb', line 2261 def last wrap_expr(_rbexpr.last) end |
#len ⇒ Expr
Count the number of values in this expression.
Alias for #count.
776 777 778 |
# File 'lib/polars/expr.rb', line 776 def len count end |
#limit(n = 10) ⇒ Expr
Get the first n
rows.
Alias for #head.
2856 2857 2858 |
# File 'lib/polars/expr.rb', line 2856 def limit(n = 10) head(n) end |
#list ⇒ Expr
Aggregate to list.
5164 5165 5166 |
# File 'lib/polars/expr.rb', line 5164 def list wrap_expr(_rbexpr.list) end |
#log(base = Math::E) ⇒ Expr
Compute the logarithm to a given base.
5018 5019 5020 |
# File 'lib/polars/expr.rb', line 5018 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.
4381 4382 4383 |
# File 'lib/polars/expr.rb', line 4381 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.
460 461 462 |
# File 'lib/polars/expr.rb', line 460 def map_alias(&f) Utils.wrap_expr(_rbexpr.map_alias(f)) end |
#max ⇒ Expr
Get maximum value.
1960 1961 1962 |
# File 'lib/polars/expr.rb', line 1960 def max wrap_expr(_rbexpr.max) end |
#mean ⇒ Expr
Get mean value.
2064 2065 2066 |
# File 'lib/polars/expr.rb', line 2064 def mean wrap_expr(_rbexpr.mean) end |
#median ⇒ Expr
Get median value using linear interpolation.
2084 2085 2086 |
# File 'lib/polars/expr.rb', line 2084 def median wrap_expr(_rbexpr.median) end |
#meta ⇒ MetaExpr
Create an object namespace of all meta related expression methods.
5229 5230 5231 |
# File 'lib/polars/expr.rb', line 5229 def MetaExpr.new(self) end |
#min ⇒ Expr
Get minimum value.
1980 1981 1982 |
# File 'lib/polars/expr.rb', line 1980 def min wrap_expr(_rbexpr.min) end |
#mode ⇒ Expr
Compute the most occurring value(s).
Can return multiple Values.
1261 1262 1263 |
# File 'lib/polars/expr.rb', line 1261 def mode wrap_expr(_rbexpr.mode) end |
#n_unique ⇒ Expr
Count unique values.
2124 2125 2126 |
# File 'lib/polars/expr.rb', line 2124 def n_unique wrap_expr(_rbexpr.n_unique) end |
#nan_max ⇒ Expr
Get maximum value, but propagate/poison encountered NaN values.
2000 2001 2002 |
# File 'lib/polars/expr.rb', line 2000 def nan_max wrap_expr(_rbexpr.nan_max) end |
#nan_min ⇒ Expr
Get minimum value, but propagate/poison encountered NaN values.
2020 2021 2022 |
# File 'lib/polars/expr.rb', line 2020 def nan_min wrap_expr(_rbexpr.nan_min) end |
#null_count ⇒ Expr
Count null values.
2149 2150 2151 |
# File 'lib/polars/expr.rb', line 2149 def null_count wrap_expr(_rbexpr.null_count) end |
#over(expr) ⇒ Expr
Apply window function over a subgroup.
This is similar to a groupby + aggregation + self join. Or similar to window functions in Postgres.
2334 2335 2336 2337 |
# File 'lib/polars/expr.rb', line 2334 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.
4193 4194 4195 |
# File 'lib/polars/expr.rb', line 4193 def pct_change(n: 1) wrap_expr(_rbexpr.pct_change(n)) end |
#pow(exponent) ⇒ Expr
Raise expression to the power of exponent.
2882 2883 2884 2885 |
# File 'lib/polars/expr.rb', line 2882 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.
424 425 426 |
# File 'lib/polars/expr.rb', line 424 def prefix(prefix) wrap_expr(_rbexpr.prefix(prefix)) end |
#product ⇒ Expr
Compute the product of an expression.
2104 2105 2106 |
# File 'lib/polars/expr.rb', line 2104 def product wrap_expr(_rbexpr.product) end |
#quantile(quantile, interpolation: "nearest") ⇒ Expr
Get quantile value.
2488 2489 2490 2491 |
# File 'lib/polars/expr.rb', line 2488 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) ⇒ Expr
Assign ranks to data, dealing with ties appropriately.
4120 4121 4122 |
# File 'lib/polars/expr.rb', line 4120 def rank(method: "average", reverse: false) wrap_expr(_rbexpr.rank(method, reverse)) end |
#rechunk ⇒ Expr
Create a single chunk of memory for this Series.
880 881 882 |
# File 'lib/polars/expr.rb', line 880 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.
3088 3089 3090 |
# File 'lib/polars/expr.rb', line 3088 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
.
2957 2958 2959 2960 |
# File 'lib/polars/expr.rb', line 2957 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.
4700 4701 4702 |
# File 'lib/polars/expr.rb', line 4700 def reshape(dims) wrap_expr(_rbexpr.reshape(dims)) end |
#reverse ⇒ Expr
Reverse the selection.
1894 1895 1896 |
# File 'lib/polars/expr.rb', line 1894 def reverse wrap_expr(_rbexpr.reverse) 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 groupby_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.
3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 |
# File 'lib/polars/expr.rb', line 3329 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 groupby_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.
3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 |
# File 'lib/polars/expr.rb', line 3423 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") ⇒ 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 groupby_rolling
this method can cache the window size
computation.
Compute a rolling median.
3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 |
# File 'lib/polars/expr.rb', line 3795 def rolling_median( 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_median( window_size, weights, min_periods, center, by, closed ) ) 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 groupby_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.
3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 |
# File 'lib/polars/expr.rb', line 3235 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") ⇒ 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 groupby_rolling
this method can cache the window size
computation.
Compute a rolling quantile.
3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 |
# File 'lib/polars/expr.rb', line 3889 def rolling_quantile( quantile, interpolation: "nearest", window_size: 2, 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_quantile( quantile, interpolation, window_size, weights, min_periods, center, by, closed ) ) end |
#rolling_skew(window_size, bias: true) ⇒ Expr
Compute a rolling skew.
3985 3986 3987 |
# File 'lib/polars/expr.rb', line 3985 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") ⇒ 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 groupby_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.
3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 |
# File 'lib/polars/expr.rb', line 3611 def rolling_std( 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_std( window_size, weights, min_periods, center, by, closed ) ) 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 groupby_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.
3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 |
# File 'lib/polars/expr.rb', line 3517 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") ⇒ 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 groupby_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.
3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 |
# File 'lib/polars/expr.rb', line 3705 def rolling_var( 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_var( window_size, weights, min_periods, center, by, closed ) ) end |
#round(decimals = 0) ⇒ Expr
Round underlying floating point data by decimals
digits.
1203 1204 1205 |
# File 'lib/polars/expr.rb', line 1203 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.
4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 |
# File 'lib/polars/expr.rb', line 4767 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? return wrap_expr(_rbexpr.sample_n(n, with_replacement, shuffle, seed)) end if frac.nil? frac = 1.0 end wrap_expr( _rbexpr.sample_frac(frac, with_replacement, shuffle, seed) ) end |
#search_sorted(element) ⇒ Expr
Find indices where elements should be inserted to maintain order.
1546 1547 1548 1549 |
# File 'lib/polars/expr.rb', line 1546 def search_sorted(element) element = Utils.expr_to_lit_or_expr(element, str_to_lit: false) wrap_expr(_rbexpr.search_sorted(element._rbexpr)) end |
#shift(periods = 1) ⇒ Expr
Shift the values by a given period.
1677 1678 1679 |
# File 'lib/polars/expr.rb', line 1677 def shift(periods = 1) wrap_expr(_rbexpr.shift(periods)) end |
#shift_and_fill(periods, fill_value) ⇒ Expr
Shift the values by a given period and fill the resulting null values.
1708 1709 1710 1711 |
# File 'lib/polars/expr.rb', line 1708 def shift_and_fill(periods, fill_value) fill_value = Utils.expr_to_lit_or_expr(fill_value, str_to_lit: true) wrap_expr(_rbexpr.shift_and_fill(periods, fill_value._rbexpr)) 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.
5201 5202 5203 |
# File 'lib/polars/expr.rb', line 5201 def shrink_dtype wrap_expr(_rbexpr.shrink_dtype) end |
#shuffle(seed: nil) ⇒ Expr
Shuffle the contents of this expr.
4728 4729 4730 4731 4732 4733 |
# File 'lib/polars/expr.rb', line 4728 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.
4432 4433 4434 |
# File 'lib/polars/expr.rb', line 4432 def sign wrap_expr(_rbexpr.sign) end |
#sin ⇒ Expr
Compute the element-wise value for the sine.
4452 4453 4454 |
# File 'lib/polars/expr.rb', line 4452 def sin wrap_expr(_rbexpr.sin) end |
#sinh ⇒ Expr
Compute the element-wise value for the hyperbolic sine.
4572 4573 4574 |
# File 'lib/polars/expr.rb', line 4572 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.
4222 4223 4224 |
# File 'lib/polars/expr.rb', line 4222 def skew(bias: true) wrap_expr(_rbexpr.skew(bias)) end |
#slice(offset, length = nil) ⇒ Expr
Get a slice of this expression.
809 810 811 812 813 814 815 816 817 |
# File 'lib/polars/expr.rb', line 809 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 groupby context, the groups are sorted.
1388 1389 1390 |
# File 'lib/polars/expr.rb', line 1388 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 groupby context, the groups are sorted.
1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 |
# File 'lib/polars/expr.rb', line 1598 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.
246 247 248 |
# File 'lib/polars/expr.rb', line 246 def sqrt self**0.5 end |
#std(ddof: 1) ⇒ Expr
Get standard deviation.
1917 1918 1919 |
# File 'lib/polars/expr.rb', line 1917 def std(ddof: 1) wrap_expr(_rbexpr.std(ddof)) end |
#str ⇒ StringExpr
Create an object namespace of all string related methods.
5236 5237 5238 |
# File 'lib/polars/expr.rb', line 5236 def str StringExpr.new(self) end |
#struct ⇒ StructExpr
Create an object namespace of all struct related methods.
5243 5244 5245 |
# File 'lib/polars/expr.rb', line 5243 def struct StructExpr.new(self) end |
#suffix(suffix) ⇒ Expr
Add a suffix to the root column name of the expression.
431 432 433 |
# File 'lib/polars/expr.rb', line 431 def suffix(suffix) wrap_expr(_rbexpr.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.
2044 2045 2046 |
# File 'lib/polars/expr.rb', line 2044 def sum wrap_expr(_rbexpr.sum) end |
#tail(n = 10) ⇒ Expr
Get the last n
rows.
2844 2845 2846 |
# File 'lib/polars/expr.rb', line 2844 def tail(n = 10) wrap_expr(_rbexpr.tail(n)) end |
#take(indices) ⇒ Expr
Take values by index.
1643 1644 1645 1646 1647 1648 1649 1650 |
# File 'lib/polars/expr.rb', line 1643 def take(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.take(indices_lit._rbexpr)) end |
#take_every(n) ⇒ Expr
Take every nth value in the Series and return as a new Series.
2790 2791 2792 |
# File 'lib/polars/expr.rb', line 2790 def take_every(n) wrap_expr(_rbexpr.take_every(n)) end |
#tan ⇒ Expr
Compute the element-wise value for the tangent.
4492 4493 4494 |
# File 'lib/polars/expr.rb', line 4492 def tan wrap_expr(_rbexpr.tan) end |
#tanh ⇒ Expr
Compute the element-wise value for the hyperbolic tangent.
4612 4613 4614 |
# File 'lib/polars/expr.rb', line 4612 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.
177 178 179 |
# File 'lib/polars/expr.rb', line 177 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, reverse: false) ⇒ Expr
Return the k
largest elements.
If 'reverse: true` the smallest elements will be given.
1432 1433 1434 |
# File 'lib/polars/expr.rb', line 1432 def top_k(k: 5, reverse: false) wrap_expr(_rbexpr.top_k(k, reverse)) end |
#unique(maintain_order: false) ⇒ Expr
Get unique values of this expression.
2217 2218 2219 2220 2221 2222 2223 |
# File 'lib/polars/expr.rb', line 2217 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
4991 4992 4993 |
# File 'lib/polars/expr.rb', line 4991 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.
4404 4405 4406 |
# File 'lib/polars/expr.rb', line 4404 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.
4956 4957 4958 |
# File 'lib/polars/expr.rb', line 4956 def value_counts(multithreaded: false, sort: false) wrap_expr(_rbexpr.value_counts(multithreaded, sort)) end |
#var(ddof: 1) ⇒ Expr
Get variance.
1940 1941 1942 |
# File 'lib/polars/expr.rb', line 1940 def var(ddof: 1) wrap_expr(_rbexpr.var(ddof)) end |
#where(predicate) ⇒ Expr
Filter a single column.
Alias for #filter.
2568 2569 2570 |
# File 'lib/polars/expr.rb', line 2568 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 |