Class: Polars::Series
- Inherits:
-
Object
- Object
- Polars::Series
- Defined in:
- lib/polars/series.rb
Overview
A Series represents a single column in a polars DataFrame.
Instance Method Summary collapse
-
#! ⇒ Series
Performs boolean not.
-
#!=(other) ⇒ Series
Not equal.
-
#%(other) ⇒ Series
Returns the modulo.
-
#&(other) ⇒ Series
Bitwise AND.
-
#*(other) ⇒ Series
Performs multiplication.
-
#**(power) ⇒ Series
Raises to the power of exponent.
-
#+(other) ⇒ Series
Performs addition.
-
#-(other) ⇒ Series
Performs subtraction.
-
#-@ ⇒ Series
Performs negation.
-
#/(other) ⇒ Series
Performs division.
-
#<(other) ⇒ Series
Less than.
-
#<=(other) ⇒ Series
Less than or equal.
-
#==(other) ⇒ Series
Equal.
-
#>(other) ⇒ Series
Greater than.
-
#>=(other) ⇒ Series
Greater than or equal.
-
#[](item) ⇒ Object
Returns elements of the Series.
-
#[]=(key, value) ⇒ Object
Sets an element of the Series.
-
#^(other) ⇒ Series
Bitwise XOR.
-
#abs ⇒ Series
Compute absolute values.
-
#alias(name) ⇒ Series
Return a copy of the Series with a new alias/name.
-
#all?(ignore_nulls: true, &block) ⇒ Boolean
(also: #all)
Check if all boolean values in the column are
true. -
#any?(ignore_nulls: true, &block) ⇒ Boolean
(also: #any)
Check if any boolean value in the column is
true. -
#append(other) ⇒ Series
Append a Series to this one.
-
#approx_n_unique ⇒ Object
Approximate count of unique values.
-
#arccos ⇒ Series
Compute the element-wise value for the inverse cosine.
-
#arccosh ⇒ Series
Compute the element-wise value for the inverse hyperbolic cosine.
-
#arcsin ⇒ Series
Compute the element-wise value for the inverse sine.
-
#arcsinh ⇒ Series
Compute the element-wise value for the inverse hyperbolic sine.
-
#arctan ⇒ Series
Compute the element-wise value for the inverse tangent.
-
#arctanh ⇒ Series
Compute the element-wise value for the inverse hyperbolic tangent.
-
#arg_max ⇒ Integer?
Get the index of the maximal value.
-
#arg_min ⇒ Integer?
Get the index of the minimal value.
-
#arg_sort(descending: false, nulls_last: false) ⇒ Series
Get the index values that would sort this Series.
-
#arg_true ⇒ Series
Get index values where Boolean Series evaluate
true. -
#arg_unique ⇒ Series
Get unique index as Series.
-
#arr ⇒ ArrayNameSpace
Create an object namespace of all array related methods.
-
#backward_fill(limit: nil) ⇒ Series
Fill missing values with the next non-null value.
-
#bin ⇒ BinaryNameSpace
Create an object namespace of all binary related methods.
-
#bitwise_and ⇒ Object
Perform an aggregation of bitwise ANDs.
-
#bitwise_count_ones ⇒ Series
Evaluate the number of set bits.
-
#bitwise_count_zeros ⇒ Series
Evaluate the number of unset bits.
-
#bitwise_leading_ones ⇒ Series
Evaluate the number most-significant set bits before seeing an unset bit.
-
#bitwise_leading_zeros ⇒ Series
Evaluate the number most-significant unset bits before seeing a set bit.
-
#bitwise_or ⇒ Object
Perform an aggregation of bitwise ORs.
-
#bitwise_trailing_ones ⇒ Series
Evaluate the number least-significant set bits before seeing an unset bit.
-
#bitwise_trailing_zeros ⇒ Series
Evaluate the number least-significant unset bits before seeing a set bit.
-
#bitwise_xor ⇒ Object
Perform an aggregation of bitwise XORs.
-
#bottom_k(k: 5) ⇒ Boolean
Return the
ksmallest elements. -
#bottom_k_by(by, k: 5, reverse: false) ⇒ Series
Return the
ksmallest elements of thebycolumn. -
#cast(dtype, strict: true, wrap_numerical: false) ⇒ Series
Cast between data types.
-
#cat ⇒ CatNameSpace
Create an object namespace of all categorical related methods.
-
#cbrt ⇒ Series
Compute the cube root of the elements.
-
#ceil ⇒ Series
Rounds up to the nearest integer value.
-
#chunk_lengths ⇒ Array
Get the length of each individual chunk.
-
#clear(n: 0) ⇒ Series
Create an empty copy of the current Series.
-
#clip(lower_bound = nil, upper_bound = nil) ⇒ Series
Set values outside the given boundaries to the boundary value.
-
#cos ⇒ Series
Compute the element-wise value for the cosine.
-
#cosh ⇒ Series
Compute the element-wise value for the hyperbolic cosine.
-
#cot ⇒ Series
Compute the element-wise value for the cotangent.
-
#count ⇒ Integer
Return the number of elements in the Series.
-
#cum_count(reverse: false) ⇒ Series
Return the cumulative count of the non-null values in the column.
-
#cum_max(reverse: false) ⇒ Series
Get an array with the cumulative max computed at every element.
-
#cum_min(reverse: false) ⇒ Series
Get an array with the cumulative min computed at every element.
-
#cum_prod(reverse: false) ⇒ Series
Get an array with the cumulative product computed at every element.
-
#cum_sum(reverse: false) ⇒ Series
Get an array with the cumulative sum computed at every element.
-
#cumulative_eval(expr, min_samples: 1) ⇒ Series
Run an expression over a sliding window that increases
1slot every iteration. -
#cut(breaks, labels: nil, left_closed: false, include_breaks: false) ⇒ Series
Bin continuous values into discrete categories.
-
#describe(percentiles: [0.25, 0.5, 0.75], interpolation: "nearest") ⇒ DataFrame
Quick summary statistics of a series.
-
#diff(n: 1, null_behavior: "ignore") ⇒ Series
Calculate the n-th discrete difference.
-
#dot(other) ⇒ Numeric
Compute the dot/inner product between two Series.
-
#drop_nans ⇒ Series
Drop NaN values.
-
#drop_nulls ⇒ Series
Create a new Series that copies data from this Series without null values.
-
#dt ⇒ DateTimeNameSpace
Create an object namespace of all datetime related methods.
-
#dtype ⇒ Symbol
Get the data type of this Series.
-
#each ⇒ Object
Returns an enumerator.
-
#entropy(base: Math::E, normalize: true) ⇒ Float?
Computes the entropy.
-
#eq(other) ⇒ Series
Method equivalent of operator expression
series == other. -
#eq_missing(other) ⇒ Object
Method equivalent of equality operator
series == otherwherenil == nil. -
#equals(other, check_dtypes: false, check_names: false, null_equal: true) ⇒ Boolean
Check if series is equal with another Series.
-
#estimated_size(unit = "b") ⇒ Numeric
Return an estimation of the total (heap) allocated size of the Series.
-
#ewm_mean(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, min_samples: 1, ignore_nulls: false) ⇒ Series
Exponentially-weighted moving average.
-
#ewm_mean_by(by, half_life:) ⇒ Series
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) ⇒ Series
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) ⇒ Series
Exponentially-weighted moving variance.
-
#exp ⇒ Series
Compute the exponential, element-wise.
-
#explode(empty_as_null: true, keep_nulls: true) ⇒ Series
Explode a list or utf8 Series.
-
#ext ⇒ ExtensionNameSpace
Create an object namespace of all extension type related methods.
-
#extend(other) ⇒ Series
Extend the memory backed by this Series with the values from another.
-
#extend_constant(value, n) ⇒ Series
Extend the Series with given number of values.
-
#fill_nan(value) ⇒ Series
Fill floating point NaN value with a fill value.
-
#fill_null(value = nil, strategy: nil, limit: nil) ⇒ Series
Fill null values using the specified value or strategy.
-
#filter(predicate) ⇒ Series
Filter elements by a boolean mask.
-
#first(ignore_nulls: false) ⇒ Object
Get the first element of the Series.
-
#flags ⇒ Hash
Get flags that are set on the Series.
-
#floor ⇒ Series
Rounds down to the nearest integer value.
-
#forward_fill(limit: nil) ⇒ Series
Fill missing values with the next non-null value.
-
#gather(indices, null_on_oob: false) ⇒ Series
Take values by index.
-
#gather_every(n, offset = 0) ⇒ Series
Take every nth value in the Series and return as new Series.
-
#ge(other) ⇒ Series
Method equivalent of operator expression
series >= other. -
#get_chunks ⇒ Array
Get the chunks of this Series as a list of Series.
-
#gt(other) ⇒ Series
Method equivalent of operator expression
series > other. -
#has_nulls ⇒ Boolean
Return
trueif the Series has a validity bitmask. -
#hash_(seed = 0, seed_1 = nil, seed_2 = nil, seed_3 = nil) ⇒ Series
Hash the Series.
-
#head(n = 10) ⇒ Series
Get the first
nrows. -
#hist(bins: nil, bin_count: nil, include_category: true, include_breakpoint: true) ⇒ DataFrame
Bin values into buckets and count their occurrences.
-
#implode ⇒ Series
Aggregate values into a list.
-
#index_of(element) ⇒ Object
Get the index of the first occurrence of a value, or
nilif it's not found. -
#initialize(name = nil, values = nil, dtype: nil, strict: true, nan_to_null: false) ⇒ Series
constructor
Create a new Series.
-
#interpolate(method: "linear") ⇒ Series
Interpolate intermediate values.
-
#interpolate_by(by) ⇒ Series
Fill null values using interpolation based on another column.
-
#is_between(lower_bound, upper_bound, closed: "both") ⇒ Series
Get a boolean mask of the values that are between the given lower/upper bounds.
-
#is_close(other, abs_tol: 0.0, rel_tol: 1.0e-09, nans_equal: false) ⇒ Series
Get a boolean mask of the values being close to the other values.
-
#is_duplicated ⇒ Series
Get mask of all duplicated values.
-
#is_empty(ignore_nulls: false) ⇒ Boolean
(also: #empty?)
Check if the Series is empty.
-
#is_finite ⇒ Series
Returns a boolean Series indicating which values are finite.
-
#is_first_distinct ⇒ Series
Get a mask of the first unique value.
-
#is_in(other, nulls_equal: false) ⇒ Series
(also: #in?)
Check if elements of this Series are in the other Series.
-
#is_infinite ⇒ Series
Returns a boolean Series indicating which values are infinite.
-
#is_last_distinct ⇒ Series
Return a boolean mask indicating the last occurrence of each distinct value.
-
#is_nan ⇒ Series
Returns a boolean Series indicating which values are NaN.
-
#is_not_nan ⇒ Series
Returns a boolean Series indicating which values are not NaN.
-
#is_not_null ⇒ Series
Returns a boolean Series indicating which values are not null.
-
#is_null ⇒ Series
Returns a boolean Series indicating which values are null.
-
#is_sorted(descending: false, nulls_last: false) ⇒ Boolean
(also: #sorted?)
Check if the Series is sorted.
-
#is_unique ⇒ Series
Get mask of all unique values.
-
#item(index = nil) ⇒ Object
Return the Series as a scalar, or return the element at the given index.
-
#kurtosis(fisher: true, bias: true) ⇒ Float?
Compute the kurtosis (Fisher or Pearson) of a dataset.
-
#last(ignore_nulls: false) ⇒ Object
Get the last element of the Series.
-
#le(other) ⇒ Series
Method equivalent of operator expression
series <= other. -
#len ⇒ Integer
(also: #length, #size)
Return the number of elements in the Series.
-
#limit(n = 10) ⇒ Series
Get the first
nrows. -
#list ⇒ ListNameSpace
Create an object namespace of all list related methods.
-
#log(base = Math::E) ⇒ Series
Compute the logarithm to a given base.
-
#log10 ⇒ Series
Compute the base 10 logarithm of the input array, element-wise.
-
#log1p ⇒ Series
Compute the natural logarithm of the input array plus one, element-wise.
-
#lower_bound ⇒ Series
Return the lower bound of this Series' dtype as a unit Series.
-
#lt(other) ⇒ Series
Method equivalent of operator expression
series < other. -
#map_elements(return_dtype: nil, skip_nulls: true, &function) ⇒ Series
(also: #map)
Apply a custom/user-defined function (UDF) over elements in this Series and return a new Series.
-
#max ⇒ Object
Get the maximum value in this Series.
-
#max_by(by) ⇒ Object
Get the maximum value in this Series, ordered by an expression.
-
#mean ⇒ Float?
Reduce this Series to the mean value.
-
#median ⇒ Float?
Get the median of this Series.
-
#min ⇒ Object
Get the minimal value in this Series.
-
#min_by(by) ⇒ Expr
Get the minimum value in this Series, ordered by an expression.
-
#mode(maintain_order: false) ⇒ Series
Compute the most occurring value(s).
-
#n_chunks ⇒ Integer
Get the number of chunks that this Series contains.
-
#n_unique ⇒ Integer
Count the number of unique values in this Series.
-
#name ⇒ String
Get the name of this Series.
-
#nan_max ⇒ Object
Get maximum value, but propagate/poison encountered NaN values.
-
#nan_min ⇒ Object
Get minimum value, but propagate/poison encountered NaN values.
-
#ne(other) ⇒ Series
Method equivalent of operator expression
series != other. -
#ne_missing(other) ⇒ Object
Method equivalent of equality operator
series != otherwherenil == nil. -
#new_from_index(index, length) ⇒ Series
Create a new Series filled with values from the given index.
-
#none?(&block) ⇒ Boolean
(also: #none)
Check if all boolean values in the column are
false. -
#not_ ⇒ Series
Negate a boolean Series.
-
#null_count ⇒ Integer
Count the null values in this Series.
-
#pct_change(n: 1) ⇒ Series
Computes percentage change between values.
-
#peak_max ⇒ Series
Get a boolean mask of the local maximum peaks.
-
#peak_min ⇒ Series
Get a boolean mask of the local minimum peaks.
-
#plot ⇒ SeriesPlot
Create a plot namespace.
-
#pow(exponent) ⇒ Series
Raise to the power of the given exponent.
-
#product ⇒ Numeric
Reduce this Series to the product value.
-
#qcut(quantiles, labels: nil, left_closed: false, allow_duplicates: false, include_breaks: false) ⇒ Series
Bin continuous values into discrete categories based on their quantiles.
-
#quantile(quantile, interpolation: "nearest") ⇒ Float?
Get the quantile value of this Series.
-
#rank(method: "average", descending: false, seed: nil) ⇒ Series
Assign ranks to data, dealing with ties appropriately.
-
#rechunk(in_place: false) ⇒ Series
Create a single chunk of memory for this Series.
-
#reinterpret(signed: nil, dtype: nil) ⇒ Series
Reinterpret the underlying bits as a signed/unsigned integer or float.
-
#rename(name) ⇒ Series
Rename this Series.
-
#repeat_by(by) ⇒ Object
Repeat the elements in this Series as specified in the given expression.
-
#replace(old, new = NO_DEFAULT, default: NO_DEFAULT, return_dtype: nil) ⇒ Series
Replace values by different values.
-
#replace_strict(old, new = NO_DEFAULT, default: NO_DEFAULT, return_dtype: nil) ⇒ Series
Replace all values by different values.
-
#reshape(dimensions) ⇒ Series
Reshape this Series to a flat Series or a Series of Lists.
-
#reverse ⇒ Series
Return Series in reverse order.
-
#rle ⇒ Series
Get the lengths of runs of identical values.
-
#rle_id ⇒ Series
Map values to run IDs.
-
#rolling_kurtosis(window_size, fisher: true, bias: true, min_samples: nil, center: false) ⇒ Series
Compute a rolling kurtosis.
-
#rolling_map(window_size, weights: nil, min_samples: nil, center: false, &function) ⇒ Series
Compute a custom rolling window function.
-
#rolling_max(window_size, weights: nil, min_samples: nil, center: false) ⇒ Series
Apply a rolling max (moving max) over the values in this array.
-
#rolling_max_by(by, window_size, min_samples: 1, closed: "right") ⇒ Series
Compute a rolling max based on another series.
-
#rolling_mean(window_size, weights: nil, min_samples: nil, center: false) ⇒ Series
Apply a rolling mean (moving mean) over the values in this array.
-
#rolling_mean_by(by, window_size, min_samples: 1, closed: "right") ⇒ Series
Compute a rolling mean based on another series.
-
#rolling_median(window_size, weights: nil, min_samples: nil, center: false) ⇒ Series
Compute a rolling median.
-
#rolling_median_by(by, window_size, min_samples: 1, closed: "right") ⇒ Series
Compute a rolling median based on another series.
-
#rolling_min(window_size, weights: nil, min_samples: nil, center: false) ⇒ Series
Apply a rolling min (moving min) over the values in this array.
-
#rolling_min_by(by, window_size, min_samples: 1, closed: "right") ⇒ Series
Compute a rolling min based on another series.
-
#rolling_quantile(quantile, interpolation: "nearest", window_size: 2, weights: nil, min_samples: nil, center: false) ⇒ Series
Compute a rolling quantile.
-
#rolling_quantile_by(by, window_size, quantile:, interpolation: "nearest", min_samples: 1, closed: "right") ⇒ Series
Compute a rolling quantile based on another series.
-
#rolling_rank(window_size, method: "average", seed: nil, min_samples: nil, center: false) ⇒ Series
Compute a rolling rank.
-
#rolling_rank_by(by, window_size, method: "average", seed: nil, min_samples: 1, closed: "right") ⇒ Series
Compute a rolling rank based on another column.
-
#rolling_skew(window_size, bias: true, min_samples: nil, center: false) ⇒ Series
Compute a rolling skew.
-
#rolling_std(window_size, weights: nil, min_samples: nil, center: false, ddof: 1) ⇒ Series
Compute a rolling std dev.
-
#rolling_std_by(by, window_size, min_samples: 1, closed: "right", ddof: 1) ⇒ Series
Compute a rolling standard deviation based on another series.
-
#rolling_sum(window_size, weights: nil, min_samples: nil, center: false) ⇒ Series
Apply a rolling sum (moving sum) over the values in this array.
-
#rolling_sum_by(by, window_size, min_samples: 0, closed: "right") ⇒ Series
Compute a rolling sum based on another series.
-
#rolling_var(window_size, weights: nil, min_samples: nil, center: false, ddof: 1) ⇒ Series
Compute a rolling variance.
-
#rolling_var_by(by, window_size, min_samples: 1, closed: "right", ddof: 1) ⇒ Series
Compute a rolling variance based on another series.
-
#round(decimals = 0, mode: "half_to_even") ⇒ Series
Round underlying floating point data by
decimalsdigits. -
#round_sig_figs(digits) ⇒ Series
Round to a number of significant figures.
-
#sample(n: nil, fraction: nil, with_replacement: false, shuffle: false, seed: nil) ⇒ Series
Sample from this Series.
-
#scatter(indices, values) ⇒ Series
Set values at the index locations.
-
#search_sorted(element, side: "any", descending: false) ⇒ Integer
Find indices where elements should be inserted to maintain order.
-
#set(filter, value) ⇒ Series
Set masked values.
-
#set_sorted(descending: false) ⇒ Series
Flags the Series as sorted.
-
#shape ⇒ Array
Shape of this Series.
-
#shift(n = 1, fill_value: nil) ⇒ Series
Shift the values by a given period.
-
#shrink_dtype ⇒ Series
Shrink numeric columns to the minimal required datatype.
-
#shrink_to_fit(in_place: false) ⇒ Series
Shrink Series memory usage.
-
#shuffle(seed: nil) ⇒ Series
Shuffle the contents of this Series.
-
#sign ⇒ Series
Compute the element-wise indication of the sign.
-
#sin ⇒ Series
Compute the element-wise value for the sine.
-
#sinh ⇒ Series
Compute the element-wise value for the hyperbolic sine.
-
#skew(bias: true) ⇒ Float?
Compute the sample skewness of a data set.
-
#slice(offset, length = nil) ⇒ Series
Get a slice of this Series.
-
#sort(descending: false, nulls_last: false, multithreaded: true, in_place: false) ⇒ Series
Sort this Series.
-
#sql(query, table_name: "self") ⇒ DataFrame
Execute a SQL query against the Series.
-
#sqrt ⇒ Series
Compute the square root of the elements.
-
#std(ddof: 1) ⇒ Float?
Get the standard deviation of this Series.
-
#str ⇒ StringNameSpace
Create an object namespace of all string related methods.
-
#struct ⇒ StructNameSpace
Create an object namespace of all struct related methods.
-
#sum ⇒ Numeric
Reduce this Series to the sum value.
-
#tail(n = 10) ⇒ Series
Get the last
nrows. -
#tan ⇒ Series
Compute the element-wise value for the tangent.
-
#tanh ⇒ Series
Compute the element-wise value for the hyperbolic tangent.
-
#to_a ⇒ Array
Convert this Series to a Ruby Array.
-
#to_dummies(separator: "_", drop_first: false, drop_nulls: false) ⇒ DataFrame
Get dummy variables.
-
#to_frame(name = nil) ⇒ DataFrame
Cast this Series to a DataFrame.
-
#to_numo ⇒ Numo::NArray
Convert this Series to a Numo array.
-
#to_physical ⇒ Series
Cast to physical representation of the logical dtype.
-
#to_s ⇒ String
(also: #inspect)
Returns a string representing the Series.
-
#top_k(k: 5) ⇒ Boolean
Return the
klargest elements. -
#top_k_by(by, k: 5, reverse: false) ⇒ Series
Return the
klargest elements of thebycolumn. -
#truncate(decimals = 0) ⇒ Series
Truncate numeric data toward zero to
decimalsnumber of decimal places. -
#unique(maintain_order: false) ⇒ Series
(also: #uniq)
Get unique elements in series.
-
#unique_counts ⇒ Series
Return a count of the unique values in the order of appearance.
-
#upper_bound ⇒ Series
Return the upper bound of this Series' dtype as a unit Series.
-
#value_counts(sort: false, parallel: false, name: nil, normalize: false) ⇒ DataFrame
Count the unique values in a Series.
-
#var(ddof: 1) ⇒ Float?
Get variance of this Series.
-
#zip_with(mask, other) ⇒ Series
Take values from self or other based on the given mask.
-
#|(other) ⇒ Series
Bitwise OR.
Constructor Details
#initialize(name = nil, values = nil, dtype: nil, strict: true, nan_to_null: false) ⇒ Series
Create a new Series.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/polars/series.rb', line 32 def initialize(name = nil, values = nil, dtype: nil, strict: true, nan_to_null: false) # If 'Unknown' treat as nil to trigger type inference if dtype == Unknown dtype = nil elsif !dtype.nil? && !Utils.is_polars_dtype(dtype) dtype = Utils.parse_into_dtype(dtype) end # Handle case where values are passed as the first argument original_name = nil if name.nil? name = "" elsif name.is_a?(::String) original_name = name else if values.nil? values = name name = "" else raise TypeError, "Series name must be a string" end end if values.is_a?(::Array) || values.is_a?(Range) self._s = Utils.sequence_to_rbseries( name, values, dtype: dtype, strict: strict ) elsif values.nil? self._s = Utils.sequence_to_rbseries(name, [], dtype: dtype) elsif defined?(Numo::NArray) && values.is_a?(Numo::NArray) self._s = Utils.numo_to_rbseries(name, values, strict: strict, nan_to_null: nan_to_null) if !dtype.nil? self._s = cast(dtype, strict: strict)._s end elsif values.is_a?(Series) self._s = Utils.series_to_rbseries(original_name, values, dtype: dtype, strict: strict) elsif values.is_a?(DataFrame) self._s = Utils.dataframe_to_rbseries( original_name, values, dtype: dtype, strict: strict ) else raise TypeError, "Series constructor called with unsupported type; got #{values.class.name}" end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Polars::ExprDispatch
Instance Method Details
#! ⇒ Series
Performs boolean not.
408 409 410 411 412 413 |
# File 'lib/polars/series.rb', line 408 def ! if dtype == Boolean return Utils.wrap_s(_s.not_) end raise NotImplementedError end |
#!=(other) ⇒ Series
Not equal.
191 192 193 |
# File 'lib/polars/series.rb', line 191 def !=(other) _comp(other, :neq) end |
#%(other) ⇒ Series
Returns the modulo.
388 389 390 391 392 393 |
# File 'lib/polars/series.rb', line 388 def %(other) if dtype.temporal? raise ArgumentError, "first cast to integer before applying modulo on datelike dtypes" end _arithmetic(other, :rem) end |
#&(other) ⇒ Series
Bitwise AND.
154 155 156 157 158 159 |
# File 'lib/polars/series.rb', line 154 def &(other) if !other.is_a?(Series) other = Series.new([other]) end Utils.wrap_s(_s.bitand(other._s)) end |
#*(other) ⇒ Series
Performs multiplication.
360 361 362 363 364 365 366 367 368 |
# File 'lib/polars/series.rb', line 360 def *(other) if dtype.temporal? raise ArgumentError, "first cast to integer before multiplying datelike dtypes" elsif other.is_a?(DataFrame) other * self else _arithmetic(other, :mul) end end |
#**(power) ⇒ Series
Raises to the power of exponent.
398 399 400 401 402 403 |
# File 'lib/polars/series.rb', line 398 def **(power) if dtype.temporal? raise ArgumentError, "first cast to integer before raising datelike dtypes to a power" end to_frame.select(Polars.col(name).pow(power)).to_series end |
#+(other) ⇒ Series
Performs addition.
346 347 348 |
# File 'lib/polars/series.rb', line 346 def +(other) _arithmetic(other, :add) end |
#-(other) ⇒ Series
Performs subtraction.
353 354 355 |
# File 'lib/polars/series.rb', line 353 def -(other) _arithmetic(other, :sub) end |
#-@ ⇒ Series
Performs negation.
418 419 420 |
# File 'lib/polars/series.rb', line 418 def -@ 0 - self end |
#/(other) ⇒ Series
Performs division.
373 374 375 376 377 378 379 380 381 382 383 |
# File 'lib/polars/series.rb', line 373 def /(other) if dtype.temporal? raise ArgumentError, "first cast to integer before dividing datelike dtypes" end if dtype.float? return _arithmetic(other, :div) end cast(Float64) / other end |
#<(other) ⇒ Series
Less than.
205 206 207 |
# File 'lib/polars/series.rb', line 205 def <(other) _comp(other, :lt) end |
#<=(other) ⇒ Series
Less than or equal.
219 220 221 |
# File 'lib/polars/series.rb', line 219 def <=(other) _comp(other, :lt_eq) end |
#==(other) ⇒ Series
Equal.
184 185 186 |
# File 'lib/polars/series.rb', line 184 def ==(other) _comp(other, :eq) end |
#>(other) ⇒ Series
Greater than.
198 199 200 |
# File 'lib/polars/series.rb', line 198 def >(other) _comp(other, :gt) end |
#>=(other) ⇒ Series
Greater than or equal.
212 213 214 |
# File 'lib/polars/series.rb', line 212 def >=(other) _comp(other, :gt_eq) end |
#[](item) ⇒ Object
Returns elements of the Series.
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
# File 'lib/polars/series.rb', line 436 def [](item) if item.is_a?(Series) && [UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64].include?(item.dtype) return Utils.wrap_s(_s.gather_with_series(_pos_idxs(item)._s)) end if item.is_a?(Series) && item.bool? return filter(item) end if item.is_a?(Integer) if item < 0 item = len + item end return _s.get_index(item) end if item.is_a?(Range) return Slice.new(self).apply(item) end if Utils.is_int_sequence(item) return Utils.wrap_s(_s.gather_with_series(_pos_idxs(Series.new("", item))._s)) end raise ArgumentError, "Cannot get item of type: #{item.class.name}" end |
#[]=(key, value) ⇒ Object
Sets an element of the Series.
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
# File 'lib/polars/series.rb', line 467 def []=(key, value) if value.is_a?(::Array) if dtype.numeric? || dtype.temporal? scatter(key, value) return end raise ArgumentError, "cannot set Series of dtype: #{dtype} with list/tuple as value; use a scalar value" end if key.is_a?(Series) if key.dtype == Boolean self._s = set(key, value)._s elsif key.dtype == UInt64 self._s = scatter(key.cast(UInt32), value)._s elsif key.dtype == UInt32 self._s = scatter(key, value)._s else raise Todo end elsif key.is_a?(::Array) s = Utils.wrap_s(Utils.sequence_to_rbseries("", key, dtype: UInt32)) self[s] = value elsif key.is_a?(Range) s = Series.new("", key, dtype: UInt32) self[s] = value elsif key.is_a?(Integer) self[[key]] = value else raise ArgumentError, "cannot use #{key} for indexing" end end |
#^(other) ⇒ Series
Bitwise XOR.
174 175 176 177 178 179 |
# File 'lib/polars/series.rb', line 174 def ^(other) if !other.is_a?(Series) other = Series.new([other]) end Utils.wrap_s(_s.bitxor(other._s)) end |
#abs ⇒ Series
Compute absolute values.
5456 5457 5458 |
# File 'lib/polars/series.rb', line 5456 def abs super end |
#alias(name) ⇒ Series
Return a copy of the Series with a new alias/name.
1575 1576 1577 1578 1579 |
# File 'lib/polars/series.rb', line 1575 def alias(name) s = dup s._s.rename(name) s end |
#all?(ignore_nulls: true, &block) ⇒ Boolean Also known as: all
Check if all boolean values in the column are true.
638 639 640 641 642 643 644 |
# File 'lib/polars/series.rb', line 638 def all?(ignore_nulls: true, &block) if block_given? map_elements(return_dtype: Boolean, skip_nulls: ignore_nulls, &block).all? else _s.all(ignore_nulls) end end |
#any?(ignore_nulls: true, &block) ⇒ Boolean Also known as: any
Check if any boolean value in the column is true.
614 615 616 617 618 619 620 |
# File 'lib/polars/series.rb', line 614 def any?(ignore_nulls: true, &block) if block_given? map_elements(return_dtype: Boolean, skip_nulls: ignore_nulls, &block).any? else _s.any(ignore_nulls) end end |
#append(other) ⇒ Series
Append a Series to this one.
1806 1807 1808 1809 1810 |
# File 'lib/polars/series.rb', line 1806 def append(other) Utils.require_same_type(self, other) _s.append(other._s) self end |
#approx_n_unique ⇒ Object
Approximate count of unique values.
This is done using the HyperLogLog++ algorithm for cardinality estimation.
6380 6381 6382 |
# File 'lib/polars/series.rb', line 6380 def approx_n_unique _s.approx_n_unique end |
#arccos ⇒ Series
Compute the element-wise value for the inverse cosine.
3671 3672 3673 |
# File 'lib/polars/series.rb', line 3671 def arccos super end |
#arccosh ⇒ Series
Compute the element-wise value for the inverse hyperbolic cosine.
3729 3730 3731 |
# File 'lib/polars/series.rb', line 3729 def arccosh super end |
#arcsin ⇒ Series
Compute the element-wise value for the inverse sine.
3652 3653 3654 |
# File 'lib/polars/series.rb', line 3652 def arcsin super end |
#arcsinh ⇒ Series
Compute the element-wise value for the inverse hyperbolic sine.
3709 3710 3711 |
# File 'lib/polars/series.rb', line 3709 def arcsinh super end |
#arctan ⇒ Series
Compute the element-wise value for the inverse tangent.
3690 3691 3692 |
# File 'lib/polars/series.rb', line 3690 def arctan super end |
#arctanh ⇒ Series
Compute the element-wise value for the inverse hyperbolic tangent.
3752 3753 3754 |
# File 'lib/polars/series.rb', line 3752 def arctanh super end |
#arg_max ⇒ Integer?
Get the index of the maximal value.
2290 2291 2292 |
# File 'lib/polars/series.rb', line 2290 def arg_max _s.arg_max end |
#arg_min ⇒ Integer?
Get the index of the minimal value.
2278 2279 2280 |
# File 'lib/polars/series.rb', line 2278 def arg_min _s.arg_min end |
#arg_sort(descending: false, nulls_last: false) ⇒ Series
Get the index values that would sort this Series.
2247 2248 2249 |
# File 'lib/polars/series.rb', line 2247 def arg_sort(descending: false, nulls_last: false) super end |
#arg_true ⇒ Series
Get index values where Boolean Series evaluate true.
2704 2705 2706 |
# File 'lib/polars/series.rb', line 2704 def arg_true Polars.arg_where(self, eager: true) end |
#arg_unique ⇒ Series
Get unique index as Series.
2266 2267 2268 |
# File 'lib/polars/series.rb', line 2266 def arg_unique super end |
#arr ⇒ ArrayNameSpace
Create an object namespace of all array related methods.
6394 6395 6396 |
# File 'lib/polars/series.rb', line 6394 def arr ArrayNameSpace.new(self) end |
#backward_fill(limit: nil) ⇒ Series
Fill missing values with the next non-null value.
This is an alias of .fill_null(strategy: "backward").
3344 3345 3346 |
# File 'lib/polars/series.rb', line 3344 def backward_fill(limit: nil) fill_null(strategy: "backward", limit: limit) end |
#bin ⇒ BinaryNameSpace
Create an object namespace of all binary related methods.
6401 6402 6403 |
# File 'lib/polars/series.rb', line 6401 def bin BinaryNameSpace.new(self) end |
#bitwise_and ⇒ Object
Perform an aggregation of bitwise ANDs.
6329 6330 6331 |
# File 'lib/polars/series.rb', line 6329 def bitwise_and _s.bitwise_and end |
#bitwise_count_ones ⇒ Series
Evaluate the number of set bits.
6287 6288 6289 |
# File 'lib/polars/series.rb', line 6287 def bitwise_count_ones super end |
#bitwise_count_zeros ⇒ Series
Evaluate the number of unset bits.
6294 6295 6296 |
# File 'lib/polars/series.rb', line 6294 def bitwise_count_zeros super end |
#bitwise_leading_ones ⇒ Series
Evaluate the number most-significant set bits before seeing an unset bit.
6301 6302 6303 |
# File 'lib/polars/series.rb', line 6301 def bitwise_leading_ones super end |
#bitwise_leading_zeros ⇒ Series
Evaluate the number most-significant unset bits before seeing a set bit.
6308 6309 6310 |
# File 'lib/polars/series.rb', line 6308 def bitwise_leading_zeros super end |
#bitwise_or ⇒ Object
Perform an aggregation of bitwise ORs.
6336 6337 6338 |
# File 'lib/polars/series.rb', line 6336 def bitwise_or _s.bitwise_or end |
#bitwise_trailing_ones ⇒ Series
Evaluate the number least-significant set bits before seeing an unset bit.
6315 6316 6317 |
# File 'lib/polars/series.rb', line 6315 def bitwise_trailing_ones super end |
#bitwise_trailing_zeros ⇒ Series
Evaluate the number least-significant unset bits before seeing a set bit.
6322 6323 6324 |
# File 'lib/polars/series.rb', line 6322 def bitwise_trailing_zeros super end |
#bitwise_xor ⇒ Object
Perform an aggregation of bitwise XORs.
6343 6344 6345 |
# File 'lib/polars/series.rb', line 6343 def bitwise_xor _s.bitwise_xor end |
#bottom_k(k: 5) ⇒ Boolean
Return the k smallest elements.
2183 2184 2185 |
# File 'lib/polars/series.rb', line 2183 def bottom_k(k: 5) super end |
#bottom_k_by(by, k: 5, reverse: false) ⇒ Series
Return the k smallest elements of the by column.
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 sort after this function if you wish the
output to be sorted.
2217 2218 2219 2220 2221 2222 2223 |
# File 'lib/polars/series.rb', line 2217 def bottom_k_by( by, k: 5, reverse: false ) super end |
#cast(dtype, strict: true, wrap_numerical: false) ⇒ Series
Cast between data types.
2892 2893 2894 2895 |
# File 'lib/polars/series.rb', line 2892 def cast(dtype, strict: true, wrap_numerical: false) dtype = Utils.parse_into_dtype(dtype) self.class._from_rbseries(_s.cast(dtype, strict, wrap_numerical)) end |
#cat ⇒ CatNameSpace
Create an object namespace of all categorical related methods.
6408 6409 6410 |
# File 'lib/polars/series.rb', line 6408 def cat CatNameSpace.new(self) end |
#cbrt ⇒ Series
Compute the cube root of the elements.
595 596 597 |
# File 'lib/polars/series.rb', line 595 def cbrt super end |
#ceil ⇒ Series
Rounds up to the nearest integer value.
Only works on floating point Series.
3398 3399 3400 |
# File 'lib/polars/series.rb', line 3398 def ceil super end |
#chunk_lengths ⇒ Array
Get the length of each individual chunk.
1618 1619 1620 |
# File 'lib/polars/series.rb', line 1618 def chunk_lengths _s.chunk_lengths end |
#clear(n: 0) ⇒ Series
Create an empty copy of the current Series.
The copy has identical name/dtype but no data.
3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 |
# File 'lib/polars/series.rb', line 3246 def clear(n: 0) if n < 0 msg = "`n` should be greater than or equal to 0, got #{n}" raise ArgumentError, msg end # faster path if n == 0 return self.class._from_rbseries(_s.clear) end s = len > 0 ? self.class.new(name, [], dtype: dtype) : clone n > 0 ? s.extend_constant(nil, n) : s end |
#clip(lower_bound = nil, upper_bound = nil) ⇒ Series
Set values outside the given boundaries to the boundary value.
5697 5698 5699 |
# File 'lib/polars/series.rb', line 5697 def clip(lower_bound = nil, upper_bound = nil) super end |
#cos ⇒ Series
Compute the element-wise value for the cosine.
3595 3596 3597 |
# File 'lib/polars/series.rb', line 3595 def cos super end |
#cosh ⇒ Series
Compute the element-wise value for the hyperbolic cosine.
3790 3791 3792 |
# File 'lib/polars/series.rb', line 3790 def cosh super end |
#cot ⇒ Series
Compute the element-wise value for the cotangent.
3633 3634 3635 |
# File 'lib/polars/series.rb', line 3633 def cot super end |
#count ⇒ Integer
Return the number of elements in the Series.
2851 2852 2853 |
# File 'lib/polars/series.rb', line 2851 def count len - null_count end |
#cum_count(reverse: false) ⇒ Series
Return the cumulative count of the non-null values in the column.
1686 1687 1688 |
# File 'lib/polars/series.rb', line 1686 def cum_count(reverse: false) super end |
#cum_max(reverse: false) ⇒ Series
Get an array with the cumulative max computed at every element.
1730 1731 1732 |
# File 'lib/polars/series.rb', line 1730 def cum_max(reverse: false) super end |
#cum_min(reverse: false) ⇒ Series
Get an array with the cumulative min computed at every element.
1708 1709 1710 |
# File 'lib/polars/series.rb', line 1708 def cum_min(reverse: false) super end |
#cum_prod(reverse: false) ⇒ Series
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.
1756 1757 1758 |
# File 'lib/polars/series.rb', line 1756 def cum_prod(reverse: false) super end |
#cum_sum(reverse: false) ⇒ Series
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.
1663 1664 1665 |
# File 'lib/polars/series.rb', line 1663 def cum_sum(reverse: false) super end |
#cumulative_eval(expr, min_samples: 1) ⇒ Series
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.
1553 1554 1555 |
# File 'lib/polars/series.rb', line 1553 def cumulative_eval(expr, min_samples: 1) super end |
#cut(breaks, labels: nil, left_closed: false, include_breaks: false) ⇒ Series
Bin continuous values into discrete categories.
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 |
# File 'lib/polars/series.rb', line 1212 def cut(breaks, labels: nil, left_closed: false, include_breaks: false) result = ( to_frame .select( Polars.col(name).cut( breaks, labels: labels, left_closed: left_closed, include_breaks: include_breaks ) ) .to_series ) if include_breaks result = result.struct.rename_fields(["break_point", "category"]) end result end |
#describe(percentiles: [0.25, 0.5, 0.75], interpolation: "nearest") ⇒ DataFrame
Quick summary statistics of a series.
Series with mixed datatypes will return summary statistics for the datatype of the first value.
874 875 876 877 878 879 880 881 882 883 884 |
# File 'lib/polars/series.rb', line 874 def describe( percentiles: [0.25, 0.5, 0.75], interpolation: "nearest" ) stats = to_frame.describe( percentiles: percentiles, interpolation: interpolation ) stats.columns = ["statistic", "value"] stats.filter(F.col("value").is_not_null) end |
#diff(n: 1, null_behavior: "ignore") ⇒ Series
Calculate the n-th discrete difference.
5564 5565 5566 |
# File 'lib/polars/series.rb', line 5564 def diff(n: 1, null_behavior: "ignore") super end |
#dot(other) ⇒ Numeric
Compute the dot/inner product between two Series.
3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 |
# File 'lib/polars/series.rb', line 3507 def dot(other) if !other.is_a?(Series) other = Series.new(other) end if len != other.len n, m = len, other.len raise ArgumentError, "Series length mismatch: expected #{n}, found #{m}" end _s.dot(other._s) end |
#drop_nans ⇒ Series
Drop NaN values.
784 785 786 |
# File 'lib/polars/series.rb', line 784 def drop_nans super end |
#drop_nulls ⇒ Series
Create a new Series that copies data from this Series without null values.
765 766 767 |
# File 'lib/polars/series.rb', line 765 def drop_nulls super end |
#dt ⇒ DateTimeNameSpace
Create an object namespace of all datetime related methods.
6415 6416 6417 |
# File 'lib/polars/series.rb', line 6415 def dt DateTimeNameSpace.new(self) end |
#dtype ⇒ Symbol
Get the data type of this Series.
96 97 98 |
# File 'lib/polars/series.rb', line 96 def dtype _s.dtype end |
#each ⇒ Object
Returns an enumerator.
425 426 427 428 429 430 431 |
# File 'lib/polars/series.rb', line 425 def each return to_enum(:each) unless block_given? length.times do |i| yield self[i] end end |
#entropy(base: Math::E, normalize: true) ⇒ Float?
Computes the entropy.
Uses the formula -sum(pk * log(pk) where pk are discrete probabilities.
1518 1519 1520 |
# File 'lib/polars/series.rb', line 1518 def entropy(base: Math::E, normalize: true) Polars.select(Polars.lit(self).entropy(base: base, normalize: normalize)).to_series[0] end |
#eq(other) ⇒ Series
Method equivalent of operator expression series == other.
240 241 242 |
# File 'lib/polars/series.rb', line 240 def eq(other) self == other end |
#eq_missing(other) ⇒ Object
Method equivalent of equality operator series == other where nil == nil.
This differs from the standard ne where null values are propagated.
276 277 278 279 280 281 |
# File 'lib/polars/series.rb', line 276 def eq_missing(other) if other.is_a?(Expr) return Polars.lit(self).eq_missing(other) end to_frame.select(Polars.col(name).eq_missing(other)).to_series end |
#equals(other, check_dtypes: false, check_names: false, null_equal: true) ⇒ Boolean
Check if series is equal with another Series.
2839 2840 2841 |
# File 'lib/polars/series.rb', line 2839 def equals(other, check_dtypes: false, check_names: false, null_equal: true) _s.equals(other._s, check_dtypes, check_names, null_equal) end |
#estimated_size(unit = "b") ⇒ Numeric
Return an estimation of the total (heap) allocated size of the Series.
Estimated size is given in the specified unit (bytes by default).
This estimation is the sum of the size of its buffers, validity, including nested arrays. Multiple arrays may share buffers and bitmaps. Therefore, the size of 2 arrays is not the sum of the sizes computed from this function. In particular, StructArray's size is an upper bound.
When an array is sliced, its allocated size remains constant because the buffer unchanged. However, this function will yield a smaller number. This is because this function returns the visible size of the buffer, not its total capacity.
FFI buffers are included in this estimation.
556 557 558 559 |
# File 'lib/polars/series.rb', line 556 def estimated_size(unit = "b") sz = _s.estimated_size Utils.scale_bytes(sz, to: unit) end |
#ewm_mean(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, min_samples: 1, ignore_nulls: false) ⇒ Series
Exponentially-weighted moving average.
6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 |
# File 'lib/polars/series.rb', line 6018 def ewm_mean( com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, min_samples: 1, ignore_nulls: false ) super end |
#ewm_mean_by(by, half_life:) ⇒ Series
Compute time-based exponentially weighted moving average.
6085 6086 6087 6088 6089 6090 |
# File 'lib/polars/series.rb', line 6085 def ewm_mean_by( by, half_life: ) super end |
#ewm_std(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_samples: 1, ignore_nulls: false) ⇒ Series
Exponentially-weighted moving standard deviation.
6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 |
# File 'lib/polars/series.rb', line 6107 def ewm_std( com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_samples: 1, ignore_nulls: false ) super end |
#ewm_var(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_samples: 1, ignore_nulls: false) ⇒ Series
Exponentially-weighted moving variance.
6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 |
# File 'lib/polars/series.rb', line 6135 def ewm_var( com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_samples: 1, ignore_nulls: false ) super end |
#exp ⇒ Series
Compute the exponential, element-wise.
746 747 748 |
# File 'lib/polars/series.rb', line 746 def exp super end |
#explode(empty_as_null: true, keep_nulls: true) ⇒ Series
Explode a list or utf8 Series.
This means that every item is expanded to a new row.
2815 2816 2817 |
# File 'lib/polars/series.rb', line 2815 def explode(empty_as_null: true, keep_nulls: true) super end |
#ext ⇒ ExtensionNameSpace
Create an object namespace of all extension type related methods.
6436 6437 6438 |
# File 'lib/polars/series.rb', line 6436 def ext ExtensionNameSpace.new(self) end |
#extend(other) ⇒ Series
This method modifies the series in-place. The series is returned for convenience only.
Extend the memory backed by this Series with the values from another.
Different from append, which adds the chunks from other to the chunks of
this series, extend appends the data from other to the underlying memory
locations and thus may cause a reallocation (which is expensive).
If this does not cause a reallocation, the resulting data structure will not
have any extra chunks and thus will yield faster queries.
Prefer extend over append when you want to do a query after a single
append. For instance, during online operations where you add n rows
and rerun a query.
Prefer append over extend when you want to append many times
before doing a query. For instance, when you read in multiple files and want
to store them in a single Series. In the latter case, finish the sequence
of append operations with a rechunk.
1857 1858 1859 1860 1861 |
# File 'lib/polars/series.rb', line 1857 def extend(other) Utils.require_same_type(self, other) _s.extend(other._s) self end |
#extend_constant(value, n) ⇒ Series
Extend the Series with given number of values.
6171 6172 6173 |
# File 'lib/polars/series.rb', line 6171 def extend_constant(value, n) super end |
#fill_nan(value) ⇒ Series
Fill floating point NaN value with a fill value.
3280 3281 3282 |
# File 'lib/polars/series.rb', line 3280 def fill_nan(value) super end |
#fill_null(value = nil, strategy: nil, limit: nil) ⇒ Series
Fill null values using the specified value or strategy.
3332 3333 3334 |
# File 'lib/polars/series.rb', line 3332 def fill_null(value = nil, strategy: nil, limit: nil) super end |
#filter(predicate) ⇒ Series
Filter elements by a boolean mask.
1881 1882 1883 1884 1885 1886 |
# File 'lib/polars/series.rb', line 1881 def filter(predicate) if predicate.is_a?(::Array) predicate = Series.new("", predicate) end Utils.wrap_s(_s.filter(predicate._s)) end |
#first(ignore_nulls: false) ⇒ Object
Get the first element of the Series.
Returns nil if the Series is empty.
6357 6358 6359 |
# File 'lib/polars/series.rb', line 6357 def first(ignore_nulls: false) _s.first(ignore_nulls) end |
#flags ⇒ Hash
Get flags that are set on the Series.
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/polars/series.rb', line 108 def flags out = { "SORTED_ASC" => _s.is_sorted_flag, "SORTED_DESC" => _s.is_sorted_reverse_flag } if dtype.is_a?(List) out["FAST_EXPLODE"] = _s.can_fast_explode_flag end out end |
#floor ⇒ Series
Rounds down to the nearest integer value.
Only works on floating point Series.
3377 3378 3379 |
# File 'lib/polars/series.rb', line 3377 def floor Utils.wrap_s(_s.floor) end |
#forward_fill(limit: nil) ⇒ Series
Fill missing values with the next non-null value.
This is an alias of .fill_null(strategy: "forward").
3356 3357 3358 |
# File 'lib/polars/series.rb', line 3356 def forward_fill(limit: nil) fill_null(strategy: "forward", limit: limit) end |
#gather(indices, null_on_oob: false) ⇒ Series
Take values by index.
2406 2407 2408 |
# File 'lib/polars/series.rb', line 2406 def gather(indices, null_on_oob: false) super end |
#gather_every(n, offset = 0) ⇒ Series
Take every nth value in the Series and return as new Series.
1988 1989 1990 |
# File 'lib/polars/series.rb', line 1988 def gather_every(n, offset = 0) super end |
#ge(other) ⇒ Series
Method equivalent of operator expression series >= other.
332 333 334 |
# File 'lib/polars/series.rb', line 332 def ge(other) self >= other end |
#get_chunks ⇒ Array
Get the chunks of this Series as a list of Series.
6263 6264 6265 |
# File 'lib/polars/series.rb', line 6263 def get_chunks _s.get_chunks end |
#gt(other) ⇒ Series
Method equivalent of operator expression series > other.
339 340 341 |
# File 'lib/polars/series.rb', line 339 def gt(other) self > other end |
#has_nulls ⇒ Boolean
Return true if the Series has a validity bitmask.
If there is none, it means that there are no null values. Use this to swiftly assert a Series does not have null values.
2437 2438 2439 |
# File 'lib/polars/series.rb', line 2437 def has_nulls _s.has_nulls end |
#hash_(seed = 0, seed_1 = nil, seed_2 = nil, seed_3 = nil) ⇒ Series
Hash the Series.
The hash value is of type UInt64.
5351 5352 5353 |
# File 'lib/polars/series.rb', line 5351 def hash_(seed = 0, seed_1 = nil, seed_2 = nil, seed_3 = nil) super end |
#head(n = 10) ⇒ Series
Get the first n rows.
1905 1906 1907 1908 1909 1910 |
# File 'lib/polars/series.rb', line 1905 def head(n = 10) if n < 0 n = [0, len + n].max end self.class._from_rbseries(_s.head(n)) end |
#hist(bins: nil, bin_count: nil, include_category: true, include_breakpoint: true) ⇒ DataFrame
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.
1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 |
# File 'lib/polars/series.rb', line 1405 def hist( bins: nil, bin_count: nil, include_category: true, include_breakpoint: true ) out = ( to_frame .select_seq( F.col(name).hist( bins: bins, bin_count: bin_count, include_category: include_category, include_breakpoint: include_breakpoint ) ) .to_series ) if !include_breakpoint && !include_category out.to_frame else out.struct.unnest end end |
#implode ⇒ Series
Aggregate values into a list.
6280 6281 6282 |
# File 'lib/polars/series.rb', line 6280 def implode super end |
#index_of(element) ⇒ Object
Get the index of the first occurrence of a value, or nil if it's not found.
3215 3216 3217 |
# File 'lib/polars/series.rb', line 3215 def index_of(element) F.select(F.lit(self).index_of(element)).item end |
#interpolate(method: "linear") ⇒ Series
Interpolate intermediate values. The interpolation method is linear.
5413 5414 5415 |
# File 'lib/polars/series.rb', line 5413 def interpolate(method: "linear") super end |
#interpolate_by(by) ⇒ Series
Fill null values using interpolation based on another column.
5437 5438 5439 |
# File 'lib/polars/series.rb', line 5437 def interpolate_by(by) super end |
#is_between(lower_bound, upper_bound, closed: "both") ⇒ Series
If the value of the lower_bound is greater than that of the upper_bound
then the result will be false, as no value can satisfy the condition.
Get a boolean mask of the values that are between the given lower/upper bounds.
3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 |
# File 'lib/polars/series.rb', line 3045 def is_between( lower_bound, upper_bound, closed: "both" ) if closed == "none" out = (self > lower_bound) & (self < upper_bound) elsif closed == "both" out = (self >= lower_bound) & (self <= upper_bound) elsif closed == "right" out = (self > lower_bound) & (self <= upper_bound) elsif closed == "left" out = (self >= lower_bound) & (self < upper_bound) end if out.is_a?(Expr) out = F.select(out).to_series end out end |
#is_close(other, abs_tol: 0.0, rel_tol: 1.0e-09, nans_equal: false) ⇒ Series
Get a boolean mask of the values being close to the other values.
3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 |
# File 'lib/polars/series.rb', line 3093 def is_close( other, abs_tol: 0.0, rel_tol: 1.0e-09, nans_equal: false ) F.select( F.lit(self).is_close( other, abs_tol: abs_tol, rel_tol: rel_tol, nans_equal: nans_equal ) ).to_series end |
#is_duplicated ⇒ Series
Get mask of all duplicated values.
2786 2787 2788 |
# File 'lib/polars/series.rb', line 2786 def is_duplicated super end |
#is_empty(ignore_nulls: false) ⇒ Boolean Also known as: empty?
Check if the Series is empty.
2453 2454 2455 2456 2457 2458 2459 2460 |
# File 'lib/polars/series.rb', line 2453 def is_empty(ignore_nulls: false) if ignore_nulls msg = "the `ignore_nulls` parameter of `Series.is_empty()` is considered unstable." Utils.issue_unstable_warning(msg) end _s.is_empty(ignore_nulls: ignore_nulls) end |
#is_finite ⇒ Series
Returns a boolean Series indicating which values are finite.
2560 2561 2562 |
# File 'lib/polars/series.rb', line 2560 def is_finite super end |
#is_first_distinct ⇒ Series
Get a mask of the first unique value.
2745 2746 2747 |
# File 'lib/polars/series.rb', line 2745 def is_first_distinct super end |
#is_in(other, nulls_equal: false) ⇒ Series Also known as: in?
Check if elements of this Series are in the other Series.
2686 2687 2688 |
# File 'lib/polars/series.rb', line 2686 def is_in(other, nulls_equal: false) super end |
#is_infinite ⇒ Series
Returns a boolean Series indicating which values are infinite.
2579 2580 2581 |
# File 'lib/polars/series.rb', line 2579 def is_infinite super end |
#is_last_distinct ⇒ Series
Return a boolean mask indicating the last occurrence of each distinct value.
2766 2767 2768 |
# File 'lib/polars/series.rb', line 2766 def is_last_distinct super end |
#is_nan ⇒ Series
Returns a boolean Series indicating which values are NaN.
2599 2600 2601 |
# File 'lib/polars/series.rb', line 2599 def is_nan super end |
#is_not_nan ⇒ Series
Returns a boolean Series indicating which values are not NaN.
2619 2620 2621 |
# File 'lib/polars/series.rb', line 2619 def is_not_nan super end |
#is_not_null ⇒ Series
Returns a boolean Series indicating which values are not null.
2541 2542 2543 |
# File 'lib/polars/series.rb', line 2541 def is_not_null super end |
#is_null ⇒ Series
Returns a boolean Series indicating which values are null.
2521 2522 2523 |
# File 'lib/polars/series.rb', line 2521 def is_null super end |
#is_sorted(descending: false, nulls_last: false) ⇒ Boolean Also known as: sorted?
Check if the Series is sorted.
2481 2482 2483 |
# File 'lib/polars/series.rb', line 2481 def is_sorted(descending: false, nulls_last: false) _s.is_sorted(descending, nulls_last) end |
#is_unique ⇒ Series
Get mask of all unique values.
2724 2725 2726 |
# File 'lib/polars/series.rb', line 2724 def is_unique super end |
#item(index = nil) ⇒ Object
Return the Series as a scalar, or return the element at the given index.
If no index is provided, this is equivalent to s[0], with a check
that the shape is (1,). With an index, this is equivalent to s[index].
515 516 517 518 519 520 521 522 523 524 525 526 527 528 |
# File 'lib/polars/series.rb', line 515 def item(index = nil) if index.nil? if len != 1 msg = ( "can only call '.item' if the Series is of length 1," + " or an explicit index is provided (Series is of length #{len})" ) raise ArgumentError, msg end return _s.get_index(0) end _s.get_index_signed(index) end |
#kurtosis(fisher: true, bias: true) ⇒ Float?
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
5668 5669 5670 |
# File 'lib/polars/series.rb', line 5668 def kurtosis(fisher: true, bias: true) _s.kurtosis(fisher, bias) end |
#last(ignore_nulls: false) ⇒ Object
Get the last element of the Series.
Returns nil if the Series is empty.
6371 6372 6373 |
# File 'lib/polars/series.rb', line 6371 def last(ignore_nulls: false) _s.last(ignore_nulls) end |
#le(other) ⇒ Series
Method equivalent of operator expression series <= other.
226 227 228 |
# File 'lib/polars/series.rb', line 226 def le(other) self <= other end |
#len ⇒ Integer Also known as: length, size
Return the number of elements in the Series.
2863 2864 2865 |
# File 'lib/polars/series.rb', line 2863 def len _s.len end |
#limit(n = 10) ⇒ Series
Get the first n rows.
Alias for #head.
1955 1956 1957 |
# File 'lib/polars/series.rb', line 1955 def limit(n = 10) head(n) end |
#list ⇒ ListNameSpace
Create an object namespace of all list related methods.
6387 6388 6389 |
# File 'lib/polars/series.rb', line 6387 def list ListNameSpace.new(self) end |
#log(base = Math::E) ⇒ Series
Compute the logarithm to a given base.
689 690 691 |
# File 'lib/polars/series.rb', line 689 def log(base = Math::E) super end |
#log10 ⇒ Series
Compute the base 10 logarithm of the input array, element-wise.
727 728 729 |
# File 'lib/polars/series.rb', line 727 def log10 super end |
#log1p ⇒ Series
Compute the natural logarithm of the input array plus one, element-wise.
708 709 710 |
# File 'lib/polars/series.rb', line 708 def log1p super end |
#lower_bound ⇒ Series
Return the lower bound of this Series' dtype as a unit Series.
5724 5725 5726 |
# File 'lib/polars/series.rb', line 5724 def lower_bound super end |
#lt(other) ⇒ Series
Method equivalent of operator expression series < other.
233 234 235 |
# File 'lib/polars/series.rb', line 233 def lt(other) self < other end |
#map_elements(return_dtype: nil, skip_nulls: true, &function) ⇒ Series Also known as: map
Apply a custom/user-defined function (UDF) over elements in this Series and return a new Series.
If the function returns another datatype, the return_dtype arg should be set, otherwise the method will fail.
3840 3841 3842 3843 3844 3845 3846 3847 |
# File 'lib/polars/series.rb', line 3840 def map_elements(return_dtype: nil, skip_nulls: true, &function) if return_dtype.nil? pl_return_dtype = nil else pl_return_dtype = Utils.parse_into_dtype(return_dtype) end Utils.wrap_s(_s.map_elements(function, pl_return_dtype, skip_nulls)) end |
#max ⇒ Object
Get the maximum value in this Series.
1007 1008 1009 |
# File 'lib/polars/series.rb', line 1007 def max _s.max end |
#max_by(by) ⇒ Object
This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.
Get the maximum value in this Series, ordered by an expression.
If the by expression has multiple values equal to the maximum it is not defined which value will be chosen.
1030 1031 1032 |
# File 'lib/polars/series.rb', line 1030 def max_by(by) to_frame.select_seq(F.col(name).max_by(by)).item end |
#mean ⇒ Float?
Reduce this Series to the mean value.
910 911 912 |
# File 'lib/polars/series.rb', line 910 def mean _s.mean end |
#median ⇒ Float?
Get the median of this Series.
1116 1117 1118 |
# File 'lib/polars/series.rb', line 1116 def median _s.median end |
#min ⇒ Object
Get the minimal value in this Series.
972 973 974 |
# File 'lib/polars/series.rb', line 972 def min _s.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 the minimum value in this Series, ordered by an expression.
If the by expression has multiple values equal to the minimum it is not defined which value will be chosen.
995 996 997 |
# File 'lib/polars/series.rb', line 995 def min_by(by) to_frame.select_seq(F.col(name).min_by(by)).item end |
#mode(maintain_order: false) ⇒ Series
Compute the most occurring value(s).
Can return multiple Values.
3536 3537 3538 |
# File 'lib/polars/series.rb', line 3536 def mode(maintain_order: false) super end |
#n_chunks ⇒ Integer
Get the number of chunks that this Series contains.
1637 1638 1639 |
# File 'lib/polars/series.rb', line 1637 def n_chunks _s.n_chunks end |
#n_unique ⇒ Integer
Count the number of unique values in this Series.
5304 5305 5306 |
# File 'lib/polars/series.rb', line 5304 def n_unique _s.n_unique end |
#name ⇒ String
Get the name of this Series.
127 128 129 |
# File 'lib/polars/series.rb', line 127 def name _s.name end |
#nan_max ⇒ Object
Get maximum value, but propagate/poison encountered NaN values.
1047 1048 1049 |
# File 'lib/polars/series.rb', line 1047 def nan_max to_frame.select(F.col(name).nan_max)[0, 0] end |
#nan_min ⇒ Object
Get minimum value, but propagate/poison encountered NaN values.
1064 1065 1066 |
# File 'lib/polars/series.rb', line 1064 def nan_min to_frame.select(F.col(name).nan_min)[0, 0] end |
#ne(other) ⇒ Series
Method equivalent of operator expression series != other.
286 287 288 |
# File 'lib/polars/series.rb', line 286 def ne(other) self != other end |
#ne_missing(other) ⇒ Object
Method equivalent of equality operator series != other where nil == nil.
This differs from the standard ne where null values are propagated.
322 323 324 325 326 327 |
# File 'lib/polars/series.rb', line 322 def ne_missing(other) if other.is_a?(Expr) return Polars.lit(self).ne_missing(other) end to_frame.select(Polars.col(name).ne_missing(other)).to_series end |
#new_from_index(index, length) ⇒ Series
Create a new Series filled with values from the given index.
6211 6212 6213 |
# File 'lib/polars/series.rb', line 6211 def new_from_index(index, length) Utils.wrap_s(_s.new_from_index(index, length)) end |
#none?(&block) ⇒ Boolean Also known as: none
Check if all boolean values in the column are false.
662 663 664 665 666 667 668 |
# File 'lib/polars/series.rb', line 662 def none?(&block) if block_given? map_elements(return_dtype: Boolean, &block).none? else to_frame.select(Polars.col(name).is_not.all).to_series[0] end end |
#not_ ⇒ Series
Negate a boolean Series.
2501 2502 2503 |
# File 'lib/polars/series.rb', line 2501 def not_ self.class._from_rbseries(_s.not_) end |
#null_count ⇒ Integer
Count the null values in this Series.
2418 2419 2420 |
# File 'lib/polars/series.rb', line 2418 def null_count _s.null_count end |
#pct_change(n: 1) ⇒ Series
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.
5615 5616 5617 |
# File 'lib/polars/series.rb', line 5615 def pct_change(n: 1) super end |
#peak_max ⇒ Series
Get a boolean mask of the local maximum peaks.
5271 5272 5273 |
# File 'lib/polars/series.rb', line 5271 def peak_max super end |
#peak_min ⇒ Series
Get a boolean mask of the local minimum peaks.
5292 5293 5294 |
# File 'lib/polars/series.rb', line 5292 def peak_min super end |
#plot ⇒ SeriesPlot
This functionality is currently considered unstable. It may be changed at any point without it being considered a breaking change.
Create a plot namespace.
6451 6452 6453 |
# File 'lib/polars/series.rb', line 6451 def plot SeriesPlot.new(self) end |
#pow(exponent) ⇒ Series
Raise to the power of the given exponent.
If the exponent is float, the result follows the dtype of exponent. Otherwise, it follows dtype of base.
960 961 962 |
# File 'lib/polars/series.rb', line 960 def pow(exponent) to_frame.select_seq(F.col(name).pow(exponent)).to_series end |
#product ⇒ Numeric
Reduce this Series to the product value.
922 923 924 |
# File 'lib/polars/series.rb', line 922 def product to_frame.select(Polars.col(name).product).to_series[0] end |
#qcut(quantiles, labels: nil, left_closed: false, allow_duplicates: false, include_breaks: false) ⇒ Series
Bin continuous values into discrete categories based on their quantiles.
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 |
# File 'lib/polars/series.rb', line 1297 def qcut(quantiles, labels: nil, left_closed: false, allow_duplicates: false, include_breaks: false) result = ( to_frame .select( Polars.col(name).qcut( quantiles, labels: labels, left_closed: left_closed, allow_duplicates: allow_duplicates, include_breaks: include_breaks ) ) .to_series ) if include_breaks result = result.struct.rename_fields(["break_point", "category"]) end result end |
#quantile(quantile, interpolation: "nearest") ⇒ Float?
Get the quantile value of this Series.
1133 1134 1135 |
# File 'lib/polars/series.rb', line 1133 def quantile(quantile, interpolation: "nearest") _s.quantile(quantile, interpolation) end |
#rank(method: "average", descending: false, seed: nil) ⇒ Series
Assign ranks to data, dealing with ties appropriately.
5514 5515 5516 |
# File 'lib/polars/series.rb', line 5514 def rank(method: "average", descending: false, seed: nil) super end |
#rechunk(in_place: false) ⇒ Series
Create a single chunk of memory for this Series.
2964 2965 2966 2967 |
# File 'lib/polars/series.rb', line 2964 def rechunk(in_place: false) opt_s = _s.rechunk(in_place) in_place ? self : Utils.wrap_s(opt_s) end |
#reinterpret(signed: nil, dtype: nil) ⇒ Series
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.
5392 5393 5394 |
# File 'lib/polars/series.rb', line 5392 def reinterpret(signed: nil, dtype: nil) super end |
#rename(name) ⇒ Series
Rename this Series.
1599 1600 1601 |
# File 'lib/polars/series.rb', line 1599 def rename(name) self.alias(name) end |
#repeat_by(by) ⇒ Object
Repeat the elements in this Series as specified in the given expression.
The repeated elements are expanded into a List.
6465 6466 6467 |
# File 'lib/polars/series.rb', line 6465 def repeat_by(by) super end |
#replace(old, new = NO_DEFAULT, default: NO_DEFAULT, return_dtype: nil) ⇒ Series
Replace values by different values.
5823 5824 5825 |
# File 'lib/polars/series.rb', line 5823 def replace(old, new = NO_DEFAULT, default: NO_DEFAULT, return_dtype: nil) super end |
#replace_strict(old, new = NO_DEFAULT, default: NO_DEFAULT, return_dtype: nil) ⇒ Series
Replace all values by different values.
5932 5933 5934 5935 5936 5937 5938 5939 |
# File 'lib/polars/series.rb', line 5932 def replace_strict( old, new = NO_DEFAULT, default: NO_DEFAULT, return_dtype: nil ) super end |
#reshape(dimensions) ⇒ Series
Reshape this Series to a flat Series or a Series of Lists.
5977 5978 5979 |
# File 'lib/polars/series.rb', line 5977 def reshape(dimensions) self.class._from_rbseries(_s.reshape(dimensions)) end |
#reverse ⇒ Series
Return Series in reverse order.
2984 2985 2986 |
# File 'lib/polars/series.rb', line 2984 def reverse super end |
#rle ⇒ Series
Get the lengths of runs of identical values.
1340 1341 1342 |
# File 'lib/polars/series.rb', line 1340 def rle super end |
#rle_id ⇒ Series
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.
1368 1369 1370 |
# File 'lib/polars/series.rb', line 1368 def rle_id super end |
#rolling_kurtosis(window_size, fisher: true, bias: true, min_samples: nil, center: false) ⇒ Series
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.
5207 5208 5209 5210 5211 5212 5213 5214 5215 |
# File 'lib/polars/series.rb', line 5207 def rolling_kurtosis( window_size, fisher: true, bias: true, min_samples: nil, center: false ) super end |
#rolling_map(window_size, weights: nil, min_samples: nil, center: false, &function) ⇒ Series
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.
4726 4727 4728 4729 4730 4731 4732 4733 4734 |
# File 'lib/polars/series.rb', line 4726 def rolling_map( window_size, weights: nil, min_samples: nil, center: false, &function ) super end |
#rolling_max(window_size, weights: nil, min_samples: nil, center: false) ⇒ Series
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.
4171 4172 4173 4174 4175 4176 4177 4178 |
# File 'lib/polars/series.rb', line 4171 def rolling_max( window_size, weights: nil, min_samples: nil, center: false ) super end |
#rolling_max_by(by, window_size, min_samples: 1, closed: "right") ⇒ Series
This functionality is considered unstable. It may be changed at any point 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 max based on another series.
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]
4130 4131 4132 4133 4134 4135 4136 4137 |
# File 'lib/polars/series.rb', line 4130 def rolling_max_by( by, window_size, min_samples: 1, closed: "right" ) super end |
#rolling_mean(window_size, weights: nil, min_samples: nil, center: false) ⇒ Series
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.
4296 4297 4298 4299 4300 4301 4302 4303 |
# File 'lib/polars/series.rb', line 4296 def rolling_mean( window_size, weights: nil, min_samples: nil, center: false ) super end |
#rolling_mean_by(by, window_size, min_samples: 1, closed: "right") ⇒ Series
This functionality is considered unstable. It may be changed at any point 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 mean based on another series.
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]
4255 4256 4257 4258 4259 4260 4261 4262 |
# File 'lib/polars/series.rb', line 4255 def rolling_mean_by( by, window_size, min_samples: 1, closed: "right" ) super end |
#rolling_median(window_size, weights: nil, min_samples: nil, center: false) ⇒ Series
Compute a rolling median.
4849 4850 4851 4852 4853 4854 4855 4856 |
# File 'lib/polars/series.rb', line 4849 def rolling_median( window_size, weights: nil, min_samples: nil, center: false ) super end |
#rolling_median_by(by, window_size, min_samples: 1, closed: "right") ⇒ Series
This functionality is considered unstable. It may be changed at any point 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 based on another series.
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]
4811 4812 4813 4814 4815 4816 4817 4818 |
# File 'lib/polars/series.rb', line 4811 def rolling_median_by( by, window_size, min_samples: 1, closed: "right" ) super end |
#rolling_min(window_size, weights: nil, min_samples: nil, center: false) ⇒ Series
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.
4046 4047 4048 4049 4050 4051 4052 4053 |
# File 'lib/polars/series.rb', line 4046 def rolling_min( window_size, weights: nil, min_samples: nil, center: false ) super end |
#rolling_min_by(by, window_size, min_samples: 1, closed: "right") ⇒ Series
This functionality is considered unstable. It may be changed at any point 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 min based on another series.
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]
4005 4006 4007 4008 4009 4010 4011 4012 |
# File 'lib/polars/series.rb', line 4005 def rolling_min_by( by, window_size, min_samples: 1, closed: "right" ) super end |
#rolling_quantile(quantile, interpolation: "nearest", window_size: 2, weights: nil, min_samples: nil, center: false) ⇒ Series
Compute a rolling quantile.
4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 |
# File 'lib/polars/series.rb', line 4995 def rolling_quantile( quantile, interpolation: "nearest", window_size: 2, weights: nil, min_samples: nil, center: false ) super end |
#rolling_quantile_by(by, window_size, quantile:, interpolation: "nearest", min_samples: 1, closed: "right") ⇒ Series
This functionality is considered unstable. It may be changed at any point 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 based on another series.
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]
4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 |
# File 'lib/polars/series.rb', line 4937 def rolling_quantile_by( by, window_size, quantile:, interpolation: "nearest", min_samples: 1, closed: "right" ) super end |
#rolling_rank(window_size, method: "average", seed: nil, min_samples: nil, center: false) ⇒ Series
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.
5133 5134 5135 5136 5137 5138 5139 5140 5141 |
# File 'lib/polars/series.rb', line 5133 def rolling_rank( window_size, method: "average", seed: nil, min_samples: nil, center: false ) super end |
#rolling_rank_by(by, window_size, method: "average", seed: nil, min_samples: 1, closed: "right") ⇒ Series
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]
5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 |
# File 'lib/polars/series.rb', line 5071 def rolling_rank_by( by, window_size, method: "average", seed: nil, min_samples: 1, closed: "right" ) super end |
#rolling_skew(window_size, bias: true, min_samples: nil, center: false) ⇒ Series
Compute a rolling skew.
5168 5169 5170 |
# File 'lib/polars/series.rb', line 5168 def rolling_skew(window_size, bias: true, min_samples: nil, center: false) super end |
#rolling_std(window_size, weights: nil, min_samples: nil, center: false, ddof: 1) ⇒ Series
Compute a rolling std dev.
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.
4552 4553 4554 4555 4556 4557 4558 4559 4560 |
# File 'lib/polars/series.rb', line 4552 def rolling_std( window_size, weights: nil, min_samples: nil, center: false, ddof: 1 ) super end |
#rolling_std_by(by, window_size, min_samples: 1, closed: "right", ddof: 1) ⇒ Series
This functionality is considered unstable. It may be changed at any point 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 based on another series.
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]
4507 4508 4509 4510 4511 4512 4513 4514 4515 |
# File 'lib/polars/series.rb', line 4507 def rolling_std_by( by, window_size, min_samples: 1, closed: "right", ddof: 1 ) super end |
#rolling_sum(window_size, weights: nil, min_samples: nil, center: false) ⇒ Series
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.
4421 4422 4423 4424 4425 4426 4427 4428 |
# File 'lib/polars/series.rb', line 4421 def rolling_sum( window_size, weights: nil, min_samples: nil, center: false ) super end |
#rolling_sum_by(by, window_size, min_samples: 0, closed: "right") ⇒ Series
This functionality is considered unstable. It may be changed at any point 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 sum based on another series.
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]
4380 4381 4382 4383 4384 4385 4386 4387 |
# File 'lib/polars/series.rb', line 4380 def rolling_sum_by( by, window_size, min_samples: 0, closed: "right" ) super end |
#rolling_var(window_size, weights: nil, min_samples: nil, center: false, ddof: 1) ⇒ Series
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.
4684 4685 4686 4687 4688 4689 4690 4691 4692 |
# File 'lib/polars/series.rb', line 4684 def rolling_var( window_size, weights: nil, min_samples: nil, center: false, ddof: 1 ) super end |
#rolling_var_by(by, window_size, min_samples: 1, closed: "right", ddof: 1) ⇒ Series
This functionality is considered unstable. It may be changed at any point 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 based on another series.
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]
4639 4640 4641 4642 4643 4644 4645 4646 4647 |
# File 'lib/polars/series.rb', line 4639 def rolling_var_by( by, window_size, min_samples: 1, closed: "right", ddof: 1 ) super end |
#round(decimals = 0, mode: "half_to_even") ⇒ Series
Round underlying floating point data by decimals digits.
The default rounding mode is "half to even" (also known as "bankers' rounding").
3469 3470 3471 |
# File 'lib/polars/series.rb', line 3469 def round(decimals = 0, mode: "half_to_even") super end |
#round_sig_figs(digits) ⇒ Series
Round to a number of significant figures.
3491 3492 3493 |
# File 'lib/polars/series.rb', line 3491 def round_sig_figs(digits) super end |
#sample(n: nil, fraction: nil, with_replacement: false, shuffle: false, seed: nil) ⇒ Series
Sample from this Series.
5244 5245 5246 5247 5248 5249 5250 5251 5252 |
# File 'lib/polars/series.rb', line 5244 def sample( n: nil, fraction: nil, with_replacement: false, shuffle: false, seed: nil ) super end |
#scatter(indices, values) ⇒ Series
Set values at the index locations.
3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 |
# File 'lib/polars/series.rb', line 3173 def scatter(indices, values) if indices.is_a?(Integer) indices = [indices] end if indices.length == 0 return self end indices = Series.new("", indices) if values.is_a?(Integer) || values.is_a?(Float) || Utils.bool?(values) || values.is_a?(::String) || values.nil? values = Series.new("", [values]) # if we need to set more than a single value, we extend it if indices.length > 0 values = values.extend_constant(values[0], indices.length - 1) end elsif !values.is_a?(Series) values = Series.new("", values) end _s.scatter(indices._s, values._s) self end |
#search_sorted(element, side: "any", descending: false) ⇒ Integer
Find indices where elements should be inserted to maintain order.
2353 2354 2355 2356 2357 2358 2359 |
# File 'lib/polars/series.rb', line 2353 def search_sorted(element, side: "any", descending: false) if element.is_a?(Integer) || element.is_a?(Float) return Polars.select(Polars.lit(self).search_sorted(element, side: side, descending: descending)).item end element = Series.new(element) Polars.select(Polars.lit(self).search_sorted(element, side: side, descending: descending)).to_series end |
#set(filter, value) ⇒ Series
Use of this function is frequently an anti-pattern, as it can
block optimization (predicate pushdown, etc). Consider using
Polars.when(predicate).then(value).otherwise(self) instead.
Set masked values.
3149 3150 3151 |
# File 'lib/polars/series.rb', line 3149 def set(filter, value) Utils.wrap_s(_s.send("set_with_mask_#{DTYPE_TO_FFINAME.fetch(dtype.class)}", filter._s, value)) end |
#set_sorted(descending: false) ⇒ Series
This can lead to incorrect results if this Series is not sorted!! Use with care!
Flags the Series as sorted.
Enables downstream code to user fast paths for sorted arrays.
6192 6193 6194 |
# File 'lib/polars/series.rb', line 6192 def set_sorted(descending: false) Utils.wrap_s(_s.set_sorted(descending)) end |
#shape ⇒ Array
Shape of this Series.
139 140 141 |
# File 'lib/polars/series.rb', line 139 def shape [_s.len] end |
#shift(n = 1, fill_value: nil) ⇒ Series
Shift the values by a given period.
3882 3883 3884 |
# File 'lib/polars/series.rb', line 3882 def shift(n = 1, fill_value: nil) super end |
#shrink_dtype ⇒ Series
Shrink numeric columns to the minimal required datatype.
Shrink to the dtype needed to fit the extrema of this Series. This can be used to reduce memory pressure.
6236 6237 6238 |
# File 'lib/polars/series.rb', line 6236 def shrink_dtype Utils.wrap_s(_s.shrink_dtype) end |
#shrink_to_fit(in_place: false) ⇒ Series
Shrink Series memory usage.
Shrinks the underlying array capacity to exactly fit the actual data. (Note that this function does not change the Series data type).
5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 |
# File 'lib/polars/series.rb', line 5314 def shrink_to_fit(in_place: false) if in_place _s.shrink_to_fit self else series = clone series._s.shrink_to_fit series end end |
#shuffle(seed: nil) ⇒ Series
Shuffle the contents of this Series.
5999 6000 6001 |
# File 'lib/polars/series.rb', line 5999 def shuffle(seed: nil) super end |
#sign ⇒ Series
Compute the element-wise indication of the sign.
3557 3558 3559 |
# File 'lib/polars/series.rb', line 3557 def sign super end |
#sin ⇒ Series
Compute the element-wise value for the sine.
3576 3577 3578 |
# File 'lib/polars/series.rb', line 3576 def sin super end |
#sinh ⇒ Series
Compute the element-wise value for the hyperbolic sine.
3771 3772 3773 |
# File 'lib/polars/series.rb', line 3771 def sinh super end |
#skew(bias: true) ⇒ Float?
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.
5636 5637 5638 |
# File 'lib/polars/series.rb', line 5636 def skew(bias: true) _s.skew(bias) end |
#slice(offset, length = nil) ⇒ Series
Get a slice of this Series.
1780 1781 1782 |
# File 'lib/polars/series.rb', line 1780 def slice(offset, length = nil) self.class._from_rbseries(_s.slice(offset, length)) end |
#sort(descending: false, nulls_last: false, multithreaded: true, in_place: false) ⇒ Series
Sort this Series.
2096 2097 2098 2099 2100 2101 2102 2103 |
# File 'lib/polars/series.rb', line 2096 def sort(descending: false, nulls_last: false, multithreaded: true, in_place: false) if in_place self._s = _s.sort(descending, nulls_last, multithreaded) self else Utils.wrap_s(_s.sort(descending, nulls_last, multithreaded)) end end |
#sql(query, table_name: "self") ⇒ DataFrame
This functionality is considered unstable, although it is close to being considered stable. It may be changed at any point without it being considered a breaking change.
- The calling Series is automatically registered as a table in the SQLContext
under the name "self". If you want access to the DataFrames, LazyFrames, and
other Series found in the current globals, use :meth:
pl.sql <polars.sql>. - More control over registration and execution behaviour is available by
using the :class:
SQLContextobject. - The SQL query executes in lazy mode before being collected and returned as a DataFrame.
- It is recommended to name your Series for use with SQL, otherwise the default
Series name (an empty string) is used; while
""is valid, it is awkward.
Execute a SQL query against the Series.
2057 2058 2059 |
# File 'lib/polars/series.rb', line 2057 def sql(query, table_name: "self") to_frame.sql(query, table_name: table_name) end |
#sqrt ⇒ Series
Compute the square root of the elements.
576 577 578 |
# File 'lib/polars/series.rb', line 576 def sqrt super end |
#std(ddof: 1) ⇒ Float?
Get the standard deviation of this Series.
1080 1081 1082 1083 1084 1085 1086 |
# File 'lib/polars/series.rb', line 1080 def std(ddof: 1) if !dtype.numeric? nil else to_frame.select(Polars.col(name).std(ddof: ddof)).to_series[0] end end |
#str ⇒ StringNameSpace
Create an object namespace of all string related methods.
6422 6423 6424 |
# File 'lib/polars/series.rb', line 6422 def str StringNameSpace.new(self) end |
#struct ⇒ StructNameSpace
Create an object namespace of all struct related methods.
6429 6430 6431 |
# File 'lib/polars/series.rb', line 6429 def struct StructNameSpace.new(self) end |
#sum ⇒ Numeric
Dtypes in \{Int8, UInt8, Int16, UInt16} are cast to Int64 before summing to prevent overflow issues.
Reduce this Series to the sum value.
898 899 900 |
# File 'lib/polars/series.rb', line 898 def sum _s.sum end |
#tail(n = 10) ⇒ Series
Get the last n rows.
1929 1930 1931 1932 1933 1934 |
# File 'lib/polars/series.rb', line 1929 def tail(n = 10) if n < 0 n = [0, len + n].max end self.class._from_rbseries(_s.tail(n)) end |
#tan ⇒ Series
Compute the element-wise value for the tangent.
3614 3615 3616 |
# File 'lib/polars/series.rb', line 3614 def tan super end |
#tanh ⇒ Series
Compute the element-wise value for the hyperbolic tangent.
3809 3810 3811 |
# File 'lib/polars/series.rb', line 3809 def tanh super end |
#to_a ⇒ Array
Convert this Series to a Ruby Array. This operation clones data.
2925 2926 2927 |
# File 'lib/polars/series.rb', line 2925 def to_a _s.to_a end |
#to_dummies(separator: "_", drop_first: false, drop_nulls: false) ⇒ DataFrame
Get dummy variables.
1162 1163 1164 |
# File 'lib/polars/series.rb', line 1162 def to_dummies(separator: "_", drop_first: false, drop_nulls: false) Utils.wrap_df(_s.to_dummies(separator, drop_first, drop_nulls)) end |
#to_frame(name = nil) ⇒ DataFrame
Cast this Series to a DataFrame.
818 819 820 821 822 823 |
# File 'lib/polars/series.rb', line 818 def to_frame(name = nil) if name return Utils.wrap_df(RbDataFrame.new([rename(name)._s])) end Utils.wrap_df(RbDataFrame.new([_s])) end |
#to_numo ⇒ Numo::NArray
Convert this Series to a Numo array. This operation clones data but is completely safe.
3116 3117 3118 3119 3120 3121 3122 |
# File 'lib/polars/series.rb', line 3116 def to_numo if dtype.temporal? Numo::RObject.cast(to_a) else _s.to_numo end end |
#to_physical ⇒ Series
Cast to physical representation of the logical dtype.
2913 2914 2915 |
# File 'lib/polars/series.rb', line 2913 def to_physical super end |
#to_s ⇒ String Also known as: inspect
Returns a string representing the Series.
146 147 148 |
# File 'lib/polars/series.rb', line 146 def to_s _s.to_s end |
#top_k(k: 5) ⇒ Boolean
Return the k largest elements.
2123 2124 2125 |
# File 'lib/polars/series.rb', line 2123 def top_k(k: 5) super end |
#top_k_by(by, k: 5, reverse: false) ⇒ Series
Return the k largest elements of the by column.
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 sort after this function if you wish the
output to be sorted.
2157 2158 2159 2160 2161 2162 2163 |
# File 'lib/polars/series.rb', line 2157 def top_k_by( by, k: 5, reverse: false ) super end |
#truncate(decimals = 0) ⇒ Series
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:Series.dt.truncate instead.
Truncate numeric data toward zero to decimals number of decimal places.
3443 3444 3445 |
# File 'lib/polars/series.rb', line 3443 def truncate(decimals = 0) super end |
#unique(maintain_order: false) ⇒ Series Also known as: uniq
Get unique elements in series.
2379 2380 2381 |
# File 'lib/polars/series.rb', line 2379 def unique(maintain_order: false) super end |
#unique_counts ⇒ Series
Return a count of the unique values in the order of appearance.
1494 1495 1496 |
# File 'lib/polars/series.rb', line 1494 def unique_counts super end |
#upper_bound ⇒ Series
Return the upper bound of this Series' dtype as a unit Series.
5751 5752 5753 |
# File 'lib/polars/series.rb', line 5751 def upper_bound super end |
#value_counts(sort: false, parallel: false, name: nil, normalize: false) ⇒ DataFrame
Count the unique values in a Series.
1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 |
# File 'lib/polars/series.rb', line 1459 def value_counts( sort: false, parallel: false, name: nil, normalize: false ) if name.nil? if normalize name = "proportion" else name = "count" end end DataFrame._from_rbdf( self._s.value_counts( sort, parallel, name, normalize ) ) end |
#var(ddof: 1) ⇒ Float?
Get variance of this Series.
1100 1101 1102 1103 1104 1105 1106 |
# File 'lib/polars/series.rb', line 1100 def var(ddof: 1) if !dtype.numeric? nil else to_frame.select(Polars.col(name).var(ddof: ddof)).to_series[0] end end |
#zip_with(mask, other) ⇒ Series
Take values from self or other based on the given mask.
Where mask evaluates true, take values from self. Where mask evaluates false, take values from other.
3926 3927 3928 |
# File 'lib/polars/series.rb', line 3926 def zip_with(mask, other) Utils.wrap_s(_s.zip_with(mask._s, other._s)) end |