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.
-
#add(other) ⇒ Expr
Method equivalent of addition operator
expr + other
. -
#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_n_unique ⇒ Expr
(also: #approx_unique)
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
k
smallest 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 = nil, upper_bound = nil) ⇒ 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
max
boundary. -
#clip_min(lower_bound) ⇒ 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.
-
#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
1
slot 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.
-
#eq(other) ⇒ Expr
Method equivalent of equality operator
expr == other
. -
#eq_missing(other) ⇒ Expr
Method equivalent of equality operator
expr == other
whereNone == None
. -
#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
Method equivalent of integer division operator
expr // other
. -
#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.
-
#ge(other) ⇒ Expr
Method equivalent of "greater than or equal" operator
expr >= other
. -
#get(index) ⇒ Expr
Return a single value by index.
-
#gt(other) ⇒ Expr
Method equivalent of "greater than" operator
expr > other
. -
#head(n = 10) ⇒ Expr
Get the first
n
rows. -
#implode ⇒ Expr
Aggregate to list.
-
#interpolate(method: "linear") ⇒ Expr
Fill nulls with linear interpolation over missing values.
-
#is_between(lower_bound, upper_bound, 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
(also: #not_)
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.
-
#le(other) ⇒ Expr
Method equivalent of "less than or equal" operator
expr <= other
. -
#len ⇒ Expr
(also: #length)
Count the number of values in this expression.
-
#limit(n = 10) ⇒ Expr
Get the first
n
rows. -
#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.
-
#lt(other) ⇒ Expr
Method equivalent of "less than" operator
expr < other
. -
#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.
-
#mod(other) ⇒ Expr
Method equivalent of modulus operator
expr % other
. -
#mode ⇒ Expr
Compute the most occurring value(s).
-
#mul(other) ⇒ Expr
Method equivalent of multiplication operator
expr * other
. -
#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.
-
#ne(other) ⇒ Expr
Method equivalent of inequality operator
expr != other
. -
#ne_missing(other) ⇒ Expr
Method equivalent of equality operator
expr != other
whereNone == None
. -
#neg ⇒ Expr
Method equivalent of unary minus operator
-expr
. -
#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.
-
#replace(old, new = NO_DEFAULT, default: NO_DEFAULT, return_dtype: nil) ⇒ Expr
Replace values by different values.
-
#replace_strict(old, new = NO_DEFAULT, default: NO_DEFAULT, return_dtype: nil) ⇒ Expr
Replace all values by different values.
-
#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) ⇒ Expr
Apply a rolling max (moving max) over the values in this array.
-
#rolling_max_by(by, window_size, min_periods: 1, closed: "right", warn_if_unsorted: nil) ⇒ Expr
Apply a rolling max based on another column.
-
#rolling_mean(window_size, weights: nil, min_periods: nil, center: false) ⇒ Expr
Apply a rolling mean (moving mean) over the values in this array.
-
#rolling_mean_by(by, window_size, min_periods: 1, closed: "right", warn_if_unsorted: nil) ⇒ Expr
Apply a rolling mean based on another column.
-
#rolling_median(window_size, weights: nil, min_periods: nil, center: false) ⇒ Expr
Compute a rolling median.
-
#rolling_median_by(by, window_size, min_periods: 1, closed: "right", warn_if_unsorted: nil) ⇒ Expr
Compute a rolling median based on another column.
-
#rolling_min(window_size, weights: nil, min_periods: nil, center: false) ⇒ Expr
Apply a rolling min (moving min) over the values in this array.
-
#rolling_min_by(by, window_size, min_periods: 1, closed: "right", warn_if_unsorted: nil) ⇒ Expr
Apply a rolling min based on another column.
-
#rolling_quantile(quantile, interpolation: "nearest", window_size: 2, weights: nil, min_periods: nil, center: false) ⇒ Expr
Compute a rolling quantile.
-
#rolling_quantile_by(by, window_size, quantile:, interpolation: "nearest", min_periods: 1, closed: "right", warn_if_unsorted: nil) ⇒ Expr
Compute a rolling quantile based on another column.
-
#rolling_skew(window_size, bias: true) ⇒ Expr
Compute a rolling skew.
-
#rolling_std(window_size, weights: nil, min_periods: nil, center: false, ddof: 1) ⇒ Expr
Compute a rolling standard deviation.
-
#rolling_std_by(by, window_size, min_periods: 1, closed: "right", ddof: 1, warn_if_unsorted: nil) ⇒ Expr
Compute a rolling standard deviation based on another column.
-
#rolling_sum(window_size, weights: nil, min_periods: nil, center: false) ⇒ Expr
Apply a rolling sum (moving sum) over the values in this array.
-
#rolling_sum_by(by, window_size, min_periods: 1, closed: "right", warn_if_unsorted: nil) ⇒ Expr
Apply a rolling sum based on another column.
-
#rolling_var(window_size, weights: nil, min_periods: nil, center: false, ddof: 1) ⇒ Expr
Compute a rolling variance.
-
#rolling_var_by(by, window_size, min_periods: 1, closed: "right", ddof: 1, warn_if_unsorted: nil) ⇒ Expr
Compute a rolling variance based on another column.
-
#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, 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, *more_by, reverse: false, nulls_last: false, multithreaded: true, maintain_order: 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.
-
#sub(other) ⇒ Expr
Method equivalent of subtraction operator
expr - other
. -
#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. -
#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
k
largest elements. -
#truediv(other) ⇒ Expr
Method equivalent of float division operator
expr / other
. -
#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(sort: false, parallel: false, name: nil, normalize: 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.
-
#xor(other) ⇒ Expr
Method equivalent of bitwise exclusive-or operator
expr ^ other
. -
#|(other) ⇒ Expr
Bitwise OR.
Instance Method Details
#!=(other) ⇒ Expr
Not equal.
113 114 115 |
# File 'lib/polars/expr.rb', line 113 def !=(other) _from_rbexpr(_rbexpr.neq(_to_expr(other)._rbexpr)) end |
#%(other) ⇒ Expr
Returns the modulo.
77 78 79 |
# File 'lib/polars/expr.rb', line 77 def %(other) _from_rbexpr(_rbexpr % _to_rbexpr(other)) end |
#&(other) ⇒ Expr
Bitwise AND.
35 36 37 |
# File 'lib/polars/expr.rb', line 35 def &(other) _from_rbexpr(_rbexpr._and(_to_rbexpr(other))) end |
#*(other) ⇒ Expr
Performs multiplication.
63 64 65 |
# File 'lib/polars/expr.rb', line 63 def *(other) _from_rbexpr(_rbexpr * _to_rbexpr(other)) end |
#**(power) ⇒ Expr
Raises to the power of exponent.
84 85 86 87 |
# File 'lib/polars/expr.rb', line 84 def **(power) exponent = Utils.parse_into_expression(power) _from_rbexpr(_rbexpr.pow(exponent)) end |
#+(other) ⇒ Expr
Performs addition.
49 50 51 |
# File 'lib/polars/expr.rb', line 49 def +(other) _from_rbexpr(_rbexpr + _to_rbexpr(other)) end |
#-(other) ⇒ Expr
Performs subtraction.
56 57 58 |
# File 'lib/polars/expr.rb', line 56 def -(other) _from_rbexpr(_rbexpr - _to_rbexpr(other)) end |
#-@ ⇒ Expr
Performs negation.
141 142 143 |
# File 'lib/polars/expr.rb', line 141 def -@ _from_rbexpr(_rbexpr.neg) end |
#/(other) ⇒ Expr
Performs division.
70 71 72 |
# File 'lib/polars/expr.rb', line 70 def /(other) _from_rbexpr(_rbexpr / _to_rbexpr(other)) end |
#<(other) ⇒ Expr
Less than.
120 121 122 |
# File 'lib/polars/expr.rb', line 120 def <(other) _from_rbexpr(_rbexpr.lt(_to_expr(other)._rbexpr)) end |
#<=(other) ⇒ Expr
Less than or equal.
99 100 101 |
# File 'lib/polars/expr.rb', line 99 def <=(other) _from_rbexpr(_rbexpr.lt_eq(_to_expr(other)._rbexpr)) end |
#==(other) ⇒ Expr
Equal.
106 107 108 |
# File 'lib/polars/expr.rb', line 106 def ==(other) _from_rbexpr(_rbexpr.eq(_to_expr(other)._rbexpr)) end |
#>(other) ⇒ Expr
Greater than.
127 128 129 |
# File 'lib/polars/expr.rb', line 127 def >(other) _from_rbexpr(_rbexpr.gt(_to_expr(other)._rbexpr)) end |
#>=(other) ⇒ Expr
Greater than or equal.
92 93 94 |
# File 'lib/polars/expr.rb', line 92 def >=(other) _from_rbexpr(_rbexpr.gt_eq(_to_expr(other)._rbexpr)) end |
#^(other) ⇒ Expr
Bitwise XOR.
28 29 30 |
# File 'lib/polars/expr.rb', line 28 def ^(other) _from_rbexpr(_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
.
3892 3893 3894 3895 3896 3897 3898 |
# File 'lib/polars/expr.rb', line 3892 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 _from_rbexpr(_rbexpr._hash(k0, k1, k2, k3)) end |
#abs ⇒ Expr
Compute absolute values.
5732 5733 5734 |
# File 'lib/polars/expr.rb', line 5732 def abs _from_rbexpr(_rbexpr.abs) end |
#add(other) ⇒ Expr
Method equivalent of addition operator expr + other
.
3481 3482 3483 |
# File 'lib/polars/expr.rb', line 3481 def add(other) self + other end |
#agg_groups ⇒ Expr
Get the group indexes of the group by operation.
Should be used in aggregation context only.
741 742 743 |
# File 'lib/polars/expr.rb', line 741 def agg_groups _from_rbexpr(_rbexpr.agg_groups) end |
#alias(name) ⇒ Expr
Rename the output of an expression.
324 325 326 |
# File 'lib/polars/expr.rb', line 324 def alias(name) _from_rbexpr(_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.
223 224 225 |
# File 'lib/polars/expr.rb', line 223 def all(drop_nulls: true) _from_rbexpr(_rbexpr.all(drop_nulls)) end |
#any(drop_nulls: true) ⇒ Boolean
Check if any boolean value in a Boolean column is true
.
198 199 200 |
# File 'lib/polars/expr.rb', line 198 def any(drop_nulls: true) _from_rbexpr(_rbexpr.any(drop_nulls)) end |
#append(other, upcast: true) ⇒ Expr
Append expressions.
This is done by adding the chunks of other
to this Series
.
853 854 855 856 |
# File 'lib/polars/expr.rb', line 853 def append(other, upcast: true) other = Utils.parse_into_expression(other) _from_rbexpr(_rbexpr.append(other, upcast)) end |
#approx_n_unique ⇒ Expr Also known as: approx_unique
Approx count unique values.
This is done using the HyperLogLog++ algorithm for cardinality estimation.
2187 2188 2189 |
# File 'lib/polars/expr.rb', line 2187 def approx_n_unique _from_rbexpr(_rbexpr.approx_n_unique) end |
#arccos ⇒ Expr
Compute the element-wise value for the inverse cosine.
6227 6228 6229 |
# File 'lib/polars/expr.rb', line 6227 def arccos _from_rbexpr(_rbexpr.arccos) end |
#arccosh ⇒ Expr
Compute the element-wise value for the inverse hyperbolic cosine.
6347 6348 6349 |
# File 'lib/polars/expr.rb', line 6347 def arccosh _from_rbexpr(_rbexpr.arccosh) end |
#arcsin ⇒ Expr
Compute the element-wise value for the inverse sine.
6207 6208 6209 |
# File 'lib/polars/expr.rb', line 6207 def arcsin _from_rbexpr(_rbexpr.arcsin) end |
#arcsinh ⇒ Expr
Compute the element-wise value for the inverse hyperbolic sine.
6327 6328 6329 |
# File 'lib/polars/expr.rb', line 6327 def arcsinh _from_rbexpr(_rbexpr.arcsinh) end |
#arctan ⇒ Expr
Compute the element-wise value for the inverse tangent.
6247 6248 6249 |
# File 'lib/polars/expr.rb', line 6247 def arctan _from_rbexpr(_rbexpr.arctan) end |
#arctanh ⇒ Expr
Compute the element-wise value for the inverse hyperbolic tangent.
6367 6368 6369 |
# File 'lib/polars/expr.rb', line 6367 def arctanh _from_rbexpr(_rbexpr.arctanh) end |
#arg_max ⇒ Expr
Get the index of the maximal value.
1483 1484 1485 |
# File 'lib/polars/expr.rb', line 1483 def arg_max _from_rbexpr(_rbexpr.arg_max) end |
#arg_min ⇒ Expr
Get the index of the minimal value.
1507 1508 1509 |
# File 'lib/polars/expr.rb', line 1507 def arg_min _from_rbexpr(_rbexpr.arg_min) end |
#arg_sort(reverse: false, nulls_last: false) ⇒ Expr
Get the index values that would sort this column.
1459 1460 1461 |
# File 'lib/polars/expr.rb', line 1459 def arg_sort(reverse: false, nulls_last: false) _from_rbexpr(_rbexpr.arg_sort(reverse, nulls_last)) end |
#arg_unique ⇒ Expr
Get index of first unique value.
2253 2254 2255 |
# File 'lib/polars/expr.rb', line 2253 def arg_unique _from_rbexpr(_rbexpr.arg_unique) end |
#argsort(reverse: false, nulls_last: false) ⇒ expr
Get the index values that would sort this column.
Alias for #arg_sort.
5765 5766 5767 |
# File 'lib/polars/expr.rb', line 5765 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.
7240 7241 7242 |
# File 'lib/polars/expr.rb', line 7240 def arr ArrayExpr.new(self) end |
#backward_fill(limit: nil) ⇒ Expr
Fill missing values with the next to be seen values.
1899 1900 1901 |
# File 'lib/polars/expr.rb', line 1899 def backward_fill(limit: nil) _from_rbexpr(_rbexpr.backward_fill(limit)) end |
#bin ⇒ BinaryExpr
Create an object namespace of all binary related methods.
7247 7248 7249 |
# File 'lib/polars/expr.rb', line 7247 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.
1427 1428 1429 1430 |
# File 'lib/polars/expr.rb', line 1427 def bottom_k(k: 5) k = Utils.parse_into_expression(k) _from_rbexpr(_rbexpr.bottom_k(k)) end |
#cast(dtype, strict: true) ⇒ Expr
Cast between data types.
1274 1275 1276 1277 |
# File 'lib/polars/expr.rb', line 1274 def cast(dtype, strict: true) dtype = Utils.rb_type_to_dtype(dtype) _from_rbexpr(_rbexpr.cast(dtype, strict)) end |
#cat ⇒ CatExpr
Create an object namespace of all categorical related methods.
7254 7255 7256 |
# File 'lib/polars/expr.rb', line 7254 def cat CatExpr.new(self) end |
#ceil ⇒ Expr
Rounds up to the nearest integer value.
Only works on floating point Series.
1153 1154 1155 |
# File 'lib/polars/expr.rb', line 1153 def ceil _from_rbexpr(_rbexpr.ceil) end |
#clip(lower_bound = nil, upper_bound = nil) ⇒ 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.
5989 5990 5991 5992 5993 5994 5995 5996 5997 |
# File 'lib/polars/expr.rb', line 5989 def clip(lower_bound = nil, upper_bound = nil) if !lower_bound.nil? lower_bound = Utils.parse_into_expression(lower_bound) end if !upper_bound.nil? upper_bound = Utils.parse_into_expression(upper_bound) end _from_rbexpr(_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.
6057 6058 6059 |
# File 'lib/polars/expr.rb', line 6057 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.
6026 6027 6028 |
# File 'lib/polars/expr.rb', line 6026 def clip_min(lower_bound) clip(lower_bound, nil) end |
#cos ⇒ Expr
Compute the element-wise value for the cosine.
6167 6168 6169 |
# File 'lib/polars/expr.rb', line 6167 def cos _from_rbexpr(_rbexpr.cos) end |
#cosh ⇒ Expr
Compute the element-wise value for the hyperbolic cosine.
6287 6288 6289 |
# File 'lib/polars/expr.rb', line 6287 def cosh _from_rbexpr(_rbexpr.cosh) end |
#count ⇒ Expr
Count the number of values in this expression.
761 762 763 |
# File 'lib/polars/expr.rb', line 761 def count _from_rbexpr(_rbexpr.count) 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
1102 1103 1104 |
# File 'lib/polars/expr.rb', line 1102 def cum_count(reverse: false) _from_rbexpr(_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.
1068 1069 1070 |
# File 'lib/polars/expr.rb', line 1068 def cum_max(reverse: false) _from_rbexpr(_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.
1036 1037 1038 |
# File 'lib/polars/expr.rb', line 1036 def cum_min(reverse: false) _from_rbexpr(_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.
1004 1005 1006 |
# File 'lib/polars/expr.rb', line 1004 def cum_prod(reverse: false) _from_rbexpr(_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.
968 969 970 |
# File 'lib/polars/expr.rb', line 968 def cum_sum(reverse: false) _from_rbexpr(_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.
6822 6823 6824 6825 6826 |
# File 'lib/polars/expr.rb', line 6822 def cumulative_eval(expr, min_periods: 1, parallel: false) _from_rbexpr( _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.
2636 2637 2638 |
# File 'lib/polars/expr.rb', line 2636 def cut(breaks, labels: nil, left_closed: false, include_breaks: false) _from_rbexpr(_rbexpr.cut(breaks, labels, left_closed, include_breaks)) end |
#diff(n: 1, null_behavior: "ignore") ⇒ Expr
Calculate the n-th discrete difference.
5860 5861 5862 |
# File 'lib/polars/expr.rb', line 5860 def diff(n: 1, null_behavior: "ignore") _from_rbexpr(_rbexpr.diff(n, null_behavior)) end |
#dot(other) ⇒ Expr
Compute the dot/inner product between two Expressions.
1207 1208 1209 1210 |
# File 'lib/polars/expr.rb', line 1207 def dot(other) other = Utils.parse_into_expression(other, str_as_lit: false) _from_rbexpr(_rbexpr.dot(other)) end |
#drop_nans ⇒ Expr
Drop floating point NaN values.
933 934 935 |
# File 'lib/polars/expr.rb', line 933 def drop_nans _from_rbexpr(_rbexpr.drop_nans) end |
#drop_nulls ⇒ Expr
Drop null values.
906 907 908 |
# File 'lib/polars/expr.rb', line 906 def drop_nulls _from_rbexpr(_rbexpr.drop_nulls) end |
#dt ⇒ DateTimeExpr
Create an object namespace of all datetime related methods.
7261 7262 7263 |
# File 'lib/polars/expr.rb', line 7261 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.
6775 6776 6777 |
# File 'lib/polars/expr.rb', line 6775 def entropy(base: 2, normalize: true) _from_rbexpr(_rbexpr.entropy(base, normalize)) end |
#eq(other) ⇒ Expr
Method equivalent of equality operator expr == other
.
3191 3192 3193 |
# File 'lib/polars/expr.rb', line 3191 def eq(other) self == other end |
#eq_missing(other) ⇒ Expr
Method equivalent of equality operator expr == other
where None == None
.
This differs from default eq
where null values are propagated.
3229 3230 3231 3232 |
# File 'lib/polars/expr.rb', line 3229 def eq_missing(other) other = Utils.parse_into_expression(other, str_as_lit: true) _from_rbexpr(_rbexpr.eq_missing(other)) 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.
6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 |
# File 'lib/polars/expr.rb', line 6519 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) _from_rbexpr(_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.
6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 |
# File 'lib/polars/expr.rb', line 6550 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) _from_rbexpr(_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.
6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 |
# File 'lib/polars/expr.rb', line 6582 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) _from_rbexpr(_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 $
.
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'lib/polars/expr.rb', line 365 def exclude(columns) if columns.is_a?(::String) columns = [columns] return _from_rbexpr(_rbexpr.exclude(columns)) elsif !columns.is_a?(::Array) columns = [columns] return _from_rbexpr(_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) _from_rbexpr(_rbexpr.exclude(columns)) else _from_rbexpr(_rbexpr.exclude_dtype(columns)) end end |
#exp ⇒ Expr
Compute the exponential, element-wise.
289 290 291 |
# File 'lib/polars/expr.rb', line 289 def exp _from_rbexpr(_rbexpr.exp) end |
#explode ⇒ Expr
Explode a list or utf8 Series.
This means that every item is expanded to a new row.
3059 3060 3061 |
# File 'lib/polars/expr.rb', line 3059 def explode _from_rbexpr(_rbexpr.explode) end |
#extend_constant(value, n) ⇒ Expr
Extend the Series with given number of values.
6622 6623 6624 |
# File 'lib/polars/expr.rb', line 6622 def extend_constant(value, n) _from_rbexpr(_rbexpr.extend_constant(value, n)) end |
#fill_nan(fill_value) ⇒ Expr
Fill floating point NaN value with a fill value.
1838 1839 1840 1841 |
# File 'lib/polars/expr.rb', line 1838 def fill_nan(fill_value) fill_value = Utils.parse_into_expression(fill_value, str_as_lit: true) _from_rbexpr(_rbexpr.fill_nan(fill_value)) 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.
1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 |
# File 'lib/polars/expr.rb', line 1798 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.parse_into_expression(value, str_as_lit: true) _from_rbexpr(_rbexpr.fill_null(value)) else _from_rbexpr(_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
.
2819 2820 2821 |
# File 'lib/polars/expr.rb', line 2819 def filter(predicate) _from_rbexpr(_rbexpr.filter(predicate._rbexpr)) end |
#first ⇒ Expr
Get the first value.
2301 2302 2303 |
# File 'lib/polars/expr.rb', line 2301 def first _from_rbexpr(_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.
3032 3033 3034 |
# File 'lib/polars/expr.rb', line 3032 def flatten _from_rbexpr(_rbexpr.explode) end |
#floor ⇒ Expr
Rounds down to the nearest integer value.
Only works on floating point Series.
1128 1129 1130 |
# File 'lib/polars/expr.rb', line 1128 def floor _from_rbexpr(_rbexpr.floor) end |
#floordiv(other) ⇒ Expr
Method equivalent of integer division operator expr // other
.
3511 3512 3513 |
# File 'lib/polars/expr.rb', line 3511 def floordiv(other) _from_rbexpr(_rbexpr.floordiv(_to_rbexpr(other))) end |
#forward_fill(limit: nil) ⇒ Expr
Fill missing values with the latest seen values.
1869 1870 1871 |
# File 'lib/polars/expr.rb', line 1869 def forward_fill(limit: nil) _from_rbexpr(_rbexpr.forward_fill(limit)) end |
#gather(indices) ⇒ Expr Also known as: take
Take values by index.
1630 1631 1632 1633 1634 1635 1636 1637 |
# File 'lib/polars/expr.rb', line 1630 def gather(indices) if indices.is_a?(::Array) indices_lit = Polars.lit(Series.new("", indices, dtype: :u32))._rbexpr else indices_lit = Utils.parse_into_expression(indices, str_as_lit: false) end _from_rbexpr(_rbexpr.gather(indices_lit)) 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.
3081 3082 3083 |
# File 'lib/polars/expr.rb', line 3081 def gather_every(n, offset = 0) _from_rbexpr(_rbexpr.gather_every(n, offset)) end |
#ge(other) ⇒ Expr
Method equivalent of "greater than or equal" operator expr >= other
.
3263 3264 3265 |
# File 'lib/polars/expr.rb', line 3263 def ge(other) self >= other end |
#get(index) ⇒ Expr
Return a single value by index.
1672 1673 1674 1675 |
# File 'lib/polars/expr.rb', line 1672 def get(index) index_lit = Utils.parse_into_expression(index) _from_rbexpr(_rbexpr.get(index_lit)) end |
#gt(other) ⇒ Expr
Method equivalent of "greater than" operator expr > other
.
3296 3297 3298 |
# File 'lib/polars/expr.rb', line 3296 def gt(other) self > other end |
#head(n = 10) ⇒ Expr
Get the first n
rows.
3107 3108 3109 |
# File 'lib/polars/expr.rb', line 3107 def head(n = 10) _from_rbexpr(_rbexpr.head(n)) end |
#implode ⇒ Expr
Aggregate to list.
6878 6879 6880 |
# File 'lib/polars/expr.rb', line 6878 def implode _from_rbexpr(_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.
3993 3994 3995 |
# File 'lib/polars/expr.rb', line 3993 def interpolate(method: "linear") _from_rbexpr(_rbexpr.interpolate(method)) end |
#is_between(lower_bound, upper_bound, closed: "both") ⇒ Expr
Check if this expression is between start and end.
3849 3850 3851 3852 3853 3854 3855 3856 |
# File 'lib/polars/expr.rb', line 3849 def is_between(lower_bound, upper_bound, closed: "both") lower_bound = Utils.parse_into_expression(lower_bound) upper_bound = Utils.parse_into_expression(upper_bound) _from_rbexpr( _rbexpr.is_between(lower_bound, upper_bound, closed) ) end |
#is_duplicated ⇒ Expr
Get mask of duplicated values.
2458 2459 2460 |
# File 'lib/polars/expr.rb', line 2458 def is_duplicated _from_rbexpr(_rbexpr.is_duplicated) end |
#is_finite ⇒ Expr
Returns a boolean Series indicating which values are finite.
614 615 616 |
# File 'lib/polars/expr.rb', line 614 def is_finite _from_rbexpr(_rbexpr.is_finite) end |
#is_first_distinct ⇒ Expr Also known as: is_first
Get a mask of the first unique value.
2435 2436 2437 |
# File 'lib/polars/expr.rb', line 2435 def is_first_distinct _from_rbexpr(_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.
3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 |
# File 'lib/polars/expr.rb', line 3734 def is_in(other) if other.is_a?(::Array) if other.length == 0 other = Polars.lit(nil)._rbexpr else other = Polars.lit(Series.new(other))._rbexpr end else other = Utils.parse_into_expression(other, str_as_lit: false) end _from_rbexpr(_rbexpr.is_in(other)) end |
#is_infinite ⇒ Expr
Returns a boolean Series indicating which values are infinite.
640 641 642 |
# File 'lib/polars/expr.rb', line 640 def is_infinite _from_rbexpr(_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.
673 674 675 |
# File 'lib/polars/expr.rb', line 673 def is_nan _from_rbexpr(_rbexpr.is_nan) end |
#is_not ⇒ Expr Also known as: not_
Negate a boolean expression.
529 530 531 |
# File 'lib/polars/expr.rb', line 529 def is_not _from_rbexpr(_rbexpr.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.
706 707 708 |
# File 'lib/polars/expr.rb', line 706 def is_not_nan _from_rbexpr(_rbexpr.is_not_nan) end |
#is_not_null ⇒ Expr
Returns a boolean Series indicating which values are not null.
588 589 590 |
# File 'lib/polars/expr.rb', line 588 def is_not_null _from_rbexpr(_rbexpr.is_not_null) end |
#is_null ⇒ Expr
Returns a boolean Series indicating which values are null.
559 560 561 |
# File 'lib/polars/expr.rb', line 559 def is_null _from_rbexpr(_rbexpr.is_null) end |
#is_unique ⇒ Expr
Get mask of unique values.
2407 2408 2409 |
# File 'lib/polars/expr.rb', line 2407 def is_unique _from_rbexpr(_rbexpr.is_unique) end |
#keep_name ⇒ Expr
Keep the original root name of the expression.
407 408 409 |
# File 'lib/polars/expr.rb', line 407 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
5958 5959 5960 |
# File 'lib/polars/expr.rb', line 5958 def kurtosis(fisher: true, bias: true) _from_rbexpr(_rbexpr.kurtosis(fisher, bias)) end |
#last ⇒ Expr
Get the last value.
2321 2322 2323 |
# File 'lib/polars/expr.rb', line 2321 def last _from_rbexpr(_rbexpr.last) end |
#le(other) ⇒ Expr
Method equivalent of "less than or equal" operator expr <= other
.
3329 3330 3331 |
# File 'lib/polars/expr.rb', line 3329 def le(other) self <= other end |
#len ⇒ Expr Also known as: length
Count the number of values in this expression.
781 782 783 |
# File 'lib/polars/expr.rb', line 781 def len _from_rbexpr(_rbexpr.len) end |
#limit(n = 10) ⇒ Expr
Get the first n
rows.
Alias for #head.
3159 3160 3161 |
# File 'lib/polars/expr.rb', line 3159 def limit(n = 10) head(n) end |
#list ⇒ ListExpr
Create an object namespace of all list related methods.
7233 7234 7235 |
# File 'lib/polars/expr.rb', line 7233 def list ListExpr.new(self) end |
#log(base = Math::E) ⇒ Expr
Compute the logarithm to a given base.
6736 6737 6738 |
# File 'lib/polars/expr.rb', line 6736 def log(base = Math::E) _from_rbexpr(_rbexpr.log(base)) end |
#log10 ⇒ Expr
Compute the base 10 logarithm of the input array, element-wise.
267 268 269 |
# File 'lib/polars/expr.rb', line 267 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.
6080 6081 6082 |
# File 'lib/polars/expr.rb', line 6080 def lower_bound _from_rbexpr(_rbexpr.lower_bound) end |
#lt(other) ⇒ Expr
Method equivalent of "less than" operator expr < other
.
3362 3363 3364 |
# File 'lib/polars/expr.rb', line 3362 def lt(other) self < other end |
#map_alias(&f) ⇒ Expr
Rename the output of an expression by mapping a function over the root name.
489 490 491 |
# File 'lib/polars/expr.rb', line 489 def map_alias(&f) name.map(&f) end |
#max ⇒ Expr
Get maximum value.
2001 2002 2003 |
# File 'lib/polars/expr.rb', line 2001 def max _from_rbexpr(_rbexpr.max) end |
#mean ⇒ Expr
Get mean value.
2105 2106 2107 |
# File 'lib/polars/expr.rb', line 2105 def mean _from_rbexpr(_rbexpr.mean) end |
#median ⇒ Expr
Get median value using linear interpolation.
2125 2126 2127 |
# File 'lib/polars/expr.rb', line 2125 def median _from_rbexpr(_rbexpr.median) end |
#meta ⇒ MetaExpr
Create an object namespace of all meta related expression methods.
7268 7269 7270 |
# File 'lib/polars/expr.rb', line 7268 def MetaExpr.new(self) end |
#min ⇒ Expr
Get minimum value.
2021 2022 2023 |
# File 'lib/polars/expr.rb', line 2021 def min _from_rbexpr(_rbexpr.min) end |
#mod(other) ⇒ Expr
Method equivalent of modulus operator expr % other
.
3538 3539 3540 |
# File 'lib/polars/expr.rb', line 3538 def mod(other) self % other end |
#mode ⇒ Expr
Compute the most occurring value(s).
Can return multiple Values.
1236 1237 1238 |
# File 'lib/polars/expr.rb', line 1236 def mode _from_rbexpr(_rbexpr.mode) end |
#mul(other) ⇒ Expr
Method equivalent of multiplication operator expr * other
.
3568 3569 3570 |
# File 'lib/polars/expr.rb', line 3568 def mul(other) self * other end |
#n_unique ⇒ Expr
Count unique values.
2165 2166 2167 |
# File 'lib/polars/expr.rb', line 2165 def n_unique _from_rbexpr(_rbexpr.n_unique) end |
#name ⇒ NameExpr
Create an object namespace of all expressions that modify expression names.
7275 7276 7277 |
# File 'lib/polars/expr.rb', line 7275 def name NameExpr.new(self) end |
#nan_max ⇒ Expr
Get maximum value, but propagate/poison encountered NaN values.
2041 2042 2043 |
# File 'lib/polars/expr.rb', line 2041 def nan_max _from_rbexpr(_rbexpr.nan_max) end |
#nan_min ⇒ Expr
Get minimum value, but propagate/poison encountered NaN values.
2061 2062 2063 |
# File 'lib/polars/expr.rb', line 2061 def nan_min _from_rbexpr(_rbexpr.nan_min) end |
#ne(other) ⇒ Expr
Method equivalent of inequality operator expr != other
.
3395 3396 3397 |
# File 'lib/polars/expr.rb', line 3395 def ne(other) self != other end |
#ne_missing(other) ⇒ Expr
Method equivalent of equality operator expr != other
where None == None
.
This differs from default ne
where null values are propagated.
3433 3434 3435 3436 |
# File 'lib/polars/expr.rb', line 3433 def ne_missing(other) other = Utils.parse_into_expression(other, str_as_lit: true) _from_rbexpr(_rbexpr.neq_missing(other)) end |
#neg ⇒ Expr
Method equivalent of unary minus operator -expr
.
3621 3622 3623 |
# File 'lib/polars/expr.rb', line 3621 def neg -self end |
#null_count ⇒ Expr
Count null values.
2213 2214 2215 |
# File 'lib/polars/expr.rb', line 2213 def null_count _from_rbexpr(_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.
2384 2385 2386 2387 |
# File 'lib/polars/expr.rb', line 2384 def over(expr) rbexprs = Utils.parse_into_list_of_expressions(expr) _from_rbexpr(_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.
5896 5897 5898 5899 |
# File 'lib/polars/expr.rb', line 5896 def pct_change(n: 1) n = Utils.parse_into_expression(n) _from_rbexpr(_rbexpr.pct_change(n)) end |
#peak_max ⇒ Expr
Get a boolean mask of the local maximum peaks.
2482 2483 2484 |
# File 'lib/polars/expr.rb', line 2482 def peak_max _from_rbexpr(_rbexpr.peak_max) end |
#peak_min ⇒ Expr
Get a boolean mask of the local minimum peaks.
2506 2507 2508 |
# File 'lib/polars/expr.rb', line 2506 def peak_min _from_rbexpr(_rbexpr.peak_min) end |
#pow(exponent) ⇒ Expr
Raise expression to the power of exponent.
3679 3680 3681 |
# File 'lib/polars/expr.rb', line 3679 def pow(exponent) self**exponent end |
#prefix(prefix) ⇒ Expr
Add a prefix to the root column name of the expression.
434 435 436 |
# File 'lib/polars/expr.rb', line 434 def prefix(prefix) name.prefix(prefix) end |
#product ⇒ Expr
Compute the product of an expression.
2145 2146 2147 |
# File 'lib/polars/expr.rb', line 2145 def product _from_rbexpr(_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.
2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 |
# File 'lib/polars/expr.rb', line 2717 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 _from_rbexpr(rbexpr) end |
#quantile(quantile, interpolation: "nearest") ⇒ Expr
Get quantile value.
2579 2580 2581 2582 |
# File 'lib/polars/expr.rb', line 2579 def quantile(quantile, interpolation: "nearest") quantile = Utils.parse_into_expression(quantile, str_as_lit: false) _from_rbexpr(_rbexpr.quantile(quantile, interpolation)) end |
#rank(method: "average", reverse: false, seed: nil) ⇒ Expr
Assign ranks to data, dealing with ties appropriately.
5829 5830 5831 |
# File 'lib/polars/expr.rb', line 5829 def rank(method: "average", reverse: false, seed: nil) _from_rbexpr(_rbexpr.rank(method, reverse, seed)) end |
#rechunk ⇒ Expr
Create a single chunk of memory for this Series.
879 880 881 |
# File 'lib/polars/expr.rb', line 879 def rechunk _from_rbexpr(_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.
3930 3931 3932 |
# File 'lib/polars/expr.rb', line 3930 def reinterpret(signed: false) _from_rbexpr(_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
.
3778 3779 3780 3781 |
# File 'lib/polars/expr.rb', line 3778 def repeat_by(by) by = Utils.parse_into_expression(by, str_as_lit: false) _from_rbexpr(_rbexpr.repeat_by(by)) end |
#replace(old, new = NO_DEFAULT, default: NO_DEFAULT, return_dtype: nil) ⇒ Expr
Replace values by different values.
7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 |
# File 'lib/polars/expr.rb', line 7053 def replace(old, new = NO_DEFAULT, default: NO_DEFAULT, return_dtype: nil) if !default.eql?(NO_DEFAULT) return replace_strict(old, new, default: default, return_dtype: return_dtype) end if new.eql?(NO_DEFAULT) && old.is_a?(Hash) new = Series.new(old.values) old = Series.new(old.keys) else if old.is_a?(::Array) old = Series.new(old) end if new.is_a?(::Array) new = Series.new(new) end end old = Utils.parse_into_expression(old, str_as_lit: true) new = Utils.parse_into_expression(new, str_as_lit: true) result = _from_rbexpr(_rbexpr.replace(old, new)) if !return_dtype.nil? result = result.cast(return_dtype) end result end |
#replace_strict(old, new = NO_DEFAULT, default: NO_DEFAULT, return_dtype: nil) ⇒ Expr
The global string cache must be enabled when replacing categorical values.
Replace all values by different values.
7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 |
# File 'lib/polars/expr.rb', line 7209 def replace_strict( old, new = NO_DEFAULT, default: NO_DEFAULT, return_dtype: nil ) if new.eql?(NO_DEFAULT) && old.is_a?(Hash) new = Series.new(old.values) old = Series.new(old.keys) end old = Utils.parse_into_expression(old, str_as_lit: true, list_as_series: true) new = Utils.parse_into_expression(new, str_as_lit: true, list_as_series: true) default = default.eql?(NO_DEFAULT) ? nil : Utils.parse_into_expression(default, str_as_lit: true) _from_rbexpr( _rbexpr.replace_strict(old, new, default, return_dtype) ) end |
#reshape(dims) ⇒ Expr
Reshape this Expr to a flat Series or a Series of Lists.
6413 6414 6415 |
# File 'lib/polars/expr.rb', line 6413 def reshape(dims) _from_rbexpr(_rbexpr.reshape(dims)) end |
#reverse ⇒ Expr
Reverse the selection.
1935 1936 1937 |
# File 'lib/polars/expr.rb', line 1935 def reverse _from_rbexpr(_rbexpr.reverse) end |
#rle ⇒ Expr
Get the lengths of runs of identical values.
2752 2753 2754 |
# File 'lib/polars/expr.rb', line 2752 def rle _from_rbexpr(_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.
2780 2781 2782 |
# File 'lib/polars/expr.rb', line 2780 def rle_id _from_rbexpr(_rbexpr.rle_id) end |
#rolling_max(window_size, weights: nil, min_periods: nil, center: false) ⇒ 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.
5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 |
# File 'lib/polars/expr.rb', line 5136 def rolling_max( window_size, weights: nil, min_periods: nil, center: false ) _from_rbexpr( _rbexpr.rolling_max( window_size, weights, min_periods, center ) ) end |
#rolling_max_by(by, window_size, min_periods: 1, closed: "right", warn_if_unsorted: nil) ⇒ Expr
If you want to compute multiple aggregation statistics over the same dynamic
window, consider using rolling
- this method can cache the window size
computation.
Apply a rolling max based on another column.
4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 |
# File 'lib/polars/expr.rb', line 4215 def rolling_max_by( by, window_size, min_periods: 1, closed: "right", warn_if_unsorted: nil ) window_size = _prepare_rolling_by_window_args(window_size) by = Utils.parse_into_expression(by) _from_rbexpr( _rbexpr.rolling_max_by(by, window_size, min_periods, closed) ) end |
#rolling_mean(window_size, weights: nil, min_periods: nil, center: false) ⇒ 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.
5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 |
# File 'lib/polars/expr.rb', line 5214 def rolling_mean( window_size, weights: nil, min_periods: nil, center: false ) _from_rbexpr( _rbexpr.rolling_mean( window_size, weights, min_periods, center ) ) end |
#rolling_mean_by(by, window_size, min_periods: 1, closed: "right", warn_if_unsorted: nil) ⇒ Expr
If you want to compute multiple aggregation statistics over the same dynamic
window, consider using rolling
- this method can cache the window size
computation.
Apply a rolling mean based on another column.
4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 |
# File 'lib/polars/expr.rb', line 4346 def rolling_mean_by( by, window_size, min_periods: 1, closed: "right", warn_if_unsorted: nil ) window_size = _prepare_rolling_by_window_args(window_size) by = Utils.parse_into_expression(by) _from_rbexpr( _rbexpr.rolling_mean_by( by, window_size, min_periods, closed ) ) end |
#rolling_median(window_size, weights: nil, min_periods: nil, center: false) ⇒ 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.
5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 |
# File 'lib/polars/expr.rb', line 5524 def rolling_median( window_size, weights: nil, min_periods: nil, center: false ) _from_rbexpr( _rbexpr.rolling_median( window_size, weights, min_periods, center ) ) end |
#rolling_median_by(by, window_size, min_periods: 1, closed: "right", warn_if_unsorted: nil) ⇒ Expr
If you want to compute multiple aggregation statistics over the same dynamic
window, consider using rolling
- this method can cache the window size
computation.
Compute a rolling median based on another column.
4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 |
# File 'lib/polars/expr.rb', line 4861 def rolling_median_by( by, window_size, min_periods: 1, closed: "right", warn_if_unsorted: nil ) window_size = _prepare_rolling_by_window_args(window_size) by = Utils.parse_into_expression(by) _from_rbexpr( _rbexpr.rolling_median_by(by, window_size, min_periods, closed) ) end |
#rolling_min(window_size, weights: nil, min_periods: nil, center: false) ⇒ 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.
5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 |
# File 'lib/polars/expr.rb', line 5058 def rolling_min( window_size, weights: nil, min_periods: nil, center: false ) _from_rbexpr( _rbexpr.rolling_min( window_size, weights, min_periods, center ) ) end |
#rolling_min_by(by, window_size, min_periods: 1, closed: "right", warn_if_unsorted: nil) ⇒ Expr
If you want to compute multiple aggregation statistics over the same dynamic
window, consider using rolling
- this method can cache the window size
computation.
Apply a rolling min based on another column.
4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 |
# File 'lib/polars/expr.rb', line 4086 def rolling_min_by( by, window_size, min_periods: 1, closed: "right", warn_if_unsorted: nil ) window_size = _prepare_rolling_by_window_args(window_size) by = Utils.parse_into_expression(by) _from_rbexpr( _rbexpr.rolling_min_by(by, window_size, min_periods, closed) ) end |
#rolling_quantile(quantile, interpolation: "nearest", window_size: 2, weights: nil, min_periods: nil, center: false) ⇒ 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.
5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 |
# File 'lib/polars/expr.rb', line 5602 def rolling_quantile( quantile, interpolation: "nearest", window_size: 2, weights: nil, min_periods: nil, center: false ) _from_rbexpr( _rbexpr.rolling_quantile( quantile, interpolation, window_size, weights, min_periods, center ) ) end |
#rolling_quantile_by(by, window_size, quantile:, interpolation: "nearest", min_periods: 1, closed: "right", warn_if_unsorted: nil) ⇒ Expr
If you want to compute multiple aggregation statistics over the same dynamic
window, consider using rolling
- this method can cache the window size
computation.
Compute a rolling quantile based on another column.
4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 |
# File 'lib/polars/expr.rb', line 4970 def rolling_quantile_by( by, window_size, quantile:, interpolation: "nearest", min_periods: 1, closed: "right", warn_if_unsorted: nil ) window_size = _prepare_rolling_by_window_args(window_size) by = Utils.parse_into_expression(by) _from_rbexpr( _rbexpr.rolling_quantile_by( by, quantile, interpolation, window_size, min_periods, closed, ) ) end |
#rolling_skew(window_size, bias: true) ⇒ Expr
Compute a rolling skew.
5705 5706 5707 |
# File 'lib/polars/expr.rb', line 5705 def rolling_skew(window_size, bias: true) _from_rbexpr(_rbexpr.rolling_skew(window_size, bias)) end |
#rolling_std(window_size, weights: nil, min_periods: nil, center: false, ddof: 1) ⇒ 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.
5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 |
# File 'lib/polars/expr.rb', line 5370 def rolling_std( window_size, weights: nil, min_periods: nil, center: false, ddof: 1 ) _from_rbexpr( _rbexpr.rolling_std( window_size, weights, min_periods, center, ddof ) ) end |
#rolling_std_by(by, window_size, min_periods: 1, closed: "right", ddof: 1, warn_if_unsorted: nil) ⇒ Expr
If you want to compute multiple aggregation statistics over the same dynamic
window, consider using rolling
- this method can cache the window size
computation.
Compute a rolling standard deviation based on another column.
4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 |
# File 'lib/polars/expr.rb', line 4611 def rolling_std_by( by, window_size, min_periods: 1, closed: "right", ddof: 1, warn_if_unsorted: nil ) window_size = _prepare_rolling_by_window_args(window_size) by = Utils.parse_into_expression(by) _from_rbexpr( _rbexpr.rolling_std_by( by, window_size, min_periods, closed, ddof ) ) end |
#rolling_sum(window_size, weights: nil, min_periods: nil, center: false) ⇒ 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.
5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 |
# File 'lib/polars/expr.rb', line 5292 def rolling_sum( window_size, weights: nil, min_periods: nil, center: false ) _from_rbexpr( _rbexpr.rolling_sum( window_size, weights, min_periods, center ) ) end |
#rolling_sum_by(by, window_size, min_periods: 1, closed: "right", warn_if_unsorted: nil) ⇒ Expr
If you want to compute multiple aggregation statistics over the same dynamic
window, consider using rolling
- this method can cache the window size
computation.
Apply a rolling sum based on another column.
4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 |
# File 'lib/polars/expr.rb', line 4480 def rolling_sum_by( by, window_size, min_periods: 1, closed: "right", warn_if_unsorted: nil ) window_size = _prepare_rolling_by_window_args(window_size) by = Utils.parse_into_expression(by) _from_rbexpr( _rbexpr.rolling_sum_by(by, window_size, min_periods, closed) ) end |
#rolling_var(window_size, weights: nil, min_periods: nil, center: false, ddof: 1) ⇒ 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.
5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 |
# File 'lib/polars/expr.rb', line 5449 def rolling_var( window_size, weights: nil, min_periods: nil, center: false, ddof: 1 ) _from_rbexpr( _rbexpr.rolling_var( window_size, weights, min_periods, center, ddof ) ) end |
#rolling_var_by(by, window_size, min_periods: 1, closed: "right", ddof: 1, warn_if_unsorted: nil) ⇒ Expr
If you want to compute multiple aggregation statistics over the same dynamic
window, consider using rolling
- this method can cache the window size
computation.
Compute a rolling variance based on another column.
4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 |
# File 'lib/polars/expr.rb', line 4749 def rolling_var_by( by, window_size, min_periods: 1, closed: "right", ddof: 1, warn_if_unsorted: nil ) window_size = _prepare_rolling_by_window_args(window_size) by = Utils.parse_into_expression(by) _from_rbexpr( _rbexpr.rolling_var_by( by, window_size, min_periods, closed, ddof ) ) end |
#round(decimals = 0) ⇒ Expr
Round underlying floating point data by decimals
digits.
1179 1180 1181 |
# File 'lib/polars/expr.rb', line 1179 def round(decimals = 0) _from_rbexpr(_rbexpr.round(decimals)) end |
#sample(frac: nil, with_replacement: true, shuffle: false, seed: nil, n: nil) ⇒ Expr
Sample from this expression.
6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 |
# File 'lib/polars/expr.rb', line 6476 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_into_expression(n) return _from_rbexpr(_rbexpr.sample_n(n, with_replacement, shuffle, seed)) end if frac.nil? frac = 1.0 end frac = Utils.parse_into_expression(frac) _from_rbexpr( _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.
1540 1541 1542 1543 |
# File 'lib/polars/expr.rb', line 1540 def search_sorted(element, side: "any") element = Utils.parse_into_expression(element, str_as_lit: false) _from_rbexpr(_rbexpr.search_sorted(element, 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.
6853 6854 6855 |
# File 'lib/polars/expr.rb', line 6853 def set_sorted(descending: false) _from_rbexpr(_rbexpr.set_sorted_flag(descending)) end |
#shift(n = 1, fill_value: nil) ⇒ Expr
Shift the values by a given period.
1701 1702 1703 1704 1705 1706 1707 |
# File 'lib/polars/expr.rb', line 1701 def shift(n = 1, fill_value: nil) if !fill_value.nil? fill_value = Utils.parse_into_expression(fill_value, str_as_lit: true) end n = Utils.parse_into_expression(n) _from_rbexpr(_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.
1733 1734 1735 |
# File 'lib/polars/expr.rb', line 1733 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.
6913 6914 6915 |
# File 'lib/polars/expr.rb', line 6913 def shrink_dtype _from_rbexpr(_rbexpr.shrink_dtype) end |
#shuffle(seed: nil) ⇒ Expr
Shuffle the contents of this expr.
6439 6440 6441 6442 6443 6444 |
# File 'lib/polars/expr.rb', line 6439 def shuffle(seed: nil) if seed.nil? seed = rand(10000) end _from_rbexpr(_rbexpr.shuffle(seed)) end |
#sign ⇒ Expr
Compute the element-wise indication of the sign.
6127 6128 6129 |
# File 'lib/polars/expr.rb', line 6127 def sign _from_rbexpr(_rbexpr.sign) end |
#sin ⇒ Expr
Compute the element-wise value for the sine.
6147 6148 6149 |
# File 'lib/polars/expr.rb', line 6147 def sin _from_rbexpr(_rbexpr.sin) end |
#sinh ⇒ Expr
Compute the element-wise value for the hyperbolic sine.
6267 6268 6269 |
# File 'lib/polars/expr.rb', line 6267 def sinh _from_rbexpr(_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.
5926 5927 5928 |
# File 'lib/polars/expr.rb', line 5926 def skew(bias: true) _from_rbexpr(_rbexpr.skew(bias)) end |
#slice(offset, length = nil) ⇒ Expr
Get a slice of this expression.
814 815 816 817 818 819 820 821 822 |
# File 'lib/polars/expr.rb', line 814 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 _from_rbexpr(_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.
1350 1351 1352 |
# File 'lib/polars/expr.rb', line 1350 def sort(reverse: false, nulls_last: false) _from_rbexpr(_rbexpr.sort_with(reverse, nulls_last)) end |
#sort_by(by, *more_by, reverse: false, nulls_last: false, multithreaded: true, maintain_order: 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.
1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 |
# File 'lib/polars/expr.rb', line 1587 def sort_by(by, *more_by, reverse: false, nulls_last: false, multithreaded: true, maintain_order: false) by = Utils.parse_into_list_of_expressions(by, *more_by) reverse = Utils.extend_bool(reverse, by.length, "reverse", "by") nulls_last = Utils.extend_bool(nulls_last, by.length, "nulls_last", "by") _from_rbexpr( _rbexpr.sort_by( by, reverse, nulls_last, multithreaded, maintain_order ) ) end |
#sqrt ⇒ Expr
Compute the square root of the elements.
245 246 247 |
# File 'lib/polars/expr.rb', line 245 def sqrt self**0.5 end |
#std(ddof: 1) ⇒ Expr
Get standard deviation.
1958 1959 1960 |
# File 'lib/polars/expr.rb', line 1958 def std(ddof: 1) _from_rbexpr(_rbexpr.std(ddof)) end |
#str ⇒ StringExpr
Create an object namespace of all string related methods.
7282 7283 7284 |
# File 'lib/polars/expr.rb', line 7282 def str StringExpr.new(self) end |
#struct ⇒ StructExpr
Create an object namespace of all struct related methods.
7289 7290 7291 |
# File 'lib/polars/expr.rb', line 7289 def struct StructExpr.new(self) end |
#sub(other) ⇒ Expr
Method equivalent of subtraction operator expr - other
.
3598 3599 3600 |
# File 'lib/polars/expr.rb', line 3598 def sub(other) self - other end |
#suffix(suffix) ⇒ Expr
Add a suffix to the root column name of the expression.
461 462 463 |
# File 'lib/polars/expr.rb', line 461 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.
2085 2086 2087 |
# File 'lib/polars/expr.rb', line 2085 def sum _from_rbexpr(_rbexpr.sum) end |
#tail(n = 10) ⇒ Expr
Get the last n
rows.
3132 3133 3134 |
# File 'lib/polars/expr.rb', line 3132 def tail(n = 10) _from_rbexpr(_rbexpr.tail(n)) end |
#tan ⇒ Expr
Compute the element-wise value for the tangent.
6187 6188 6189 |
# File 'lib/polars/expr.rb', line 6187 def tan _from_rbexpr(_rbexpr.tan) end |
#tanh ⇒ Expr
Compute the element-wise value for the hyperbolic tangent.
6307 6308 6309 |
# File 'lib/polars/expr.rb', line 6307 def tanh _from_rbexpr(_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.
178 179 180 |
# File 'lib/polars/expr.rb', line 178 def to_physical _from_rbexpr(_rbexpr.to_physical) end |
#to_s ⇒ String Also known as: inspect
Returns a string representing the Expr.
20 21 22 |
# File 'lib/polars/expr.rb', line 20 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.
1388 1389 1390 1391 |
# File 'lib/polars/expr.rb', line 1388 def top_k(k: 5) k = Utils.parse_into_expression(k) _from_rbexpr(_rbexpr.top_k(k)) end |
#truediv(other) ⇒ Expr
Method equivalent of float division operator expr / other
.
3653 3654 3655 |
# File 'lib/polars/expr.rb', line 3653 def truediv(other) self / other end |
#unique(maintain_order: false) ⇒ Expr
Get unique values of this expression.
2277 2278 2279 2280 2281 2282 2283 |
# File 'lib/polars/expr.rb', line 2277 def unique(maintain_order: false) if maintain_order _from_rbexpr(_rbexpr.unique_stable) else _from_rbexpr(_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
6711 6712 6713 |
# File 'lib/polars/expr.rb', line 6711 def unique_counts _from_rbexpr(_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.
6103 6104 6105 |
# File 'lib/polars/expr.rb', line 6103 def upper_bound _from_rbexpr(_rbexpr.upper_bound) end |
#value_counts(sort: false, parallel: false, name: nil, normalize: false) ⇒ Expr
Count all unique values and create a struct mapping value to count.
6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 |
# File 'lib/polars/expr.rb', line 6664 def value_counts( sort: false, parallel: false, name: nil, normalize: false ) if name.nil? if normalize name = "proportion" else name = "count" end end _from_rbexpr( _rbexpr.value_counts(sort, parallel, name, normalize) ) end |
#var(ddof: 1) ⇒ Expr
Get variance.
1981 1982 1983 |
# File 'lib/polars/expr.rb', line 1981 def var(ddof: 1) _from_rbexpr(_rbexpr.var(ddof)) end |
#where(predicate) ⇒ Expr
Filter a single column.
Alias for #filter.
2857 2858 2859 |
# File 'lib/polars/expr.rb', line 2857 def where(predicate) filter(predicate) end |
#xor(other) ⇒ Expr
Method equivalent of bitwise exclusive-or operator expr ^ other
.
3707 3708 3709 |
# File 'lib/polars/expr.rb', line 3707 def xor(other) self ^ other end |
#|(other) ⇒ Expr
Bitwise OR.
42 43 44 |
# File 'lib/polars/expr.rb', line 42 def |(other) _from_rbexpr(_rbexpr._or(_to_rbexpr(other))) end |