Class: Polars::Expr
- Inherits:
-
Object
- Object
- Polars::Expr
- Defined in:
- lib/polars/expr.rb
Overview
Expressions that can be used in various contexts.
Direct Known Subclasses
Class Method Summary collapse
-
.deserialize(source) ⇒ Expr
Read a serialized expression from a file.
Instance Method Summary collapse
-
#! ⇒ Expr
(also: #~)
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.
-
#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(ignore_nulls: true) ⇒ Boolean
Check if all boolean values in a Boolean column are
true. -
#and_(*others) ⇒ Expr
Method equivalent of bitwise "and" operator
expr & other & .... -
#any(ignore_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
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(descending: false, nulls_last: false) ⇒ Expr
Get the index values that would sort this column.
-
#arg_true ⇒ Expr
Return indices where expression evaluates
true. -
#arg_unique ⇒ Expr
Get index of first unique value.
-
#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.
-
#bitwise_and ⇒ Expr
Perform an aggregation of bitwise ANDs.
-
#bitwise_count_ones ⇒ Expr
Evaluate the number of set bits.
-
#bitwise_count_zeros ⇒ Expr
Evaluate the number of unset bits.
-
#bitwise_leading_ones ⇒ Expr
Evaluate the number most-significant set bits before seeing an unset bit.
-
#bitwise_leading_zeros ⇒ Expr
Evaluate the number most-significant unset bits before seeing a set bit.
-
#bitwise_or ⇒ Expr
Perform an aggregation of bitwise ORs.
-
#bitwise_trailing_ones ⇒ Expr
Evaluate the number least-significant set bits before seeing an unset bit.
-
#bitwise_trailing_zeros ⇒ Expr
Evaluate the number least-significant unset bits before seeing a set bit.
-
#bitwise_xor ⇒ Expr
Perform an aggregation of bitwise XORs.
-
#bottom_k(k: 5) ⇒ Expr
Return the
ksmallest elements. -
#bottom_k_by(by, k: 5, reverse: false) ⇒ Expr
Return the elements corresponding to the
ksmallest elements of thebycolumn(s). -
#cast(dtype, strict: true, wrap_numerical: false) ⇒ Expr
Cast between data types.
-
#cat ⇒ CatExpr
Create an object namespace of all categorical related methods.
-
#cbrt ⇒ Expr
Compute the cube root of the elements.
-
#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.
-
#cos ⇒ Expr
Compute the element-wise value for the cosine.
-
#cosh ⇒ Expr
Compute the element-wise value for the hyperbolic cosine.
-
#cot ⇒ Expr
Compute the element-wise value for the cotangent.
-
#count ⇒ Expr
Count the number of values in this expression.
-
#cum_count(reverse: false) ⇒ Expr
Get an array with the cumulative count computed at every element.
-
#cum_max(reverse: false) ⇒ Expr
Get an array with the cumulative max computed at every element.
-
#cum_min(reverse: false) ⇒ Expr
Get an array with the cumulative min computed at every element.
-
#cum_prod(reverse: false) ⇒ Expr
Get an array with the cumulative product computed at every element.
-
#cum_sum(reverse: false) ⇒ Expr
Get an array with the cumulative sum computed at every element.
-
#cumulative_eval(expr, min_samples: 1) ⇒ Expr
Run an expression over a sliding window that increases
1slot every iteration. -
#cut(breaks, labels: nil, left_closed: false, include_breaks: false) ⇒ Expr
Bin continuous values into discrete categories.
-
#degrees ⇒ Expr
Convert from radians to degrees.
-
#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: Math::E, 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 == otherwherenil == nil. -
#ewm_mean(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, min_samples: 1, ignore_nulls: false) ⇒ Expr
Exponentially-weighted moving average.
-
#ewm_mean_by(by, half_life:) ⇒ Expr
Compute time-based exponentially weighted moving average.
-
#ewm_std(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_samples: 1, ignore_nulls: false) ⇒ Expr
Exponentially-weighted moving standard deviation.
-
#ewm_var(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_samples: 1, ignore_nulls: false) ⇒ Expr
Exponentially-weighted moving variance.
-
#exclude(columns, *more_columns) ⇒ Expr
Exclude certain columns from a wildcard/regex selection.
-
#exp ⇒ Expr
Compute the exponential, element-wise.
-
#explode(empty_as_null: OMITTED, keep_nulls: true) ⇒ Expr
Explode a list or utf8 Series.
-
#ext ⇒ ExtensionExpr
Create an object namespace of all extension type related expressions.
-
#extend_constant(value, n) ⇒ Expr
Extend the Series with given number of values.
-
#fill_nan(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(*predicates, **constraints) ⇒ Expr
Filter a single column.
-
#first(ignore_nulls: false) ⇒ Expr
Get the first value.
-
#flatten ⇒ Expr
deprecated
Deprecated.
Expr#flattenis deprecated and will be removed in a future version. UseExpr.list.explode(keep_nulls: false, empty_as_null: false)instead, which provides the behavior you likely expect. -
#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, null_on_oob: false) ⇒ Expr
Take values by index.
-
#gather_every(n, offset = 0) ⇒ Expr
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, null_on_oob: false) ⇒ Expr
Return a single value by index.
-
#gt(other) ⇒ Expr
Method equivalent of "greater than" operator
expr > other. -
#has_nulls ⇒ Expr
Check whether the expression contains one or more null values.
-
#hash_(seed = 0, seed_1 = nil, seed_2 = nil, seed_3 = nil) ⇒ Expr
Hash the elements in the selection.
-
#head(n = 10) ⇒ Expr
Get the first
nrows. -
#hist(bins: nil, bin_count: nil, include_category: false, include_breakpoint: false) ⇒ Expr
Bin values into buckets and count their occurrences.
-
#implode(maintain_order: true) ⇒ Expr
Aggregate to list.
-
#index_of(element) ⇒ Expr
Get the index of the first occurrence of a value, or
nilif it's not found. -
#inspect_(fmt = "%s") ⇒ Expr
Print the value that this expression evaluates to and pass on the value.
-
#interpolate(method: "linear") ⇒ Expr
Fill nulls with linear interpolation over missing values.
-
#interpolate_by(by) ⇒ Expr
Fill null values using interpolation based on another column.
-
#is_between(lower_bound, upper_bound, closed: "both") ⇒ Expr
Check if this expression is between start and end.
-
#is_close(other, abs_tol: 0.0, rel_tol: 1.0e-09, nans_equal: false) ⇒ Expr
Check if this expression is close, i.e.
-
#is_duplicated ⇒ Expr
Get mask of duplicated values.
-
#is_empty(ignore_nulls: false) ⇒ Expr
Return whether the column is empty.
-
#is_finite ⇒ Expr
Returns a boolean Series indicating which values are finite.
-
#is_first_distinct ⇒ Expr
Get a mask of the first unique value.
-
#is_in(other, nulls_equal: false) ⇒ 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_last_distinct ⇒ Expr
Return a boolean mask indicating the last occurrence of each distinct value.
-
#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_sorted(descending: false, nulls_last: false) ⇒ Expr
Checks if an expression is sorted.
-
#is_unique ⇒ Expr
Get mask of unique values.
-
#item(allow_empty: false) ⇒ Expr
Get the single value.
-
#kurtosis(fisher: true, bias: true) ⇒ Expr
Compute the kurtosis (Fisher or Pearson) of a dataset.
-
#last(ignore_nulls: false) ⇒ 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
nrows. -
#list ⇒ ListExpr
Create an object namespace of all list related methods.
-
#log(base = Math::E) ⇒ Expr
Compute the logarithm to a given base.
-
#log10 ⇒ Expr
Compute the base 10 logarithm of the input array, element-wise.
-
#log1p ⇒ Expr
Compute the natural logarithm of each element plus one.
-
#lower_bound ⇒ Expr
Calculate the lower bound.
-
#lt(other) ⇒ Expr
Method equivalent of "less than" operator
expr < other. -
#map_batches(return_dtype: nil, is_elementwise: false, returns_scalar: false, &function) ⇒ Expr
Apply a custom Ruby function to a Series or array of Series.
-
#map_elements(return_dtype: nil, skip_nulls: true, pass_name: false, strategy: "thread_local", returns_scalar: false, &function) ⇒ Expr
Apply a custom/user-defined function (UDF) in a GroupBy or Projection context.
-
#max ⇒ Expr
Get maximum value.
-
#max_by(by) ⇒ Expr
Get maximum value, ordered by another expression.
-
#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.
-
#min_by(by) ⇒ Expr
Get minimum value, ordered by another expression.
-
#mod(other) ⇒ Expr
Method equivalent of modulus operator
expr % other. -
#mode(maintain_order: false) ⇒ 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 != otherwherenil == nil. -
#neg ⇒ Expr
Method equivalent of unary minus operator
-expr. -
#null_count ⇒ Expr
Count null values.
-
#or_(*others) ⇒ Expr
Method equivalent of bitwise "or" operator
expr | other | .... -
#over(partition_by = nil, *more_exprs, order_by: nil, descending: false, nulls_last: false, mapping_strategy: "group_to_rows") ⇒ 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.
-
#pipe(function, *args, **kwargs) ⇒ Object
Offers a structured way to apply a sequence of user-defined functions (UDFs).
-
#pow(exponent) ⇒ Expr
Raise expression to the power of exponent.
-
#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.
-
#radians ⇒ Expr
Convert from degrees to radians.
-
#rank(method: "average", descending: 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: nil, dtype: nil) ⇒ Expr
Reinterpret the underlying bits as a signed/unsigned integer or float.
-
#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(dimensions) ⇒ 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(index_column:, period:, offset: nil, closed: "right") ⇒ Expr
Create rolling groups based on a temporal or integer column.
-
#rolling_kurtosis(window_size, fisher: true, bias: true, min_samples: nil, center: false) ⇒ Expr
Compute a rolling kurtosis.
-
#rolling_map(window_size, weights: nil, min_samples: nil, center: false, &function) ⇒ Expr
Compute a custom rolling window function.
-
#rolling_max(window_size, weights: nil, min_samples: nil, center: false) ⇒ Expr
Apply a rolling max (moving max) over the values in this array.
-
#rolling_max_by(by, window_size, min_samples: 1, closed: "right") ⇒ Expr
Apply a rolling max based on another column.
-
#rolling_mean(window_size, weights: nil, min_samples: nil, center: false) ⇒ Expr
Apply a rolling mean (moving mean) over the values in this array.
-
#rolling_mean_by(by, window_size, min_samples: 1, closed: "right") ⇒ Expr
Apply a rolling mean based on another column.
-
#rolling_median(window_size, weights: nil, min_samples: nil, center: false) ⇒ Expr
Compute a rolling median.
-
#rolling_median_by(by, window_size, min_samples: 1, closed: "right") ⇒ Expr
Compute a rolling median based on another column.
-
#rolling_min(window_size, weights: nil, min_samples: nil, center: false) ⇒ Expr
Apply a rolling min (moving min) over the values in this array.
-
#rolling_min_by(by, window_size, min_samples: 1, closed: "right") ⇒ Expr
Apply a rolling min based on another column.
-
#rolling_quantile(quantile, interpolation: "nearest", window_size: 2, weights: nil, min_samples: nil, center: false) ⇒ Expr
Compute a rolling quantile.
-
#rolling_quantile_by(by, window_size, quantile:, interpolation: "nearest", min_samples: 1, closed: "right") ⇒ Expr
Compute a rolling quantile based on another column.
-
#rolling_rank(window_size, method: "average", seed: nil, min_samples: nil, center: false) ⇒ Expr
Compute a rolling rank.
-
#rolling_rank_by(by, window_size, method: "average", seed: nil, min_samples: 1, closed: "right") ⇒ Expr
Compute a rolling rank based on another column.
-
#rolling_skew(window_size, bias: true, min_samples: nil, center: false) ⇒ Expr
Compute a rolling skew.
-
#rolling_std(window_size, weights: nil, min_samples: nil, center: false, ddof: 1) ⇒ Expr
Compute a rolling standard deviation.
-
#rolling_std_by(by, window_size, min_samples: 1, closed: "right", ddof: 1) ⇒ Expr
Compute a rolling standard deviation based on another column.
-
#rolling_sum(window_size, weights: nil, min_samples: nil, center: false) ⇒ Expr
Apply a rolling sum (moving sum) over the values in this array.
-
#rolling_sum_by(by, window_size, min_samples: 0, closed: "right") ⇒ Expr
Apply a rolling sum based on another column.
-
#rolling_var(window_size, weights: nil, min_samples: nil, center: false, ddof: 1) ⇒ Expr
Compute a rolling variance.
-
#rolling_var_by(by, window_size, min_samples: 1, closed: "right", ddof: 1) ⇒ Expr
Compute a rolling variance based on another column.
-
#round(decimals = 0, mode: "half_to_even") ⇒ Expr
Round underlying floating point data by
decimalsdigits. -
#round_sig_figs(digits) ⇒ Expr
Round to a number of significant figures.
-
#sample(fraction: nil, with_replacement: false, shuffle: false, seed: nil, n: nil) ⇒ Expr
Sample from this expression.
-
#search_sorted(element, side: "any", descending: false) ⇒ Expr
Find indices where elements should be inserted to maintain order.
-
#set_sorted(descending: false, nulls_last: false) ⇒ Expr
Flags the expression as 'sorted'.
-
#shift(n = 1, fill_value: nil) ⇒ Expr
Shift the values by a given period.
-
#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(descending: false, nulls_last: false) ⇒ Expr
Sort this column.
-
#sort_by(by, *more_by, descending: 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. -
#sum ⇒ Expr
Get sum value.
-
#tail(n = 10) ⇒ Expr
Get the last
nrows. -
#tan ⇒ Expr
Compute the element-wise value for the tangent.
-
#tanh ⇒ Expr
Compute the element-wise value for the hyperbolic tangent.
-
#to_physical ⇒ Expr
Cast to physical representation of the logical dtype.
-
#to_s ⇒ String
(also: #inspect)
Returns a string representing the Expr.
-
#top_k(k: 5) ⇒ Expr
Return the
klargest elements. -
#top_k_by(by, k: 5, reverse: false) ⇒ Expr
Return the elements corresponding to the
klargest elements of thebycolumn(s). -
#truediv(other) ⇒ Expr
Method equivalent of float division operator
expr / other. -
#truncate(decimals = 0) ⇒ Expr
Truncate numeric data toward zero to
decimalsnumber of decimal places. -
#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.
-
#xor(other) ⇒ Expr
Method equivalent of bitwise exclusive-or operator
expr ^ other. -
#|(other) ⇒ Expr
Bitwise OR.
Class Method Details
.deserialize(source) ⇒ Expr
This function uses marshaling if the logical plan contains Ruby UDFs, and as such inherits the security implications. Deserializing can execute arbitrary code, so it should only be attempted on trusted data.
Serialization is not stable across Polars versions: a LazyFrame serialized in one Polars version may not be deserializable in another Polars version.
Read a serialized expression from a file.
168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/polars/expr.rb', line 168 def self.deserialize(source) raise Todo unless RbExpr.respond_to?(:deserialize_binary) if Utils.pathlike?(source) source = Utils.normalize_filepath(source) end deserializer = RbExpr.method(:deserialize_binary) _from_rbexpr(deserializer.(source)) end |
Instance Method Details
#! ⇒ Expr Also known as: ~
Performs boolean not.
134 135 136 |
# File 'lib/polars/expr.rb', line 134 def ! is_not end |
#!=(other) ⇒ Expr
Not equal.
113 114 115 |
# File 'lib/polars/expr.rb', line 113 def !=(other) wrap_expr(_rbexpr.neq(_to_expr(other)._rbexpr)) end |
#%(other) ⇒ Expr
Returns the modulo.
77 78 79 |
# File 'lib/polars/expr.rb', line 77 def %(other) wrap_expr(_rbexpr % _to_rbexpr(other)) end |
#&(other) ⇒ Expr
Bitwise AND.
33 34 35 36 |
# File 'lib/polars/expr.rb', line 33 def &(other) other = Utils.parse_into_expression(other) wrap_expr(_rbexpr.and_(other)) end |
#*(other) ⇒ Expr
Performs multiplication.
63 64 65 |
# File 'lib/polars/expr.rb', line 63 def *(other) wrap_expr(_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) wrap_expr(_rbexpr.pow(exponent)) end |
#+(other) ⇒ Expr
Performs addition.
49 50 51 |
# File 'lib/polars/expr.rb', line 49 def +(other) wrap_expr(_rbexpr + _to_rbexpr(other)) end |
#-(other) ⇒ Expr
Performs subtraction.
56 57 58 |
# File 'lib/polars/expr.rb', line 56 def -(other) wrap_expr(_rbexpr - _to_rbexpr(other)) end |
#-@ ⇒ Expr
Performs negation.
142 143 144 |
# File 'lib/polars/expr.rb', line 142 def -@ wrap_expr(_rbexpr.neg) end |
#/(other) ⇒ Expr
Performs division.
70 71 72 |
# File 'lib/polars/expr.rb', line 70 def /(other) wrap_expr(_rbexpr / _to_rbexpr(other)) end |
#<(other) ⇒ Expr
Less than.
120 121 122 |
# File 'lib/polars/expr.rb', line 120 def <(other) wrap_expr(_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) wrap_expr(_rbexpr.lt_eq(_to_expr(other)._rbexpr)) end |
#==(other) ⇒ Expr
Equal.
106 107 108 |
# File 'lib/polars/expr.rb', line 106 def ==(other) wrap_expr(_rbexpr.eq(_to_expr(other)._rbexpr)) end |
#>(other) ⇒ Expr
Greater than.
127 128 129 |
# File 'lib/polars/expr.rb', line 127 def >(other) wrap_expr(_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) wrap_expr(_rbexpr.gt_eq(_to_expr(other)._rbexpr)) end |
#^(other) ⇒ Expr
Bitwise XOR.
25 26 27 28 |
# File 'lib/polars/expr.rb', line 25 def ^(other) other = Utils.parse_into_expression(other) wrap_expr(_rbexpr.xor_(other)) end |
#abs ⇒ Expr
Compute absolute values.
6789 6790 6791 |
# File 'lib/polars/expr.rb', line 6789 def abs wrap_expr(_rbexpr.abs) end |
#add(other) ⇒ Expr
Method equivalent of addition operator expr + other.
4207 4208 4209 |
# File 'lib/polars/expr.rb', line 4207 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.
770 771 772 |
# File 'lib/polars/expr.rb', line 770 def agg_groups wrap_expr(_rbexpr.agg_groups) end |
#alias(name) ⇒ Expr
Rename the output of an expression.
432 433 434 |
# File 'lib/polars/expr.rb', line 432 def alias(name) wrap_expr(_rbexpr.alias(name)) end |
#all(ignore_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.
251 252 253 |
# File 'lib/polars/expr.rb', line 251 def all(ignore_nulls: true) wrap_expr(_rbexpr.all(ignore_nulls)) end |
#and_(*others) ⇒ Expr
Method equivalent of bitwise "and" operator expr & other & ....
3844 3845 3846 |
# File 'lib/polars/expr.rb', line 3844 def and_(*others) ([self] + others).reduce(:&) end |
#any(ignore_nulls: true) ⇒ Boolean
Check if any boolean value in a Boolean column is true.
226 227 228 |
# File 'lib/polars/expr.rb', line 226 def any(ignore_nulls: true) wrap_expr(_rbexpr.any(ignore_nulls)) end |
#append(other, upcast: true) ⇒ Expr
Append expressions.
This is done by adding the chunks of other to this Series.
882 883 884 885 |
# File 'lib/polars/expr.rb', line 882 def append(other, upcast: true) other = Utils.parse_into_expression(other) wrap_expr(_rbexpr.append(other, upcast)) end |
#approx_n_unique ⇒ Expr
Approx count unique values.
This is done using the HyperLogLog++ algorithm for cardinality estimation.
2595 2596 2597 |
# File 'lib/polars/expr.rb', line 2595 def approx_n_unique wrap_expr(_rbexpr.approx_n_unique) end |
#arccos ⇒ Expr
Compute the element-wise value for the inverse cosine.
7210 7211 7212 |
# File 'lib/polars/expr.rb', line 7210 def arccos wrap_expr(_rbexpr.arccos) end |
#arccosh ⇒ Expr
Compute the element-wise value for the inverse hyperbolic cosine.
7330 7331 7332 |
# File 'lib/polars/expr.rb', line 7330 def arccosh wrap_expr(_rbexpr.arccosh) end |
#arcsin ⇒ Expr
Compute the element-wise value for the inverse sine.
7190 7191 7192 |
# File 'lib/polars/expr.rb', line 7190 def arcsin wrap_expr(_rbexpr.arcsin) end |
#arcsinh ⇒ Expr
Compute the element-wise value for the inverse hyperbolic sine.
7310 7311 7312 |
# File 'lib/polars/expr.rb', line 7310 def arcsinh wrap_expr(_rbexpr.arcsinh) end |
#arctan ⇒ Expr
Compute the element-wise value for the inverse tangent.
7230 7231 7232 |
# File 'lib/polars/expr.rb', line 7230 def arctan wrap_expr(_rbexpr.arctan) end |
#arctanh ⇒ Expr
Compute the element-wise value for the inverse hyperbolic tangent.
7350 7351 7352 |
# File 'lib/polars/expr.rb', line 7350 def arctanh wrap_expr(_rbexpr.arctanh) end |
#arg_max ⇒ Expr
Get the index of the maximal value.
1800 1801 1802 |
# File 'lib/polars/expr.rb', line 1800 def arg_max wrap_expr(_rbexpr.arg_max) end |
#arg_min ⇒ Expr
Get the index of the minimal value.
1824 1825 1826 |
# File 'lib/polars/expr.rb', line 1824 def arg_min wrap_expr(_rbexpr.arg_min) end |
#arg_sort(descending: false, nulls_last: false) ⇒ Expr
Get the index values that would sort this column.
1776 1777 1778 |
# File 'lib/polars/expr.rb', line 1776 def arg_sort(descending: false, nulls_last: false) wrap_expr(_rbexpr.arg_sort(descending, nulls_last)) end |
#arg_true ⇒ Expr
Modifies number of rows returned, so will fail in combination with other
expressions. Use as only expression in select / with_columns.
Return indices where expression evaluates true.
309 310 311 |
# File 'lib/polars/expr.rb', line 309 def arg_true wrap_expr(Plr.arg_where(_rbexpr)) end |
#arg_unique ⇒ Expr
Get index of first unique value.
2686 2687 2688 |
# File 'lib/polars/expr.rb', line 2686 def arg_unique wrap_expr(_rbexpr.arg_unique) end |
#arr ⇒ ArrayExpr
Create an object namespace of all array related methods.
8558 8559 8560 |
# File 'lib/polars/expr.rb', line 8558 def arr ArrayExpr.new(self) end |
#backward_fill(limit: nil) ⇒ Expr
Fill missing values with the next to be seen values.
2243 2244 2245 |
# File 'lib/polars/expr.rb', line 2243 def backward_fill(limit: nil) fill_null(strategy: "backward", limit: limit) end |
#bin ⇒ BinaryExpr
Create an object namespace of all binary related methods.
8565 8566 8567 |
# File 'lib/polars/expr.rb', line 8565 def bin BinaryExpr.new(self) end |
#bitwise_and ⇒ Expr
Perform an aggregation of bitwise ANDs.
8472 8473 8474 |
# File 'lib/polars/expr.rb', line 8472 def bitwise_and wrap_expr(_rbexpr.bitwise_and) end |
#bitwise_count_ones ⇒ Expr
Evaluate the number of set bits.
8401 8402 8403 |
# File 'lib/polars/expr.rb', line 8401 def bitwise_count_ones wrap_expr(_rbexpr.bitwise_count_ones) end |
#bitwise_count_zeros ⇒ Expr
Evaluate the number of unset bits.
8408 8409 8410 |
# File 'lib/polars/expr.rb', line 8408 def bitwise_count_zeros wrap_expr(_rbexpr.bitwise_count_zeros) end |
#bitwise_leading_ones ⇒ Expr
Evaluate the number most-significant set bits before seeing an unset bit.
8415 8416 8417 |
# File 'lib/polars/expr.rb', line 8415 def bitwise_leading_ones wrap_expr(_rbexpr.bitwise_leading_ones) end |
#bitwise_leading_zeros ⇒ Expr
Evaluate the number most-significant unset bits before seeing a set bit.
8422 8423 8424 |
# File 'lib/polars/expr.rb', line 8422 def bitwise_leading_zeros wrap_expr(_rbexpr.bitwise_leading_zeros) end |
#bitwise_or ⇒ Expr
Perform an aggregation of bitwise ORs.
8508 8509 8510 |
# File 'lib/polars/expr.rb', line 8508 def bitwise_or wrap_expr(_rbexpr.bitwise_or) end |
#bitwise_trailing_ones ⇒ Expr
Evaluate the number least-significant set bits before seeing an unset bit.
8429 8430 8431 |
# File 'lib/polars/expr.rb', line 8429 def bitwise_trailing_ones wrap_expr(_rbexpr.bitwise_trailing_ones) end |
#bitwise_trailing_zeros ⇒ Expr
Evaluate the number least-significant unset bits before seeing a set bit.
8436 8437 8438 |
# File 'lib/polars/expr.rb', line 8436 def bitwise_trailing_zeros wrap_expr(_rbexpr.bitwise_trailing_zeros) end |
#bitwise_xor ⇒ Expr
Perform an aggregation of bitwise XORs.
8544 8545 8546 |
# File 'lib/polars/expr.rb', line 8544 def bitwise_xor wrap_expr(_rbexpr.bitwise_xor) end |
#bottom_k(k: 5) ⇒ Expr
Return the k smallest elements.
If 'reverse: true` the smallest elements will be given.
1638 1639 1640 1641 |
# File 'lib/polars/expr.rb', line 1638 def bottom_k(k: 5) k = Utils.parse_into_expression(k) wrap_expr(_rbexpr.bottom_k(k)) end |
#bottom_k_by(by, k: 5, reverse: false) ⇒ Expr
Return the elements corresponding to the k smallest elements of the by column(s).
Non-null elements are always preferred over null elements, regardless of
the value of reverse. The output is not guaranteed to be in any
particular order, call :func:sort after this function if you wish the
output to be sorted.
1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 |
# File 'lib/polars/expr.rb', line 1738 def bottom_k_by( by, k: 5, reverse: false ) k = Utils.parse_into_expression(k) by = Utils.parse_into_list_of_expressions(by) reverse = Utils.extend_bool(reverse, by.length, "reverse", "by") wrap_expr(_rbexpr.bottom_k_by(by, k, reverse)) end |
#cast(dtype, strict: true, wrap_numerical: false) ⇒ Expr
Cast between data types.
1379 1380 1381 1382 |
# File 'lib/polars/expr.rb', line 1379 def cast(dtype, strict: true, wrap_numerical: false) dtype = Utils.parse_into_datatype_expr(dtype) wrap_expr(_rbexpr.cast(dtype._rbdatatype_expr, strict, wrap_numerical)) end |
#cat ⇒ CatExpr
Create an object namespace of all categorical related methods.
8572 8573 8574 |
# File 'lib/polars/expr.rb', line 8572 def cat CatExpr.new(self) end |
#cbrt ⇒ Expr
Compute the cube root of the elements.
353 354 355 |
# File 'lib/polars/expr.rb', line 353 def cbrt wrap_expr(_rbexpr.cbrt) end |
#ceil ⇒ Expr
Rounds up to the nearest integer value.
Only works on floating point Series.
1177 1178 1179 |
# File 'lib/polars/expr.rb', line 1177 def ceil wrap_expr(_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.
7014 7015 7016 7017 7018 7019 7020 7021 7022 |
# File 'lib/polars/expr.rb', line 7014 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 wrap_expr(_rbexpr.clip(lower_bound, upper_bound)) end |
#cos ⇒ Expr
Compute the element-wise value for the cosine.
7130 7131 7132 |
# File 'lib/polars/expr.rb', line 7130 def cos wrap_expr(_rbexpr.cos) end |
#cosh ⇒ Expr
Compute the element-wise value for the hyperbolic cosine.
7270 7271 7272 |
# File 'lib/polars/expr.rb', line 7270 def cosh wrap_expr(_rbexpr.cosh) end |
#cot ⇒ Expr
Compute the element-wise value for the cotangent.
7170 7171 7172 |
# File 'lib/polars/expr.rb', line 7170 def cot wrap_expr(_rbexpr.cot) end |
#count ⇒ Expr
Count the number of values in this expression.
790 791 792 |
# File 'lib/polars/expr.rb', line 790 def count wrap_expr(_rbexpr.count) end |
#cum_count(reverse: false) ⇒ Expr
Get an array with the cumulative count computed at every element.
Counting from 0 to len
1127 1128 1129 |
# File 'lib/polars/expr.rb', line 1127 def cum_count(reverse: false) wrap_expr(_rbexpr.cum_count(reverse)) end |
#cum_max(reverse: false) ⇒ Expr
Get an array with the cumulative max computed at every element.
1094 1095 1096 |
# File 'lib/polars/expr.rb', line 1094 def cum_max(reverse: false) wrap_expr(_rbexpr.cum_max(reverse)) end |
#cum_min(reverse: false) ⇒ Expr
Get an array with the cumulative min computed at every element.
1063 1064 1065 |
# File 'lib/polars/expr.rb', line 1063 def cum_min(reverse: false) wrap_expr(_rbexpr.cum_min(reverse)) end |
#cum_prod(reverse: false) ⇒ Expr
Dtypes in \{Int8, UInt8, Int16, UInt16} are cast to Int64 before summing to prevent overflow issues.
Get an array with the cumulative product computed at every element.
1032 1033 1034 |
# File 'lib/polars/expr.rb', line 1032 def cum_prod(reverse: false) wrap_expr(_rbexpr.cum_prod(reverse)) end |
#cum_sum(reverse: false) ⇒ Expr
Dtypes in \{Int8, UInt8, Int16, UInt16} are cast to Int64 before summing to prevent overflow issues.
Get an array with the cumulative sum computed at every element.
997 998 999 |
# File 'lib/polars/expr.rb', line 997 def cum_sum(reverse: false) wrap_expr(_rbexpr.cum_sum(reverse)) end |
#cumulative_eval(expr, min_samples: 1) ⇒ 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.
7954 7955 7956 7957 7958 |
# File 'lib/polars/expr.rb', line 7954 def cumulative_eval(expr, min_samples: 1) wrap_expr( _rbexpr.cumulative_eval(expr._rbexpr, min_samples) ) end |
#cut(breaks, labels: nil, left_closed: false, include_breaks: false) ⇒ Expr
Bin continuous values into discrete categories.
3307 3308 3309 |
# File 'lib/polars/expr.rb', line 3307 def cut(breaks, labels: nil, left_closed: false, include_breaks: false) wrap_expr(_rbexpr.cut(breaks, labels, left_closed, include_breaks)) end |
#degrees ⇒ Expr
Convert from radians to degrees.
7378 7379 7380 |
# File 'lib/polars/expr.rb', line 7378 def degrees wrap_expr(_rbexpr.degrees) end |
#diff(n: 1, null_behavior: "ignore") ⇒ Expr
Calculate the n-th discrete difference.
6884 6885 6886 6887 |
# File 'lib/polars/expr.rb', line 6884 def diff(n: 1, null_behavior: "ignore") n = Utils.parse_into_expression(n) wrap_expr(_rbexpr.diff(n, null_behavior)) end |
#dot(other) ⇒ Expr
Compute the dot/inner product between two Expressions.
1306 1307 1308 1309 |
# File 'lib/polars/expr.rb', line 1306 def dot(other) other = Utils.parse_into_expression(other, str_as_lit: false) wrap_expr(_rbexpr.dot(other)) end |
#drop_nans ⇒ Expr
Drop floating point NaN values.
962 963 964 |
# File 'lib/polars/expr.rb', line 962 def drop_nans wrap_expr(_rbexpr.drop_nans) end |
#drop_nulls ⇒ Expr
Drop null values.
935 936 937 |
# File 'lib/polars/expr.rb', line 935 def drop_nulls wrap_expr(_rbexpr.drop_nulls) end |
#dt ⇒ DateTimeExpr
Create an object namespace of all datetime related methods.
8579 8580 8581 |
# File 'lib/polars/expr.rb', line 8579 def dt DateTimeExpr.new(self) end |
#entropy(base: Math::E, normalize: true) ⇒ Expr
Computes the entropy.
Uses the formula -sum(pk * log(pk) where pk are discrete probabilities.
7910 7911 7912 |
# File 'lib/polars/expr.rb', line 7910 def entropy(base: Math::E, normalize: true) wrap_expr(_rbexpr.entropy(base, normalize)) end |
#eq(other) ⇒ Expr
Method equivalent of equality operator expr == other.
3917 3918 3919 |
# File 'lib/polars/expr.rb', line 3917 def eq(other) self == other end |
#eq_missing(other) ⇒ Expr
Method equivalent of equality operator expr == other where nil == nil.
This differs from default eq where null values are propagated.
3955 3956 3957 3958 |
# File 'lib/polars/expr.rb', line 3955 def eq_missing(other) other = Utils.parse_into_expression(other, str_as_lit: true) wrap_expr(_rbexpr.eq_missing(other)) end |
#ewm_mean(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, min_samples: 1, ignore_nulls: false) ⇒ Expr
Exponentially-weighted moving average.
7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 |
# File 'lib/polars/expr.rb', line 7558 def ewm_mean( com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, min_samples: 1, ignore_nulls: false ) alpha = _prepare_alpha(com, span, half_life, alpha) wrap_expr(_rbexpr.ewm_mean(alpha, adjust, min_samples, ignore_nulls)) end |
#ewm_mean_by(by, half_life:) ⇒ Expr
Compute time-based exponentially weighted moving average.
7631 7632 7633 7634 7635 7636 7637 7638 |
# File 'lib/polars/expr.rb', line 7631 def ewm_mean_by( by, half_life: ) by = Utils.parse_into_expression(by) half_life = Utils.parse_as_duration_string(half_life) wrap_expr(_rbexpr.ewm_mean_by(by, half_life)) end |
#ewm_std(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_samples: 1, ignore_nulls: false) ⇒ Expr
Exponentially-weighted moving standard deviation.
7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 |
# File 'lib/polars/expr.rb', line 7658 def ewm_std( com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_samples: 1, ignore_nulls: false ) alpha = _prepare_alpha(com, span, half_life, alpha) wrap_expr(_rbexpr.ewm_std(alpha, adjust, bias, min_samples, ignore_nulls)) end |
#ewm_var(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_samples: 1, ignore_nulls: false) ⇒ Expr
Exponentially-weighted moving variance.
7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 |
# File 'lib/polars/expr.rb', line 7690 def ewm_var( com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_samples: 1, ignore_nulls: false ) alpha = _prepare_alpha(com, span, half_life, alpha) wrap_expr(_rbexpr.ewm_var(alpha, adjust, bias, min_samples, ignore_nulls)) end |
#exclude(columns, *more_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 $.
470 471 472 |
# File 'lib/polars/expr.rb', line 470 def exclude(columns, *more_columns) .as_selector.exclude(columns, *more_columns).as_expr end |
#exp ⇒ Expr
Compute the exponential, element-wise.
397 398 399 |
# File 'lib/polars/expr.rb', line 397 def exp wrap_expr(_rbexpr.exp) end |
#explode(empty_as_null: OMITTED, keep_nulls: true) ⇒ Expr
Explode a list or utf8 Series.
This means that every item is expanded to a new row.
3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 |
# File 'lib/polars/expr.rb', line 3695 def explode(empty_as_null: OMITTED, keep_nulls: true) if empty_as_null == OMITTED Utils.issue_deprecation_warning( "The default behavior for `empty_as_null` will change to `false`. " + "To keep the current behavior, explicitly set `empty_as_null: true`." ) empty_as_null = true end wrap_expr(_rbexpr.explode(empty_as_null, keep_nulls)) end |
#ext ⇒ ExtensionExpr
Create an object namespace of all extension type related expressions.
8614 8615 8616 |
# File 'lib/polars/expr.rb', line 8614 def ext ExtensionExpr.new(self) end |
#extend_constant(value, n) ⇒ Expr
Extend the Series with given number of values.
7730 7731 7732 7733 7734 |
# File 'lib/polars/expr.rb', line 7730 def extend_constant(value, n) value = Utils.parse_into_expression(value, str_as_lit: true) n = Utils.parse_into_expression(n) wrap_expr(_rbexpr.extend_constant(value, n)) end |
#fill_nan(value) ⇒ Expr
Fill floating point NaN value with a fill value.
2182 2183 2184 2185 |
# File 'lib/polars/expr.rb', line 2182 def fill_nan(value) fill_value_rbexpr = Utils.parse_into_expression(value, str_as_lit: true) wrap_expr(_rbexpr.fill_nan(fill_value_rbexpr)) end |
#fill_null(value = nil, strategy: nil, limit: nil) ⇒ Expr
Fill null values using the specified value or strategy.
To interpolate over null values see interpolate.
2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 |
# File 'lib/polars/expr.rb', line 2142 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) wrap_expr(_rbexpr.fill_null(value)) else wrap_expr(_rbexpr.fill_null_with_strategy(strategy, limit)) end end |
#filter(*predicates, **constraints) ⇒ Expr
Filter a single column.
Mostly useful in an aggregation context. If you want to filter on a DataFrame
level, use LazyFrame#filter.
3494 3495 3496 3497 3498 3499 |
# File 'lib/polars/expr.rb', line 3494 def filter(*predicates, **constraints) predicate = Utils.parse_predicates_constraints_into_expression( *predicates, **constraints ) wrap_expr(_rbexpr.filter(predicate)) end |
#first(ignore_nulls: false) ⇒ Expr
Get the first value.
2739 2740 2741 |
# File 'lib/polars/expr.rb', line 2739 def first(ignore_nulls: false) wrap_expr(_rbexpr.first(ignore_nulls)) end |
#flatten ⇒ Expr
Expr#flatten is deprecated and will be removed in a future version.
Use Expr.list.explode(keep_nulls: false, empty_as_null: false) instead,
which provides the behavior you likely expect.
Explode a list or utf8 Series. This means that every item is expanded to a new row.
Alias for #explode.
3668 3669 3670 |
# File 'lib/polars/expr.rb', line 3668 def flatten explode(empty_as_null: true, keep_nulls: true) end |
#floor ⇒ Expr
Rounds down to the nearest integer value.
Only works on floating point Series.
1152 1153 1154 |
# File 'lib/polars/expr.rb', line 1152 def floor wrap_expr(_rbexpr.floor) end |
#floordiv(other) ⇒ Expr
Method equivalent of integer division operator expr // other.
4237 4238 4239 |
# File 'lib/polars/expr.rb', line 4237 def floordiv(other) wrap_expr(_rbexpr.floordiv(_to_rbexpr(other))) end |
#forward_fill(limit: nil) ⇒ Expr
Fill missing values with the latest seen values.
2213 2214 2215 |
# File 'lib/polars/expr.rb', line 2213 def forward_fill(limit: nil) fill_null(strategy: "forward", limit: limit) end |
#gather(indices, null_on_oob: false) ⇒ Expr
Take values by index.
1998 1999 2000 2001 2002 2003 2004 2005 |
# File 'lib/polars/expr.rb', line 1998 def gather(indices, null_on_oob: false) if indices.is_a?(::Array) indices_lit_rbexpr = Polars.lit(Series.new("", indices, dtype: Int64))._rbexpr else indices_lit_rbexpr = Utils.parse_into_expression(indices) end wrap_expr(_rbexpr.gather(indices_lit_rbexpr, null_on_oob)) end |
#gather_every(n, offset = 0) ⇒ Expr
Take every nth value in the Series and return as a new Series.
3725 3726 3727 |
# File 'lib/polars/expr.rb', line 3725 def gather_every(n, offset = 0) wrap_expr(_rbexpr.gather_every(n, offset)) end |
#ge(other) ⇒ Expr
Method equivalent of "greater than or equal" operator expr >= other.
3989 3990 3991 |
# File 'lib/polars/expr.rb', line 3989 def ge(other) self >= other end |
#get(index, null_on_oob: false) ⇒ Expr
Return a single value by index.
2044 2045 2046 2047 |
# File 'lib/polars/expr.rb', line 2044 def get(index, null_on_oob: false) index_lit = Utils.parse_into_expression(index) wrap_expr(_rbexpr.get(index_lit, null_on_oob)) end |
#gt(other) ⇒ Expr
Method equivalent of "greater than" operator expr > other.
4022 4023 4024 |
# File 'lib/polars/expr.rb', line 4022 def gt(other) self > other end |
#has_nulls ⇒ Expr
Check whether the expression contains one or more null values.
2646 2647 2648 |
# File 'lib/polars/expr.rb', line 2646 def has_nulls null_count > 0 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 UInt64.
4709 4710 4711 4712 4713 4714 4715 |
# File 'lib/polars/expr.rb', line 4709 def hash_(seed = 0, seed_1 = nil, seed_2 = nil, seed_3 = nil) k0 = seed k1 = seed_1.nil? ? seed : seed_1 k2 = seed_2.nil? ? seed : seed_2 k3 = seed_3.nil? ? seed : seed_3 wrap_expr(_rbexpr._hash(k0, k1, k2, k3)) end |
#head(n = 10) ⇒ Expr
Get the first n rows.
3750 3751 3752 |
# File 'lib/polars/expr.rb', line 3750 def head(n = 10) wrap_expr(_rbexpr.head(n)) end |
#hist(bins: nil, bin_count: nil, include_category: false, include_breakpoint: false) ⇒ Expr
This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.
Bin values into buckets and count their occurrences.
8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 |
# File 'lib/polars/expr.rb', line 8068 def hist( bins: nil, bin_count: nil, include_category: false, include_breakpoint: false ) if !bins.nil? if bins.is_a?(::Array) bins = Polars::Series.new(bins) end bins = Utils.parse_into_expression(bins) end wrap_expr( _rbexpr.hist(bins, bin_count, include_category, include_breakpoint) ) end |
#implode(maintain_order: true) ⇒ Expr
Aggregate to list.
8016 8017 8018 |
# File 'lib/polars/expr.rb', line 8016 def implode(maintain_order: true) wrap_expr(_rbexpr.implode(maintain_order)) end |
#index_of(element) ⇒ Expr
Get the index of the first occurrence of a value, or nil if it's not found.
1853 1854 1855 1856 |
# File 'lib/polars/expr.rb', line 1853 def index_of(element) element = Utils.parse_into_expression(element, str_as_lit: true) wrap_expr(_rbexpr.index_of(element)) end |
#inspect_(fmt = "%s") ⇒ Expr
Print the value that this expression evaluates to and pass on the value.
4786 4787 4788 4789 4790 4791 4792 4793 |
# File 'lib/polars/expr.rb', line 4786 def inspect_(fmt = "%s") inspect = lambda do |s| puts(fmt % [s]) s end map_batches(return_dtype: F.dtype_of(self), &inspect) 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.
4820 4821 4822 |
# File 'lib/polars/expr.rb', line 4820 def interpolate(method: "linear") wrap_expr(_rbexpr.interpolate(method)) end |
#interpolate_by(by) ⇒ Expr
Fill null values using interpolation based on another column.
4850 4851 4852 4853 |
# File 'lib/polars/expr.rb', line 4850 def interpolate_by(by) by = Utils.parse_into_expression(by) wrap_expr(_rbexpr.interpolate_by(by)) end |
#is_between(lower_bound, upper_bound, closed: "both") ⇒ Expr
Check if this expression is between start and end.
4569 4570 4571 4572 4573 4574 4575 4576 |
# File 'lib/polars/expr.rb', line 4569 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) wrap_expr( _rbexpr.is_between(lower_bound, upper_bound, closed) ) end |
#is_close(other, abs_tol: 0.0, rel_tol: 1.0e-09, nans_equal: false) ⇒ Expr
Check if this expression is close, i.e. almost equal, to the other expression.
4605 4606 4607 4608 4609 4610 4611 4612 4613 |
# File 'lib/polars/expr.rb', line 4605 def is_close( other, abs_tol: 0.0, rel_tol: 1.0e-09, nans_equal: false ) other = Utils.parse_into_expression(other) wrap_expr(_rbexpr.is_close(other, abs_tol, rel_tol, nans_equal)) end |
#is_duplicated ⇒ Expr
Get mask of duplicated values.
3129 3130 3131 |
# File 'lib/polars/expr.rb', line 3129 def is_duplicated wrap_expr(_rbexpr.is_duplicated) end |
#is_empty(ignore_nulls: false) ⇒ Expr
This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.
Return whether the column is empty.
283 284 285 |
# File 'lib/polars/expr.rb', line 283 def is_empty(ignore_nulls: false) wrap_expr(_rbexpr.is_empty(ignore_nulls)) end |
#is_finite ⇒ Expr
Returns a boolean Series indicating which values are finite.
643 644 645 |
# File 'lib/polars/expr.rb', line 643 def is_finite wrap_expr(_rbexpr.is_finite) end |
#is_first_distinct ⇒ Expr
Get a mask of the first unique value.
3083 3084 3085 |
# File 'lib/polars/expr.rb', line 3083 def is_first_distinct wrap_expr(_rbexpr.is_first_distinct) end |
#is_in(other, nulls_equal: false) ⇒ Expr Also known as: in?
Check if elements of this expression are present in the other Series.
4462 4463 4464 4465 |
# File 'lib/polars/expr.rb', line 4462 def is_in(other, nulls_equal: false) other = Utils.parse_into_expression(other) wrap_expr(_rbexpr.is_in(other, nulls_equal)) end |
#is_infinite ⇒ Expr
Returns a boolean Series indicating which values are infinite.
669 670 671 |
# File 'lib/polars/expr.rb', line 669 def is_infinite wrap_expr(_rbexpr.is_infinite) end |
#is_last_distinct ⇒ Expr
Return a boolean mask indicating the last occurrence of each distinct value.
3107 3108 3109 |
# File 'lib/polars/expr.rb', line 3107 def is_last_distinct wrap_expr(_rbexpr.is_last_distinct) 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.
702 703 704 |
# File 'lib/polars/expr.rb', line 702 def is_nan wrap_expr(_rbexpr.is_nan) end |
#is_not ⇒ Expr Also known as: not_
Negate a boolean expression.
558 559 560 |
# File 'lib/polars/expr.rb', line 558 def is_not wrap_expr(_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.
735 736 737 |
# File 'lib/polars/expr.rb', line 735 def is_not_nan wrap_expr(_rbexpr.is_not_nan) end |
#is_not_null ⇒ Expr
Returns a boolean Series indicating which values are not null.
617 618 619 |
# File 'lib/polars/expr.rb', line 617 def is_not_null wrap_expr(_rbexpr.is_not_null) end |
#is_null ⇒ Expr
Returns a boolean Series indicating which values are null.
588 589 590 |
# File 'lib/polars/expr.rb', line 588 def is_null wrap_expr(_rbexpr.is_null) end |
#is_sorted(descending: false, nulls_last: false) ⇒ Expr
Checks if an expression is sorted.
If descending and/or nulls_last are nil, it will check true and false
for the unspecified option(s), and return true if the expression is sorted
under any combination of those settings.
4668 4669 4670 4671 4672 4673 |
# File 'lib/polars/expr.rb', line 4668 def is_sorted( descending: false, nulls_last: false ) wrap_expr(_rbexpr.is_sorted(descending, nulls_last)) end |
#is_unique ⇒ Expr
Get mask of unique values.
3055 3056 3057 |
# File 'lib/polars/expr.rb', line 3055 def is_unique wrap_expr(_rbexpr.is_unique) end |
#item(allow_empty: false) ⇒ Expr
Get the single value.
This raises an error if there is not exactly one value.
2801 2802 2803 |
# File 'lib/polars/expr.rb', line 2801 def item(allow_empty: false) Utils.wrap_expr(_rbexpr.item(allow_empty)) 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
6983 6984 6985 |
# File 'lib/polars/expr.rb', line 6983 def kurtosis(fisher: true, bias: true) wrap_expr(_rbexpr.kurtosis(fisher, bias)) end |
#last(ignore_nulls: false) ⇒ Expr
Get the last value.
2764 2765 2766 |
# File 'lib/polars/expr.rb', line 2764 def last(ignore_nulls: false) wrap_expr(_rbexpr.last(ignore_nulls)) end |
#le(other) ⇒ Expr
Method equivalent of "less than or equal" operator expr <= other.
4055 4056 4057 |
# File 'lib/polars/expr.rb', line 4055 def le(other) self <= other end |
#len ⇒ Expr Also known as: length
Count the number of values in this expression.
810 811 812 |
# File 'lib/polars/expr.rb', line 810 def len wrap_expr(_rbexpr.len) end |
#limit(n = 10) ⇒ Expr
Get the first n rows.
Alias for #head.
3802 3803 3804 |
# File 'lib/polars/expr.rb', line 3802 def limit(n = 10) head(n) end |
#list ⇒ ListExpr
Create an object namespace of all list related methods.
8551 8552 8553 |
# File 'lib/polars/expr.rb', line 8551 def list ListExpr.new(self) end |
#log(base = Math::E) ⇒ Expr
Compute the logarithm to a given base.
7846 7847 7848 7849 |
# File 'lib/polars/expr.rb', line 7846 def log(base = Math::E) base_rbexpr = Utils.parse_into_expression(base) wrap_expr(_rbexpr.log(base_rbexpr)) end |
#log10 ⇒ Expr
Compute the base 10 logarithm of the input array, element-wise.
375 376 377 |
# File 'lib/polars/expr.rb', line 375 def log10 log(10) end |
#log1p ⇒ Expr
Compute the natural logarithm of each element plus one.
This computes log(1 + x) but is more numerically stable for x close to zero.
7871 7872 7873 |
# File 'lib/polars/expr.rb', line 7871 def log1p wrap_expr(_rbexpr.log1p) end |
#lower_bound ⇒ Expr
Calculate the lower bound.
Returns a unit Series with the lowest value possible for the dtype of this expression.
7043 7044 7045 |
# File 'lib/polars/expr.rb', line 7043 def lower_bound wrap_expr(_rbexpr.lower_bound) end |
#lt(other) ⇒ Expr
Method equivalent of "less than" operator expr < other.
4088 4089 4090 |
# File 'lib/polars/expr.rb', line 4088 def lt(other) self < other end |
#map_batches(return_dtype: nil, is_elementwise: false, returns_scalar: false, &function) ⇒ Expr
Apply a custom Ruby function to a Series or array of Series.
3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 |
# File 'lib/polars/expr.rb', line 3533 def map_batches( return_dtype: nil, is_elementwise: false, returns_scalar: false, &function ) _wrap = lambda do |sl, *args, **kwargs| function.(sl[0], *args, **kwargs) end F.map_batches( [self], return_dtype: return_dtype, is_elementwise: is_elementwise, returns_scalar: returns_scalar, &_wrap ) end |
#map_elements(return_dtype: nil, skip_nulls: true, pass_name: false, strategy: "thread_local", returns_scalar: false, &function) ⇒ Expr
Apply a custom/user-defined function (UDF) in a GroupBy or Projection context.
Depending on the context it has the following behavior:
- Selection
Expects
fto be of type Callable[[Any], Any]. Applies a Ruby function over each individual value in the column. - GroupBy
Expects
fto be of type Callable[[Series], Series]. Applies a Ruby function over each group.
Implementing logic using a Ruby function is almost always significantly slower and more memory intensive than implementing the same logic using the native expression API because:
- The native expression engine runs in Rust; UDFs run in Ruby.
- Use of Ruby UDFs forces the DataFrame to be materialized in memory.
- Polars-native expressions can be parallelised (UDFs cannot).
- Polars-native expressions can be logically optimised (UDFs cannot).
Wherever possible you should strongly prefer the native expression API to achieve the best performance.
3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 |
# File 'lib/polars/expr.rb', line 3606 def map_elements( return_dtype: nil, skip_nulls: true, pass_name: false, strategy: "thread_local", returns_scalar: false, &function ) if pass_name raise Todo else wrap_f = lambda do |x, **kwargs| return_dtype = kwargs[:return_dtype] x.map_elements(return_dtype: return_dtype, skip_nulls: skip_nulls, &function) end end if strategy == "thread_local" map_batches( return_dtype: return_dtype, returns_scalar: false, is_elementwise: true, &wrap_f ) elsif strategy == "threading" raise Todo else msg = "strategy #{strategy.inspect} is not supported" raise ArgumentError, msg end end |
#max ⇒ Expr
Get maximum value.
2345 2346 2347 |
# File 'lib/polars/expr.rb', line 2345 def max wrap_expr(_rbexpr.max) end |
#max_by(by) ⇒ Expr
This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.
Get maximum value, ordered by another expression.
If the by expression has multiple values equal to the maximum it is not defined which value will be chosen.
2376 2377 2378 2379 |
# File 'lib/polars/expr.rb', line 2376 def max_by(by) by_rbexpr = Utils.parse_into_expression(by) wrap_expr(_rbexpr.max_by(by_rbexpr)) end |
#mean ⇒ Expr
Get mean value.
2513 2514 2515 |
# File 'lib/polars/expr.rb', line 2513 def mean wrap_expr(_rbexpr.mean) end |
#median ⇒ Expr
Get median value using linear interpolation.
2533 2534 2535 |
# File 'lib/polars/expr.rb', line 2533 def median wrap_expr(_rbexpr.median) end |
#meta ⇒ MetaExpr
Create an object namespace of all meta related expression methods.
8586 8587 8588 |
# File 'lib/polars/expr.rb', line 8586 def MetaExpr.new(self) end |
#min ⇒ Expr
Get minimum value.
2397 2398 2399 |
# File 'lib/polars/expr.rb', line 2397 def min wrap_expr(_rbexpr.min) end |
#min_by(by) ⇒ Expr
This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.
Get minimum value, ordered by another expression.
If the by expression has multiple values equal to the minimum it is not defined which value will be chosen.
2428 2429 2430 2431 |
# File 'lib/polars/expr.rb', line 2428 def min_by(by) by_rbexpr = Utils.parse_into_expression(by) wrap_expr(_rbexpr.min_by(by_rbexpr)) end |
#mod(other) ⇒ Expr
Method equivalent of modulus operator expr % other.
4264 4265 4266 |
# File 'lib/polars/expr.rb', line 4264 def mod(other) self % other end |
#mode(maintain_order: false) ⇒ Expr
Compute the most occurring value(s).
Can return multiple Values.
1338 1339 1340 |
# File 'lib/polars/expr.rb', line 1338 def mode(maintain_order: false) wrap_expr(_rbexpr.mode(maintain_order)) end |
#mul(other) ⇒ Expr
Method equivalent of multiplication operator expr * other.
4294 4295 4296 |
# File 'lib/polars/expr.rb', line 4294 def mul(other) self * other end |
#n_unique ⇒ Expr
Count unique values.
2573 2574 2575 |
# File 'lib/polars/expr.rb', line 2573 def n_unique wrap_expr(_rbexpr.n_unique) end |
#name ⇒ NameExpr
Create an object namespace of all expressions that modify expression names.
8593 8594 8595 |
# File 'lib/polars/expr.rb', line 8593 def name NameExpr.new(self) end |
#nan_max ⇒ Expr
Get maximum value, but propagate/poison encountered NaN values.
2449 2450 2451 |
# File 'lib/polars/expr.rb', line 2449 def nan_max wrap_expr(_rbexpr.nan_max) end |
#nan_min ⇒ Expr
Get minimum value, but propagate/poison encountered NaN values.
2469 2470 2471 |
# File 'lib/polars/expr.rb', line 2469 def nan_min wrap_expr(_rbexpr.nan_min) end |
#ne(other) ⇒ Expr
Method equivalent of inequality operator expr != other.
4121 4122 4123 |
# File 'lib/polars/expr.rb', line 4121 def ne(other) self != other end |
#ne_missing(other) ⇒ Expr
Method equivalent of equality operator expr != other where nil == nil.
This differs from default ne where null values are propagated.
4159 4160 4161 4162 |
# File 'lib/polars/expr.rb', line 4159 def ne_missing(other) other = Utils.parse_into_expression(other, str_as_lit: true) wrap_expr(_rbexpr.neq_missing(other)) end |
#neg ⇒ Expr
Method equivalent of unary minus operator -expr.
4347 4348 4349 |
# File 'lib/polars/expr.rb', line 4347 def neg -self end |
#null_count ⇒ Expr
Count null values.
2620 2621 2622 |
# File 'lib/polars/expr.rb', line 2620 def null_count wrap_expr(_rbexpr.null_count) end |
#or_(*others) ⇒ Expr
Method equivalent of bitwise "or" operator expr | other | ....
3885 3886 3887 |
# File 'lib/polars/expr.rb', line 3885 def or_(*others) ([self] + others).reduce(:|) end |
#over(partition_by = nil, *more_exprs, order_by: nil, descending: false, nulls_last: false, mapping_strategy: "group_to_rows") ⇒ Expr
Apply window function over a subgroup.
This is similar to a group by + aggregation + self join. Or similar to window functions in Postgres.
2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 |
# File 'lib/polars/expr.rb', line 2920 def over(partition_by = nil, *more_exprs, order_by: nil, descending: false, nulls_last: false, mapping_strategy: "group_to_rows") partition_by_rbexprs = if !partition_by.nil? Utils.parse_into_list_of_expressions(partition_by, *more_exprs) else nil end order_by_rbexprs = !order_by.nil? ? Utils.parse_into_list_of_expressions(order_by) : nil wrap_expr(_rbexpr.over(partition_by_rbexprs, order_by_rbexprs, descending, nulls_last, mapping_strategy)) 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.
6921 6922 6923 6924 |
# File 'lib/polars/expr.rb', line 6921 def pct_change(n: 1) n = Utils.parse_into_expression(n) wrap_expr(_rbexpr.pct_change(n)) end |
#peak_max ⇒ Expr
Get a boolean mask of the local maximum peaks.
3153 3154 3155 |
# File 'lib/polars/expr.rb', line 3153 def peak_max wrap_expr(_rbexpr.peak_max) end |
#peak_min ⇒ Expr
Get a boolean mask of the local minimum peaks.
3177 3178 3179 |
# File 'lib/polars/expr.rb', line 3177 def peak_min wrap_expr(_rbexpr.peak_min) end |
#pipe(function, *args, **kwargs) ⇒ Object
Offers a structured way to apply a sequence of user-defined functions (UDFs).
514 515 516 517 518 519 520 |
# File 'lib/polars/expr.rb', line 514 def pipe( function, *args, **kwargs ) function.(self, *args, **kwargs) end |
#pow(exponent) ⇒ Expr
Raise expression to the power of exponent.
4405 4406 4407 |
# File 'lib/polars/expr.rb', line 4405 def pow(exponent) self**exponent end |
#product ⇒ Expr
Compute the product of an expression.
2553 2554 2555 |
# File 'lib/polars/expr.rb', line 2553 def product wrap_expr(_rbexpr.product) end |
#qcut(quantiles, labels: nil, left_closed: false, allow_duplicates: false, include_breaks: false) ⇒ Expr
Bin continuous values into discrete categories based on their quantiles.
3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 |
# File 'lib/polars/expr.rb', line 3388 def qcut(quantiles, labels: nil, left_closed: false, allow_duplicates: false, include_breaks: false) if quantiles.is_a?(Integer) rbexpr = _rbexpr.qcut_uniform( quantiles, labels, left_closed, allow_duplicates, include_breaks ) else rbexpr = _rbexpr.qcut( quantiles, labels, left_closed, allow_duplicates, include_breaks ) end wrap_expr(rbexpr) end |
#quantile(quantile, interpolation: "nearest") ⇒ Expr
Get quantile value.
3250 3251 3252 3253 |
# File 'lib/polars/expr.rb', line 3250 def quantile(quantile, interpolation: "nearest") quantile = Utils.parse_into_expression(quantile, str_as_lit: false) wrap_expr(_rbexpr.quantile(quantile, interpolation)) end |
#radians ⇒ Expr
Convert from degrees to radians.
7406 7407 7408 |
# File 'lib/polars/expr.rb', line 7406 def radians wrap_expr(_rbexpr.radians) end |
#rank(method: "average", descending: false, seed: nil) ⇒ Expr
Assign ranks to data, dealing with ties appropriately.
6853 6854 6855 |
# File 'lib/polars/expr.rb', line 6853 def rank(method: "average", descending: false, seed: nil) wrap_expr(_rbexpr.rank(method, descending, seed)) end |
#rechunk ⇒ Expr
Create a single chunk of memory for this Series.
908 909 910 |
# File 'lib/polars/expr.rb', line 908 def rechunk wrap_expr(_rbexpr.rechunk) end |
#reinterpret(signed: nil, dtype: nil) ⇒ Expr
Reinterpret the underlying bits as a signed/unsigned integer or float.
This operation is only allowed for numeric types of the same size. For lower bits numbers, you can safely use the cast operation.
Either signed or dtype can be specified.
4752 4753 4754 4755 4756 4757 4758 4759 |
# File 'lib/polars/expr.rb', line 4752 def reinterpret(signed: nil, dtype: nil) if signed.nil? == dtype.nil? msg = "reinterpret requires exactly one of `signed` or `dtype` to be specified" raise ArgumentError, msg end wrap_expr(_rbexpr.reinterpret(signed, dtype)) 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.
4498 4499 4500 4501 |
# File 'lib/polars/expr.rb', line 4498 def repeat_by(by) by = Utils.parse_into_expression(by, str_as_lit: false) wrap_expr(_rbexpr.repeat_by(by)) end |
#replace(old, new = NO_DEFAULT, default: NO_DEFAULT, return_dtype: nil) ⇒ Expr
Replace values by different values.
8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 |
# File 'lib/polars/expr.rb', line 8221 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 = wrap_expr(_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.
8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 |
# File 'lib/polars/expr.rb', line 8377 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) wrap_expr( _rbexpr.replace_strict(old, new, default, return_dtype) ) end |
#reshape(dimensions) ⇒ Expr
Reshape this Expr to a flat Series or a Series of Lists.
7452 7453 7454 |
# File 'lib/polars/expr.rb', line 7452 def reshape(dimensions) wrap_expr(_rbexpr.reshape(dimensions)) end |
#reverse ⇒ Expr
Reverse the selection.
2279 2280 2281 |
# File 'lib/polars/expr.rb', line 2279 def reverse wrap_expr(_rbexpr.reverse) end |
#rle ⇒ Expr
Get the lengths of runs of identical values.
3423 3424 3425 |
# File 'lib/polars/expr.rb', line 3423 def rle wrap_expr(_rbexpr.rle) end |
#rle_id ⇒ Expr
Map values to run IDs.
Similar to RLE, but it maps each value to an ID corresponding to the run into which it falls. This is especially useful when you want to define groups by runs of identical values rather than the values themselves.
3451 3452 3453 |
# File 'lib/polars/expr.rb', line 3451 def rle_id wrap_expr(_rbexpr.rle_id) end |
#rolling(index_column:, period:, offset: nil, closed: "right") ⇒ Expr
Create rolling groups based on a temporal or integer column.
If you have a time series <t_0, t_1, ..., t_n>, then by default the
windows created will be
* (t_0 - period, t_0]
* (t_1 - period, t_1]
* ...
* (t_n - period, t_n]
whereas if you pass a non-default offset, then the windows will be
* (t_0 + offset, t_0 + offset + period]
* (t_1 + offset, t_1 + offset + period]
* ...
* (t_n + offset, t_n + offset + period]
The period and offset arguments are created either from a timedelta, or
by using the following string language:
- 1ns (1 nanosecond)
- 1us (1 microsecond)
- 1ms (1 millisecond)
- 1s (1 second)
- 1m (1 minute)
- 1h (1 hour)
- 1d (1 calendar day)
- 1w (1 calendar week)
- 1mo (1 calendar month)
- 1q (1 calendar quarter)
- 1y (1 calendar year)
- 1i (1 index count)
Or combine them: "3d12h4m25s" # 3 days, 12 hours, 4 minutes, and 25 seconds
By "calendar day", we mean the corresponding time on the next day (which may not be 24 hours, due to daylight savings). Similarly for "calendar week", "calendar month", "calendar quarter", and "calendar year".
3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 |
# File 'lib/polars/expr.rb', line 3020 def rolling( index_column:, period:, offset: nil, closed: "right" ) index_column_rbexpr = Utils.parse_into_expression(index_column) if offset.nil? offset = Utils.negate_duration_string(Utils.parse_as_duration_string(period)) end period = Utils.parse_as_duration_string(period) offset = Utils.parse_as_duration_string(offset) wrap_expr(_rbexpr.rolling(index_column_rbexpr, period, offset, closed)) end |
#rolling_kurtosis(window_size, fisher: true, bias: true, min_samples: nil, center: false) ⇒ Expr
This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.
Compute a rolling kurtosis.
The window at a given row will include the row itself, and the window_size - 1
elements before it.
6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 |
# File 'lib/polars/expr.rb', line 6687 def rolling_kurtosis( window_size, fisher: true, bias: true, min_samples: nil, center: false ) wrap_expr( _rbexpr.rolling_kurtosis( window_size, fisher, bias, min_samples, center ) ) end |
#rolling_map(window_size, weights: nil, min_samples: nil, center: false, &function) ⇒ Expr
This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.
Compute a custom rolling window function.
6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 |
# File 'lib/polars/expr.rb', line 6740 def rolling_map( window_size, weights: nil, min_samples: nil, center: false, &function ) if min_samples.nil? min_samples = window_size end _wrap = lambda do |rbs| s = Utils.wrap_s(rbs) rv = function.(s) if rv.is_a?(Series) rv._s else Series.new([rv])._s end end wrap_expr( _rbexpr.rolling_map(_wrap, window_size, weights, min_samples, center) ) end |
#rolling_max(window_size, weights: nil, min_samples: 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 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.
6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 |
# File 'lib/polars/expr.rb', line 6057 def rolling_max( window_size, weights: nil, min_samples: nil, center: false ) wrap_expr( _rbexpr.rolling_max( window_size, weights, min_samples, center ) ) end |
#rolling_max_by(by, window_size, min_samples: 1, closed: "right") ⇒ 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.
5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 |
# File 'lib/polars/expr.rb', line 5068 def rolling_max_by( by, window_size, min_samples: 1, closed: "right" ) window_size = _prepare_rolling_by_window_args(window_size) by = Utils.parse_into_expression(by) wrap_expr( _rbexpr.rolling_max_by(by, window_size, min_samples, closed) ) end |
#rolling_mean(window_size, weights: nil, min_samples: 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 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.
6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 |
# File 'lib/polars/expr.rb', line 6135 def rolling_mean( window_size, weights: nil, min_samples: nil, center: false ) wrap_expr( _rbexpr.rolling_mean( window_size, weights, min_samples, center ) ) end |
#rolling_mean_by(by, window_size, min_samples: 1, closed: "right") ⇒ 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.
5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 |
# File 'lib/polars/expr.rb', line 5196 def rolling_mean_by( by, window_size, min_samples: 1, closed: "right" ) window_size = _prepare_rolling_by_window_args(window_size) by = Utils.parse_into_expression(by) wrap_expr( _rbexpr.rolling_mean_by( by, window_size, min_samples, closed ) ) end |
#rolling_median(window_size, weights: nil, min_samples: 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 rolling this method can cache the window size
computation.
Compute a rolling median.
6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 |
# File 'lib/polars/expr.rb', line 6449 def rolling_median( window_size, weights: nil, min_samples: nil, center: false ) wrap_expr( _rbexpr.rolling_median( window_size, weights, min_samples, center ) ) end |
#rolling_median_by(by, window_size, min_samples: 1, closed: "right") ⇒ 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.
5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 |
# File 'lib/polars/expr.rb', line 5699 def rolling_median_by( by, window_size, min_samples: 1, closed: "right" ) window_size = _prepare_rolling_by_window_args(window_size) by = Utils.parse_into_expression(by) wrap_expr( _rbexpr.rolling_median_by(by, window_size, min_samples, closed) ) end |
#rolling_min(window_size, weights: nil, min_samples: 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 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.
5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 |
# File 'lib/polars/expr.rb', line 5979 def rolling_min( window_size, weights: nil, min_samples: nil, center: false ) wrap_expr( _rbexpr.rolling_min( window_size, weights, min_samples, center ) ) end |
#rolling_min_by(by, window_size, min_samples: 1, closed: "right") ⇒ 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.
4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 |
# File 'lib/polars/expr.rb', line 4942 def rolling_min_by( by, window_size, min_samples: 1, closed: "right" ) window_size = _prepare_rolling_by_window_args(window_size) by = Utils.parse_into_expression(by) wrap_expr( _rbexpr.rolling_min_by(by, window_size, min_samples, closed) ) end |
#rolling_quantile(quantile, interpolation: "nearest", window_size: 2, weights: nil, min_samples: 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 rolling this method can cache the window size
computation.
Compute a rolling quantile.
6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 |
# File 'lib/polars/expr.rb', line 6527 def rolling_quantile( quantile, interpolation: "nearest", window_size: 2, weights: nil, min_samples: nil, center: false ) wrap_expr( _rbexpr.rolling_quantile( quantile, interpolation, window_size, weights, min_samples, center ) ) end |
#rolling_quantile_by(by, window_size, quantile:, interpolation: "nearest", min_samples: 1, closed: "right") ⇒ 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.
5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 |
# File 'lib/polars/expr.rb', line 5805 def rolling_quantile_by( by, window_size, quantile:, interpolation: "nearest", min_samples: 1, closed: "right" ) window_size = _prepare_rolling_by_window_args(window_size) by = Utils.parse_into_expression(by) wrap_expr( _rbexpr.rolling_quantile_by( by, quantile, interpolation, window_size, min_samples, closed, ) ) end |
#rolling_rank(window_size, method: "average", seed: nil, min_samples: nil, center: false) ⇒ Expr
This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.
Compute a rolling rank.
A window of length window_size will traverse the array. The values
that fill this window will be ranked according to the method
parameter. The resulting values will be the rank of the value that is
at the end of the sliding window.
6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 |
# File 'lib/polars/expr.rb', line 6597 def rolling_rank( window_size, method: "average", seed: nil, min_samples: nil, center: false ) Utils.wrap_expr( _rbexpr.rolling_rank( window_size, method, seed, min_samples, center ) ) end |
#rolling_rank_by(by, window_size, method: "average", seed: nil, min_samples: 1, closed: "right") ⇒ Expr
This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.
Compute a rolling rank based on another column.
Given a by column <t_0, t_1, ..., t_n>, then closed: "right"
(the default) means the windows will be:
- (t_0 - window_size, t_0]
- (t_1 - window_size, t_1]
- ...
- (t_n - window_size, t_n]
5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 |
# File 'lib/polars/expr.rb', line 5892 def rolling_rank_by( by, window_size, method: "average", seed: nil, min_samples: 1, closed: "right" ) window_size = _prepare_rolling_by_window_args(window_size) by_rbexpr = Utils.parse_into_expression(by) Utils.wrap_expr( _rbexpr.rolling_rank_by( by_rbexpr, window_size, method, seed, min_samples, closed ) ) end |
#rolling_skew(window_size, bias: true, min_samples: nil, center: false) ⇒ Expr
Compute a rolling skew.
6644 6645 6646 |
# File 'lib/polars/expr.rb', line 6644 def rolling_skew(window_size, bias: true, min_samples: nil, center: false) wrap_expr(_rbexpr.rolling_skew(window_size, bias, min_samples, center)) end |
#rolling_std(window_size, weights: nil, min_samples: 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 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.
6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 |
# File 'lib/polars/expr.rb', line 6293 def rolling_std( window_size, weights: nil, min_samples: nil, center: false, ddof: 1 ) wrap_expr( _rbexpr.rolling_std( window_size, weights, min_samples, center, ddof ) ) end |
#rolling_std_by(by, window_size, min_samples: 1, closed: "right", ddof: 1) ⇒ 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.
5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 |
# File 'lib/polars/expr.rb', line 5455 def rolling_std_by( by, window_size, min_samples: 1, closed: "right", ddof: 1 ) window_size = _prepare_rolling_by_window_args(window_size) by = Utils.parse_into_expression(by) wrap_expr( _rbexpr.rolling_std_by( by, window_size, min_samples, closed, ddof ) ) end |
#rolling_sum(window_size, weights: nil, min_samples: 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 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.
6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 |
# File 'lib/polars/expr.rb', line 6213 def rolling_sum( window_size, weights: nil, min_samples: nil, center: false ) wrap_expr( _rbexpr.rolling_sum( window_size, weights, min_samples, center ) ) end |
#rolling_sum_by(by, window_size, min_samples: 0, closed: "right") ⇒ 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.
5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 |
# File 'lib/polars/expr.rb', line 5327 def rolling_sum_by( by, window_size, min_samples: 0, closed: "right" ) window_size = _prepare_rolling_by_window_args(window_size) by = Utils.parse_into_expression(by) wrap_expr( _rbexpr.rolling_sum_by(by, window_size, min_samples, closed) ) end |
#rolling_var(window_size, weights: nil, min_samples: 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 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.
6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 |
# File 'lib/polars/expr.rb', line 6374 def rolling_var( window_size, weights: nil, min_samples: nil, center: false, ddof: 1 ) wrap_expr( _rbexpr.rolling_var( window_size, weights, min_samples, center, ddof ) ) end |
#rolling_var_by(by, window_size, min_samples: 1, closed: "right", ddof: 1) ⇒ 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.
5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 |
# File 'lib/polars/expr.rb', line 5590 def rolling_var_by( by, window_size, min_samples: 1, closed: "right", ddof: 1 ) window_size = _prepare_rolling_by_window_args(window_size) by = Utils.parse_into_expression(by) wrap_expr( _rbexpr.rolling_var_by( by, window_size, min_samples, closed, ddof ) ) end |
#round(decimals = 0, mode: "half_to_even") ⇒ Expr
Round underlying floating point data by decimals digits.
1210 1211 1212 |
# File 'lib/polars/expr.rb', line 1210 def round(decimals = 0, mode: "half_to_even") wrap_expr(_rbexpr.round(decimals, mode)) end |
#round_sig_figs(digits) ⇒ Expr
Round to a number of significant figures.
1235 1236 1237 |
# File 'lib/polars/expr.rb', line 1235 def round_sig_figs(digits) wrap_expr(_rbexpr.round_sig_figs(digits)) end |
#sample(fraction: nil, with_replacement: false, shuffle: false, seed: nil, n: nil) ⇒ Expr
Sample from this expression.
7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 |
# File 'lib/polars/expr.rb', line 7515 def sample( fraction: nil, with_replacement: false, shuffle: false, seed: nil, n: nil ) if !n.nil? && !fraction.nil? raise ArgumentError, "cannot specify both `n` and `fraction`" end if !n.nil? && fraction.nil? n = Utils.parse_into_expression(n) return wrap_expr(_rbexpr.sample_n(n, with_replacement, shuffle, seed)) end if fraction.nil? fraction = 1.0 end fraction = Utils.parse_into_expression(fraction) wrap_expr( _rbexpr.sample_frac(fraction, with_replacement, shuffle, seed) ) end |
#search_sorted(element, side: "any", descending: false) ⇒ Expr
Find indices where elements should be inserted to maintain order.
1894 1895 1896 1897 |
# File 'lib/polars/expr.rb', line 1894 def search_sorted(element, side: "any", descending: false) element = Utils.parse_into_expression(element, str_as_lit: false) wrap_expr(_rbexpr.search_sorted(element, side, descending)) end |
#set_sorted(descending: false, nulls_last: 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.
7987 7988 7989 |
# File 'lib/polars/expr.rb', line 7987 def set_sorted(descending: false, nulls_last: false) wrap_expr(_rbexpr.set_sorted_flag(descending, nulls_last)) end |
#shift(n = 1, fill_value: nil) ⇒ Expr
Shift the values by a given period.
2073 2074 2075 2076 2077 2078 2079 |
# File 'lib/polars/expr.rb', line 2073 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) wrap_expr(_rbexpr.shift(n, fill_value)) end |
#shuffle(seed: nil) ⇒ Expr
Shuffle the contents of this expr.
7478 7479 7480 7481 7482 7483 |
# File 'lib/polars/expr.rb', line 7478 def shuffle(seed: nil) if seed.nil? seed = rand(10000) end wrap_expr(_rbexpr.shuffle(seed)) end |
#sign ⇒ Expr
Compute the element-wise indication of the sign.
7090 7091 7092 |
# File 'lib/polars/expr.rb', line 7090 def sign wrap_expr(_rbexpr.sign) end |
#sin ⇒ Expr
Compute the element-wise value for the sine.
7110 7111 7112 |
# File 'lib/polars/expr.rb', line 7110 def sin wrap_expr(_rbexpr.sin) end |
#sinh ⇒ Expr
Compute the element-wise value for the hyperbolic sine.
7250 7251 7252 |
# File 'lib/polars/expr.rb', line 7250 def sinh wrap_expr(_rbexpr.sinh) end |
#skew(bias: true) ⇒ Expr
Compute the sample skewness of a data set.
For normally distributed data, the skewness should be about zero. For
unimodal continuous distributions, a skewness value greater than zero means
that there is more weight in the right tail of the distribution. The
function skewtest can be used to determine if the skewness value
is close enough to zero, statistically speaking.
6951 6952 6953 |
# File 'lib/polars/expr.rb', line 6951 def skew(bias: true) wrap_expr(_rbexpr.skew(bias)) end |
#slice(offset, length = nil) ⇒ Expr
Get a slice of this expression.
843 844 845 846 847 848 849 850 851 |
# File 'lib/polars/expr.rb', line 843 def slice(offset, length = nil) if !offset.is_a?(Expr) offset = Polars.lit(offset) end if !length.is_a?(Expr) length = Polars.lit(length) end wrap_expr(_rbexpr.slice(offset._rbexpr, length._rbexpr)) end |
#sort(descending: 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.
1455 1456 1457 |
# File 'lib/polars/expr.rb', line 1455 def sort(descending: false, nulls_last: false) wrap_expr(_rbexpr.sort_with(descending, nulls_last)) end |
#sort_by(by, *more_by, descending: 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.
1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 |
# File 'lib/polars/expr.rb', line 1950 def sort_by(by, *more_by, descending: false, nulls_last: false, multithreaded: true, maintain_order: false) by = Utils.parse_into_list_of_expressions(by, *more_by) descending = Utils.extend_bool(descending, by.length, "descending", "by") nulls_last = Utils.extend_bool(nulls_last, by.length, "nulls_last", "by") wrap_expr( _rbexpr.sort_by( by, descending, nulls_last, multithreaded, maintain_order ) ) end |
#sqrt ⇒ Expr
Compute the square root of the elements.
331 332 333 |
# File 'lib/polars/expr.rb', line 331 def sqrt wrap_expr(_rbexpr.sqrt) end |
#std(ddof: 1) ⇒ Expr
Get standard deviation.
2302 2303 2304 |
# File 'lib/polars/expr.rb', line 2302 def std(ddof: 1) wrap_expr(_rbexpr.std(ddof)) end |
#str ⇒ StringExpr
Create an object namespace of all string related methods.
8600 8601 8602 |
# File 'lib/polars/expr.rb', line 8600 def str StringExpr.new(self) end |
#struct ⇒ StructExpr
Create an object namespace of all struct related methods.
8607 8608 8609 |
# File 'lib/polars/expr.rb', line 8607 def struct StructExpr.new(self) end |
#sub(other) ⇒ Expr
Method equivalent of subtraction operator expr - other.
4324 4325 4326 |
# File 'lib/polars/expr.rb', line 4324 def sub(other) self - other end |
#sum ⇒ Expr
Dtypes in \{Int8, UInt8, Int16, UInt16} are cast to Int64 before summing to prevent overflow issues.
Get sum value.
2493 2494 2495 |
# File 'lib/polars/expr.rb', line 2493 def sum wrap_expr(_rbexpr.sum) end |
#tail(n = 10) ⇒ Expr
Get the last n rows.
3775 3776 3777 |
# File 'lib/polars/expr.rb', line 3775 def tail(n = 10) wrap_expr(_rbexpr.tail(n)) end |
#tan ⇒ Expr
Compute the element-wise value for the tangent.
7150 7151 7152 |
# File 'lib/polars/expr.rb', line 7150 def tan wrap_expr(_rbexpr.tan) end |
#tanh ⇒ Expr
Compute the element-wise value for the hyperbolic tangent.
7290 7291 7292 |
# File 'lib/polars/expr.rb', line 7290 def tanh wrap_expr(_rbexpr.tanh) end |
#to_physical ⇒ Expr
Cast to physical representation of the logical dtype.
206 207 208 |
# File 'lib/polars/expr.rb', line 206 def to_physical wrap_expr(_rbexpr.to_physical) end |
#to_s ⇒ String Also known as: inspect
Returns a string representing the Expr.
17 18 19 |
# File 'lib/polars/expr.rb', line 17 def to_s _rbexpr.to_str end |
#top_k(k: 5) ⇒ Expr
Return the k largest elements.
If 'reverse: true` the smallest elements will be given.
1493 1494 1495 1496 |
# File 'lib/polars/expr.rb', line 1493 def top_k(k: 5) k = Utils.parse_into_expression(k) wrap_expr(_rbexpr.top_k(k)) end |
#top_k_by(by, k: 5, reverse: false) ⇒ Expr
Return the elements corresponding to the k largest elements of the by column(s).
Non-null elements are always preferred over null elements, regardless of
the value of reverse. The output is not guaranteed to be in any
particular order, call :func:sort after this function if you wish the
output to be sorted.
1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 |
# File 'lib/polars/expr.rb', line 1593 def top_k_by( by, k: 5, reverse: false ) k = Utils.parse_into_expression(k) by = Utils.parse_into_list_of_expressions(by) reverse = Utils.extend_bool(reverse, by.length, "reverse", "by") wrap_expr(_rbexpr.top_k_by(by, k, reverse)) end |
#truediv(other) ⇒ Expr
Method equivalent of float division operator expr / other.
4379 4380 4381 |
# File 'lib/polars/expr.rb', line 4379 def truediv(other) self / other end |
#truncate(decimals = 0) ⇒ Expr
Truncation discards the fractional part beyond the given number of decimals.
For example, when rounding to 0 decimals 0.25, -0.25, 0.99, and -0.99 will
all round to 0. When rounding to 1 decimal 1.9999 rounds to 1.9 and -1.9999
rounds to -1.9. There is no tiebreak behaviour at midpoint values as there
is with :meth:round so 0.5 and -0.5 will also round to 0 when decimals=1.
This method performs numeric truncation. For truncating temporal
data (dates/datetimes), use :func:Expr.dt.truncate instead.
Truncate numeric data toward zero to decimals number of decimal places.
1278 1279 1280 |
# File 'lib/polars/expr.rb', line 1278 def truncate(decimals = 0) Utils.wrap_expr(_rbexpr.truncate(decimals)) end |
#unique(maintain_order: false) ⇒ Expr
Get unique values of this expression.
2710 2711 2712 2713 2714 2715 2716 |
# File 'lib/polars/expr.rb', line 2710 def unique(maintain_order: false) if maintain_order wrap_expr(_rbexpr.unique_stable) else wrap_expr(_rbexpr.unique) end end |
#unique_counts ⇒ Expr
Return a count of the unique values in the order of appearance.
This method differs from value_counts in that it does not return the
values, only the counts and might be faster
7821 7822 7823 |
# File 'lib/polars/expr.rb', line 7821 def unique_counts wrap_expr(_rbexpr.unique_counts) end |
#upper_bound ⇒ Expr
Calculate the upper bound.
Returns a unit Series with the highest value possible for the dtype of this expression.
7066 7067 7068 |
# File 'lib/polars/expr.rb', line 7066 def upper_bound wrap_expr(_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.
7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 |
# File 'lib/polars/expr.rb', line 7774 def value_counts( sort: false, parallel: false, name: nil, normalize: false ) if name.nil? if normalize name = "proportion" else name = "count" end end wrap_expr( _rbexpr.value_counts(sort, parallel, name, normalize) ) end |
#var(ddof: 1) ⇒ Expr
Get variance.
2325 2326 2327 |
# File 'lib/polars/expr.rb', line 2325 def var(ddof: 1) wrap_expr(_rbexpr.var(ddof)) end |
#xor(other) ⇒ Expr
Method equivalent of bitwise exclusive-or operator expr ^ other.
4433 4434 4435 |
# File 'lib/polars/expr.rb', line 4433 def xor(other) self ^ other end |
#|(other) ⇒ Expr
Bitwise OR.
41 42 43 44 |
# File 'lib/polars/expr.rb', line 41 def |(other) other = Utils.parse_into_expression(other) wrap_expr(_rbexpr.or_(other)) end |