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
.
3807 3808 3809 3810 3811 3812 3813 |
# File 'lib/polars/expr.rb', line 3807 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.
5631 5632 5633 |
# File 'lib/polars/expr.rb', line 5631 def abs _from_rbexpr(_rbexpr.abs) end |
#add(other) ⇒ Expr
Method equivalent of addition operator expr + other
.
3396 3397 3398 |
# File 'lib/polars/expr.rb', line 3396 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.
701 702 703 |
# File 'lib/polars/expr.rb', line 701 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
.
813 814 815 816 |
# File 'lib/polars/expr.rb', line 813 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.
2118 2119 2120 |
# File 'lib/polars/expr.rb', line 2118 def approx_n_unique _from_rbexpr(_rbexpr.approx_n_unique) end |
#arccos ⇒ Expr
Compute the element-wise value for the inverse cosine.
6126 6127 6128 |
# File 'lib/polars/expr.rb', line 6126 def arccos _from_rbexpr(_rbexpr.arccos) end |
#arccosh ⇒ Expr
Compute the element-wise value for the inverse hyperbolic cosine.
6246 6247 6248 |
# File 'lib/polars/expr.rb', line 6246 def arccosh _from_rbexpr(_rbexpr.arccosh) end |
#arcsin ⇒ Expr
Compute the element-wise value for the inverse sine.
6106 6107 6108 |
# File 'lib/polars/expr.rb', line 6106 def arcsin _from_rbexpr(_rbexpr.arcsin) end |
#arcsinh ⇒ Expr
Compute the element-wise value for the inverse hyperbolic sine.
6226 6227 6228 |
# File 'lib/polars/expr.rb', line 6226 def arcsinh _from_rbexpr(_rbexpr.arcsinh) end |
#arctan ⇒ Expr
Compute the element-wise value for the inverse tangent.
6146 6147 6148 |
# File 'lib/polars/expr.rb', line 6146 def arctan _from_rbexpr(_rbexpr.arctan) end |
#arctanh ⇒ Expr
Compute the element-wise value for the inverse hyperbolic tangent.
6266 6267 6268 |
# File 'lib/polars/expr.rb', line 6266 def arctanh _from_rbexpr(_rbexpr.arctanh) end |
#arg_max ⇒ Expr
Get the index of the maximal value.
1443 1444 1445 |
# File 'lib/polars/expr.rb', line 1443 def arg_max _from_rbexpr(_rbexpr.arg_max) end |
#arg_min ⇒ Expr
Get the index of the minimal value.
1467 1468 1469 |
# File 'lib/polars/expr.rb', line 1467 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.
1419 1420 1421 |
# File 'lib/polars/expr.rb', line 1419 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.
2184 2185 2186 |
# File 'lib/polars/expr.rb', line 2184 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.
5664 5665 5666 |
# File 'lib/polars/expr.rb', line 5664 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.
7139 7140 7141 |
# File 'lib/polars/expr.rb', line 7139 def arr ArrayExpr.new(self) end |
#backward_fill(limit: nil) ⇒ Expr
Fill missing values with the next to be seen values.
1859 1860 1861 |
# File 'lib/polars/expr.rb', line 1859 def backward_fill(limit: nil) _from_rbexpr(_rbexpr.backward_fill(limit)) end |
#bin ⇒ BinaryExpr
Create an object namespace of all binary related methods.
7146 7147 7148 |
# File 'lib/polars/expr.rb', line 7146 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.
1387 1388 1389 1390 |
# File 'lib/polars/expr.rb', line 1387 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.
1234 1235 1236 1237 |
# File 'lib/polars/expr.rb', line 1234 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.
7153 7154 7155 |
# File 'lib/polars/expr.rb', line 7153 def cat CatExpr.new(self) end |
#ceil ⇒ Expr
Rounds up to the nearest integer value.
Only works on floating point Series.
1113 1114 1115 |
# File 'lib/polars/expr.rb', line 1113 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.
5888 5889 5890 5891 5892 5893 5894 5895 5896 |
# File 'lib/polars/expr.rb', line 5888 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.
5956 5957 5958 |
# File 'lib/polars/expr.rb', line 5956 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.
5925 5926 5927 |
# File 'lib/polars/expr.rb', line 5925 def clip_min(lower_bound) clip(lower_bound, nil) end |
#cos ⇒ Expr
Compute the element-wise value for the cosine.
6066 6067 6068 |
# File 'lib/polars/expr.rb', line 6066 def cos _from_rbexpr(_rbexpr.cos) end |
#cosh ⇒ Expr
Compute the element-wise value for the hyperbolic cosine.
6186 6187 6188 |
# File 'lib/polars/expr.rb', line 6186 def cosh _from_rbexpr(_rbexpr.cosh) end |
#count ⇒ Expr
Count the number of values in this expression.
721 722 723 |
# File 'lib/polars/expr.rb', line 721 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
1062 1063 1064 |
# File 'lib/polars/expr.rb', line 1062 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.
1028 1029 1030 |
# File 'lib/polars/expr.rb', line 1028 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.
996 997 998 |
# File 'lib/polars/expr.rb', line 996 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.
964 965 966 |
# File 'lib/polars/expr.rb', line 964 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.
928 929 930 |
# File 'lib/polars/expr.rb', line 928 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.
6721 6722 6723 6724 6725 |
# File 'lib/polars/expr.rb', line 6721 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.
2567 2568 2569 |
# File 'lib/polars/expr.rb', line 2567 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.
5759 5760 5761 |
# File 'lib/polars/expr.rb', line 5759 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.
1167 1168 1169 1170 |
# File 'lib/polars/expr.rb', line 1167 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.
893 894 895 |
# File 'lib/polars/expr.rb', line 893 def drop_nans _from_rbexpr(_rbexpr.drop_nans) end |
#drop_nulls ⇒ Expr
Drop null values.
866 867 868 |
# File 'lib/polars/expr.rb', line 866 def drop_nulls _from_rbexpr(_rbexpr.drop_nulls) end |
#dt ⇒ DateTimeExpr
Create an object namespace of all datetime related methods.
7160 7161 7162 |
# File 'lib/polars/expr.rb', line 7160 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.
6674 6675 6676 |
# File 'lib/polars/expr.rb', line 6674 def entropy(base: 2, normalize: true) _from_rbexpr(_rbexpr.entropy(base, normalize)) end |
#eq(other) ⇒ Expr
Method equivalent of equality operator expr == other
.
3106 3107 3108 |
# File 'lib/polars/expr.rb', line 3106 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.
3144 3145 3146 3147 |
# File 'lib/polars/expr.rb', line 3144 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.
6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 |
# File 'lib/polars/expr.rb', line 6418 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.
6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 |
# File 'lib/polars/expr.rb', line 6449 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.
6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 |
# File 'lib/polars/expr.rb', line 6481 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.
2989 2990 2991 |
# File 'lib/polars/expr.rb', line 2989 def explode _from_rbexpr(_rbexpr.explode) end |
#extend_constant(value, n) ⇒ Expr
Extend the Series with given number of values.
6521 6522 6523 |
# File 'lib/polars/expr.rb', line 6521 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.
1798 1799 1800 1801 |
# File 'lib/polars/expr.rb', line 1798 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.
1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 |
# File 'lib/polars/expr.rb', line 1758 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
.
2750 2751 2752 |
# File 'lib/polars/expr.rb', line 2750 def filter(predicate) _from_rbexpr(_rbexpr.filter(predicate._rbexpr)) end |
#first ⇒ Expr
Get the first value.
2232 2233 2234 |
# File 'lib/polars/expr.rb', line 2232 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.
2962 2963 2964 |
# File 'lib/polars/expr.rb', line 2962 def flatten _from_rbexpr(_rbexpr.explode) end |
#floor ⇒ Expr
Rounds down to the nearest integer value.
Only works on floating point Series.
1088 1089 1090 |
# File 'lib/polars/expr.rb', line 1088 def floor _from_rbexpr(_rbexpr.floor) end |
#floordiv(other) ⇒ Expr
Method equivalent of integer division operator expr // other
.
3426 3427 3428 |
# File 'lib/polars/expr.rb', line 3426 def floordiv(other) _from_rbexpr(_rbexpr.floordiv(_to_rbexpr(other))) end |
#forward_fill(limit: nil) ⇒ Expr
Fill missing values with the latest seen values.
1829 1830 1831 |
# File 'lib/polars/expr.rb', line 1829 def forward_fill(limit: nil) _from_rbexpr(_rbexpr.forward_fill(limit)) end |
#gather(indices) ⇒ Expr Also known as: take
Take values by index.
1590 1591 1592 1593 1594 1595 1596 1597 |
# File 'lib/polars/expr.rb', line 1590 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.
3011 3012 3013 |
# File 'lib/polars/expr.rb', line 3011 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
.
3178 3179 3180 |
# File 'lib/polars/expr.rb', line 3178 def ge(other) self >= other end |
#get(index) ⇒ Expr
Return a single value by index.
1632 1633 1634 1635 |
# File 'lib/polars/expr.rb', line 1632 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
.
3211 3212 3213 |
# File 'lib/polars/expr.rb', line 3211 def gt(other) self > other end |
#head(n = 10) ⇒ Expr
Get the first n
rows.
3037 3038 3039 |
# File 'lib/polars/expr.rb', line 3037 def head(n = 10) _from_rbexpr(_rbexpr.head(n)) end |
#implode ⇒ Expr
Aggregate to list.
6777 6778 6779 |
# File 'lib/polars/expr.rb', line 6777 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.
3908 3909 3910 |
# File 'lib/polars/expr.rb', line 3908 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.
3764 3765 3766 3767 3768 3769 3770 3771 |
# File 'lib/polars/expr.rb', line 3764 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.
2389 2390 2391 |
# File 'lib/polars/expr.rb', line 2389 def is_duplicated _from_rbexpr(_rbexpr.is_duplicated) end |
#is_finite ⇒ Expr
Returns a boolean Series indicating which values are finite.
574 575 576 |
# File 'lib/polars/expr.rb', line 574 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.
2366 2367 2368 |
# File 'lib/polars/expr.rb', line 2366 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.
3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 |
# File 'lib/polars/expr.rb', line 3649 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.
600 601 602 |
# File 'lib/polars/expr.rb', line 600 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.
633 634 635 |
# File 'lib/polars/expr.rb', line 633 def is_nan _from_rbexpr(_rbexpr.is_nan) end |
#is_not ⇒ Expr Also known as: not_
Negate a boolean expression.
489 490 491 |
# File 'lib/polars/expr.rb', line 489 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.
666 667 668 |
# File 'lib/polars/expr.rb', line 666 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.
548 549 550 |
# File 'lib/polars/expr.rb', line 548 def is_not_null _from_rbexpr(_rbexpr.is_not_null) end |
#is_null ⇒ Expr
Returns a boolean Series indicating which values are null.
519 520 521 |
# File 'lib/polars/expr.rb', line 519 def is_null _from_rbexpr(_rbexpr.is_null) end |
#is_unique ⇒ Expr
Get mask of unique values.
2338 2339 2340 |
# File 'lib/polars/expr.rb', line 2338 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
5857 5858 5859 |
# File 'lib/polars/expr.rb', line 5857 def kurtosis(fisher: true, bias: true) _from_rbexpr(_rbexpr.kurtosis(fisher, bias)) end |
#last ⇒ Expr
Get the last value.
2252 2253 2254 |
# File 'lib/polars/expr.rb', line 2252 def last _from_rbexpr(_rbexpr.last) end |
#le(other) ⇒ Expr
Method equivalent of "less than or equal" operator expr <= other
.
3244 3245 3246 |
# File 'lib/polars/expr.rb', line 3244 def le(other) self <= other end |
#len ⇒ Expr Also known as: length
Count the number of values in this expression.
741 742 743 |
# File 'lib/polars/expr.rb', line 741 def len _from_rbexpr(_rbexpr.len) end |
#limit(n = 10) ⇒ Expr
Get the first n
rows.
Alias for #head.
3074 3075 3076 |
# File 'lib/polars/expr.rb', line 3074 def limit(n = 10) head(n) end |
#list ⇒ ListExpr
Create an object namespace of all list related methods.
7132 7133 7134 |
# File 'lib/polars/expr.rb', line 7132 def list ListExpr.new(self) end |
#log(base = Math::E) ⇒ Expr
Compute the logarithm to a given base.
6635 6636 6637 |
# File 'lib/polars/expr.rb', line 6635 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.
5979 5980 5981 |
# File 'lib/polars/expr.rb', line 5979 def lower_bound _from_rbexpr(_rbexpr.lower_bound) end |
#lt(other) ⇒ Expr
Method equivalent of "less than" operator expr < other
.
3277 3278 3279 |
# File 'lib/polars/expr.rb', line 3277 def lt(other) self < other end |
#map_alias(&f) ⇒ Expr
Rename the output of an expression by mapping a function over the root name.
449 450 451 |
# File 'lib/polars/expr.rb', line 449 def map_alias(&f) name.map(&f) end |
#max ⇒ Expr
Get maximum value.
1932 1933 1934 |
# File 'lib/polars/expr.rb', line 1932 def max _from_rbexpr(_rbexpr.max) end |
#mean ⇒ Expr
Get mean value.
2036 2037 2038 |
# File 'lib/polars/expr.rb', line 2036 def mean _from_rbexpr(_rbexpr.mean) end |
#median ⇒ Expr
Get median value using linear interpolation.
2056 2057 2058 |
# File 'lib/polars/expr.rb', line 2056 def median _from_rbexpr(_rbexpr.median) end |
#meta ⇒ MetaExpr
Create an object namespace of all meta related expression methods.
7167 7168 7169 |
# File 'lib/polars/expr.rb', line 7167 def MetaExpr.new(self) end |
#min ⇒ Expr
Get minimum value.
1952 1953 1954 |
# File 'lib/polars/expr.rb', line 1952 def min _from_rbexpr(_rbexpr.min) end |
#mod(other) ⇒ Expr
Method equivalent of modulus operator expr % other
.
3453 3454 3455 |
# File 'lib/polars/expr.rb', line 3453 def mod(other) self % other end |
#mode ⇒ Expr
Compute the most occurring value(s).
Can return multiple Values.
1196 1197 1198 |
# File 'lib/polars/expr.rb', line 1196 def mode _from_rbexpr(_rbexpr.mode) end |
#mul(other) ⇒ Expr
Method equivalent of multiplication operator expr * other
.
3483 3484 3485 |
# File 'lib/polars/expr.rb', line 3483 def mul(other) self * other end |
#n_unique ⇒ Expr
Count unique values.
2096 2097 2098 |
# File 'lib/polars/expr.rb', line 2096 def n_unique _from_rbexpr(_rbexpr.n_unique) end |
#name ⇒ NameExpr
Create an object namespace of all expressions that modify expression names.
7174 7175 7176 |
# File 'lib/polars/expr.rb', line 7174 def name NameExpr.new(self) end |
#nan_max ⇒ Expr
Get maximum value, but propagate/poison encountered NaN values.
1972 1973 1974 |
# File 'lib/polars/expr.rb', line 1972 def nan_max _from_rbexpr(_rbexpr.nan_max) end |
#nan_min ⇒ Expr
Get minimum value, but propagate/poison encountered NaN values.
1992 1993 1994 |
# File 'lib/polars/expr.rb', line 1992 def nan_min _from_rbexpr(_rbexpr.nan_min) end |
#ne(other) ⇒ Expr
Method equivalent of inequality operator expr != other
.
3310 3311 3312 |
# File 'lib/polars/expr.rb', line 3310 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.
3348 3349 3350 3351 |
# File 'lib/polars/expr.rb', line 3348 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
.
3536 3537 3538 |
# File 'lib/polars/expr.rb', line 3536 def neg -self end |
#null_count ⇒ Expr
Count null values.
2144 2145 2146 |
# File 'lib/polars/expr.rb', line 2144 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.
2315 2316 2317 2318 |
# File 'lib/polars/expr.rb', line 2315 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.
5795 5796 5797 5798 |
# File 'lib/polars/expr.rb', line 5795 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.
2413 2414 2415 |
# File 'lib/polars/expr.rb', line 2413 def peak_max _from_rbexpr(_rbexpr.peak_max) end |
#peak_min ⇒ Expr
Get a boolean mask of the local minimum peaks.
2437 2438 2439 |
# File 'lib/polars/expr.rb', line 2437 def peak_min _from_rbexpr(_rbexpr.peak_min) end |
#pow(exponent) ⇒ Expr
Raise expression to the power of exponent.
3594 3595 3596 |
# File 'lib/polars/expr.rb', line 3594 def pow(exponent) self**exponent end |
#prefix(prefix) ⇒ Expr
Add a prefix to the root column name of the expression.
414 415 416 |
# File 'lib/polars/expr.rb', line 414 def prefix(prefix) name.prefix(prefix) end |
#product ⇒ Expr
Compute the product of an expression.
2076 2077 2078 |
# File 'lib/polars/expr.rb', line 2076 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.
2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 |
# File 'lib/polars/expr.rb', line 2648 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.
2510 2511 2512 2513 |
# File 'lib/polars/expr.rb', line 2510 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.
5728 5729 5730 |
# File 'lib/polars/expr.rb', line 5728 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.
839 840 841 |
# File 'lib/polars/expr.rb', line 839 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.
3845 3846 3847 |
# File 'lib/polars/expr.rb', line 3845 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
.
3693 3694 3695 3696 |
# File 'lib/polars/expr.rb', line 3693 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.
6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 |
# File 'lib/polars/expr.rb', line 6952 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.
7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 |
# File 'lib/polars/expr.rb', line 7108 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.
6312 6313 6314 |
# File 'lib/polars/expr.rb', line 6312 def reshape(dims) _from_rbexpr(_rbexpr.reshape(dims)) end |
#reverse ⇒ Expr
Reverse the selection.
1866 1867 1868 |
# File 'lib/polars/expr.rb', line 1866 def reverse _from_rbexpr(_rbexpr.reverse) end |
#rle ⇒ Expr
Get the lengths of runs of identical values.
2683 2684 2685 |
# File 'lib/polars/expr.rb', line 2683 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.
2711 2712 2713 |
# File 'lib/polars/expr.rb', line 2711 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.
5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 |
# File 'lib/polars/expr.rb', line 5051 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.
4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 |
# File 'lib/polars/expr.rb', line 4130 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.
5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 |
# File 'lib/polars/expr.rb', line 5129 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.
4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 |
# File 'lib/polars/expr.rb', line 4261 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.
5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 |
# File 'lib/polars/expr.rb', line 5439 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.
4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 |
# File 'lib/polars/expr.rb', line 4776 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.
4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 |
# File 'lib/polars/expr.rb', line 4973 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.
4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 |
# File 'lib/polars/expr.rb', line 4001 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.
5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 |
# File 'lib/polars/expr.rb', line 5517 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.
4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 |
# File 'lib/polars/expr.rb', line 4885 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.
5604 5605 5606 |
# File 'lib/polars/expr.rb', line 5604 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.
5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 |
# File 'lib/polars/expr.rb', line 5285 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.
4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 |
# File 'lib/polars/expr.rb', line 4526 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.
5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 |
# File 'lib/polars/expr.rb', line 5207 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.
4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 |
# File 'lib/polars/expr.rb', line 4395 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.
5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 |
# File 'lib/polars/expr.rb', line 5364 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.
4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 |
# File 'lib/polars/expr.rb', line 4664 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.
1139 1140 1141 |
# File 'lib/polars/expr.rb', line 1139 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.
6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 |
# File 'lib/polars/expr.rb', line 6375 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.
1500 1501 1502 1503 |
# File 'lib/polars/expr.rb', line 1500 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.
6752 6753 6754 |
# File 'lib/polars/expr.rb', line 6752 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.
1661 1662 1663 1664 1665 1666 1667 |
# File 'lib/polars/expr.rb', line 1661 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.
1693 1694 1695 |
# File 'lib/polars/expr.rb', line 1693 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.
6812 6813 6814 |
# File 'lib/polars/expr.rb', line 6812 def shrink_dtype _from_rbexpr(_rbexpr.shrink_dtype) end |
#shuffle(seed: nil) ⇒ Expr
Shuffle the contents of this expr.
6338 6339 6340 6341 6342 6343 |
# File 'lib/polars/expr.rb', line 6338 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.
6026 6027 6028 |
# File 'lib/polars/expr.rb', line 6026 def sign _from_rbexpr(_rbexpr.sign) end |
#sin ⇒ Expr
Compute the element-wise value for the sine.
6046 6047 6048 |
# File 'lib/polars/expr.rb', line 6046 def sin _from_rbexpr(_rbexpr.sin) end |
#sinh ⇒ Expr
Compute the element-wise value for the hyperbolic sine.
6166 6167 6168 |
# File 'lib/polars/expr.rb', line 6166 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.
5825 5826 5827 |
# File 'lib/polars/expr.rb', line 5825 def skew(bias: true) _from_rbexpr(_rbexpr.skew(bias)) end |
#slice(offset, length = nil) ⇒ Expr
Get a slice of this expression.
774 775 776 777 778 779 780 781 782 |
# File 'lib/polars/expr.rb', line 774 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.
1310 1311 1312 |
# File 'lib/polars/expr.rb', line 1310 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.
1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 |
# File 'lib/polars/expr.rb', line 1547 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.
1889 1890 1891 |
# File 'lib/polars/expr.rb', line 1889 def std(ddof: 1) _from_rbexpr(_rbexpr.std(ddof)) end |
#str ⇒ StringExpr
Create an object namespace of all string related methods.
7181 7182 7183 |
# File 'lib/polars/expr.rb', line 7181 def str StringExpr.new(self) end |
#struct ⇒ StructExpr
Create an object namespace of all struct related methods.
7188 7189 7190 |
# File 'lib/polars/expr.rb', line 7188 def struct StructExpr.new(self) end |
#sub(other) ⇒ Expr
Method equivalent of subtraction operator expr - other
.
3513 3514 3515 |
# File 'lib/polars/expr.rb', line 3513 def sub(other) self - other end |
#suffix(suffix) ⇒ Expr
Add a suffix to the root column name of the expression.
421 422 423 |
# File 'lib/polars/expr.rb', line 421 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.
2016 2017 2018 |
# File 'lib/polars/expr.rb', line 2016 def sum _from_rbexpr(_rbexpr.sum) end |
#tail(n = 10) ⇒ Expr
Get the last n
rows.
3062 3063 3064 |
# File 'lib/polars/expr.rb', line 3062 def tail(n = 10) _from_rbexpr(_rbexpr.tail(n)) end |
#tan ⇒ Expr
Compute the element-wise value for the tangent.
6086 6087 6088 |
# File 'lib/polars/expr.rb', line 6086 def tan _from_rbexpr(_rbexpr.tan) end |
#tanh ⇒ Expr
Compute the element-wise value for the hyperbolic tangent.
6206 6207 6208 |
# File 'lib/polars/expr.rb', line 6206 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.
1348 1349 1350 1351 |
# File 'lib/polars/expr.rb', line 1348 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
.
3568 3569 3570 |
# File 'lib/polars/expr.rb', line 3568 def truediv(other) self / other end |
#unique(maintain_order: false) ⇒ Expr
Get unique values of this expression.
2208 2209 2210 2211 2212 2213 2214 |
# File 'lib/polars/expr.rb', line 2208 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
6610 6611 6612 |
# File 'lib/polars/expr.rb', line 6610 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.
6002 6003 6004 |
# File 'lib/polars/expr.rb', line 6002 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.
6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 |
# File 'lib/polars/expr.rb', line 6563 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.
1912 1913 1914 |
# File 'lib/polars/expr.rb', line 1912 def var(ddof: 1) _from_rbexpr(_rbexpr.var(ddof)) end |
#where(predicate) ⇒ Expr
Filter a single column.
Alias for #filter.
2788 2789 2790 |
# File 'lib/polars/expr.rb', line 2788 def where(predicate) filter(predicate) end |
#xor(other) ⇒ Expr
Method equivalent of bitwise exclusive-or operator expr ^ other
.
3622 3623 3624 |
# File 'lib/polars/expr.rb', line 3622 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 |