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.
-
#_hash(seed = 0, seed_1 = nil, seed_2 = nil, seed_3 = nil) ⇒ Series
Hash the Series.
-
#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, append_chunks: true) ⇒ Series
Append a Series to this one.
-
#arccos ⇒ Series
(also: #acos)
Compute the element-wise value for the inverse cosine.
-
#arccosh ⇒ Series
(also: #acosh)
Compute the element-wise value for the inverse hyperbolic cosine.
-
#arcsin ⇒ Series
(also: #asin)
Compute the element-wise value for the inverse sine.
-
#arcsinh ⇒ Series
(also: #asinh)
Compute the element-wise value for the inverse hyperbolic sine.
-
#arctan ⇒ Series
(also: #atan)
Compute the element-wise value for the inverse tangent.
-
#arctanh ⇒ Series
(also: #atanh)
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(reverse: 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.
-
#argsort(reverse: false, nulls_last: false) ⇒ Series
Get the index values that would sort this Series.
-
#arr ⇒ ArrayNameSpace
Create an object namespace of all array related methods.
-
#bin ⇒ BinaryNameSpace
Create an object namespace of all binary related methods.
-
#bottom_k(k: 5) ⇒ Boolean
Return the
k
smallest elements. -
#cast(dtype, strict: true) ⇒ Series
Cast between data types.
-
#cat ⇒ CatNameSpace
Create an object namespace of all categorical related methods.
-
#ceil ⇒ Series
Rounds up to the nearest integer value.
-
#chunk_lengths ⇒ Array
Get the length of each individual chunk.
-
#cleared ⇒ Series
Create an empty copy of the current Series.
-
#clip(min_val, max_val) ⇒ Series
Clip (limit) the values in an array to a
min
andmax
boundary. -
#clip_max(max_val) ⇒ Series
Clip (limit) the values in an array to a
max
boundary. -
#clip_min(min_val) ⇒ Series
Clip (limit) the values in an array to a
min
boundary. -
#cos ⇒ Series
Compute the element-wise value for the cosine.
-
#cosh ⇒ Series
Compute the element-wise value for the hyperbolic cosine.
-
#count ⇒ Integer
Return the number of elements in the Series.
-
#cum_max(reverse: false) ⇒ Series
(also: #cummax)
Get an array with the cumulative max computed at every element.
-
#cum_min(reverse: false) ⇒ Series
(also: #cummin)
Get an array with the cumulative min computed at every element.
-
#cum_prod(reverse: false) ⇒ Series
(also: #cumprod)
Get an array with the cumulative product computed at every element.
-
#cum_sum(reverse: false) ⇒ Series
(also: #cumsum)
Get an array with the cumulative sum computed at every element.
-
#cumulative_eval(expr, min_periods: 1, parallel: false) ⇒ Series
Run an expression over a sliding window that increases
1
slot every iteration. -
#cut(breaks, labels: nil, left_closed: false, include_breaks: false) ⇒ Series
Bin continuous values into discrete categories.
-
#describe ⇒ 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: false) ⇒ Float?
Computes the entropy.
-
#eq(other) ⇒ Series
Method equivalent of operator expression
series == other
. -
#eq_missing(other) ⇒ Object
Method equivalent of equality operator
series == other
wherenil == nil
. -
#equals(other, null_equal: false, strict: false) ⇒ Boolean
(also: #series_equal)
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_periods: 1) ⇒ Series
Exponentially-weighted moving average.
-
#ewm_std(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_periods: 1) ⇒ Series
Exponentially-weighted moving standard deviation.
-
#ewm_var(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_periods: 1) ⇒ Series
Exponentially-weighted moving variance.
-
#exp ⇒ Series
Compute the exponential, element-wise.
-
#explode ⇒ Series
Explode a list or utf8 Series.
-
#extend_constant(value, n) ⇒ Series
Extend the Series with given number of values.
-
#fill_nan(fill_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.
-
#flags ⇒ Hash
Get flags that are set on the Series.
-
#floor ⇒ Series
Rounds down to the nearest integer value.
-
#ge(other) ⇒ Series
Method equivalent of operator expression
series >= other
. -
#gt(other) ⇒ Series
Method equivalent of operator expression
series > other
. -
#has_validity ⇒ Boolean
Return
true
if the Series has a validity bitmask. -
#head(n = 10) ⇒ Series
Get the first
n
rows. -
#initialize(name = nil, values = nil, dtype: nil, strict: true, nan_to_null: false, dtype_if_empty: nil) ⇒ Series
constructor
Create a new Series.
-
#inner_dtype ⇒ Symbol
Get the inner dtype in of a List typed Series.
-
#interpolate(method: "linear") ⇒ Series
Interpolate intermediate values.
-
#is_boolean ⇒ Boolean
(also: #boolean?, #is_bool, #bool?)
Check if this Series is a Boolean.
-
#is_datelike ⇒ Boolean
(also: #datelike?, #is_temporal, #temporal?)
Check if this Series datatype is datelike.
-
#is_duplicated ⇒ Series
Get mask of all duplicated values.
-
#is_empty ⇒ Boolean
(also: #empty?)
Check if the Series is empty.
-
#is_finite ⇒ Series
Returns a boolean Series indicating which values are finite.
-
#is_first ⇒ Series
Get a mask of the first unique value.
-
#is_float ⇒ Boolean
(also: #float?)
Check if this Series has floating point numbers.
-
#is_in(other) ⇒ 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_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_numeric ⇒ Boolean
(also: #numeric?)
Check if this Series datatype is numeric.
-
#is_unique ⇒ Series
Get mask of all unique values.
-
#is_utf8 ⇒ Boolean
(also: #utf8?)
Check if this Series datatype is a Utf8.
-
#kurtosis(fisher: true, bias: true) ⇒ Float?
Compute the kurtosis (Fisher or Pearson) of a dataset.
-
#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
n
rows. -
#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.
-
#lt(other) ⇒ Series
Method equivalent of operator expression
series < other
. -
#map_elements(return_dtype: nil, skip_nulls: true, &func) ⇒ Series
(also: #map, #apply)
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.
-
#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.
-
#mode ⇒ 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 != other
whereNone == None
. -
#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
. -
#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.
-
#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", reverse: false) ⇒ 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: true) ⇒ Series
Reinterpret the underlying bits as a signed/unsigned integer.
-
#rename(name, in_place: false) ⇒ Series
Rename this Series.
-
#replace(old, new = Expr::NO_DEFAULT, default: Expr::NO_DEFAULT, return_dtype: nil) ⇒ Series
Replace values by different values.
-
#reshape(dims) ⇒ 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_max(window_size, weights: nil, min_periods: nil, center: false) ⇒ Series
Apply a rolling max (moving max) over the values in this array.
-
#rolling_mean(window_size, weights: nil, min_periods: nil, center: false) ⇒ Series
Apply a rolling mean (moving mean) over the values in this array.
-
#rolling_median(window_size, weights: nil, min_periods: nil, center: false, warn_if_unsorted: true) ⇒ Series
Compute a rolling median.
-
#rolling_min(window_size, weights: nil, min_periods: nil, center: false) ⇒ Series
Apply a rolling min (moving min) over the values in this array.
-
#rolling_quantile(quantile, interpolation: "nearest", window_size: 2, weights: nil, min_periods: nil, center: false, warn_if_unsorted: true) ⇒ Series
Compute a rolling quantile.
-
#rolling_skew(window_size, bias: true) ⇒ Series
Compute a rolling skew.
-
#rolling_std(window_size, weights: nil, min_periods: nil, center: false, ddof: 1, warn_if_unsorted: true) ⇒ Series
Compute a rolling std dev.
-
#rolling_sum(window_size, weights: nil, min_periods: nil, center: false) ⇒ Series
Apply a rolling sum (moving sum) over the values in this array.
-
#rolling_var(window_size, weights: nil, min_periods: nil, center: false, ddof: 1, warn_if_unsorted: true) ⇒ Series
Compute a rolling variance.
-
#round(decimals = 0) ⇒ Series
Round underlying floating point data by
decimals
digits. -
#sample(n: nil, frac: nil, with_replacement: false, shuffle: false, seed: nil) ⇒ Series
Sample from this Series.
-
#scatter(idx, value) ⇒ Series
(also: #set_at_idx)
Set values at the index locations.
-
#search_sorted(element, side: "any") ⇒ Integer
Find indices where elements should be inserted to maintain order.
-
#set(filter, value) ⇒ Series
Set masked values.
-
#set_sorted(reverse: false) ⇒ Series
Flags the Series as sorted.
-
#shape ⇒ Array
Shape of this Series.
-
#shift(periods = 1) ⇒ Series
Shift the values by a given period.
-
#shift_and_fill(periods, fill_value) ⇒ Series
Shift the values by a given period and fill the resulting null values.
-
#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(reverse: false, nulls_last: false, in_place: false) ⇒ Series
Sort this 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
n
rows. -
#take(indices) ⇒ Series
Take values by index.
-
#take_every(n) ⇒ Series
Take every nth value in the Series and return as new Series.
-
#tan ⇒ Series
Compute the element-wise value for the tangent.
-
#tanh ⇒ Series
Compute the element-wise value for the hyperbolic tangent.
-
#time_unit ⇒ String
Get the time unit of underlying Datetime Series as
"ns"
,"us"
, or"ms"
. -
#to_a ⇒ Array
Convert this Series to a Ruby Array.
-
#to_dummies(separator: "_", drop_first: false) ⇒ DataFrame
Get dummy variables.
-
#to_frame ⇒ 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
k
largest elements. -
#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.
-
#value_counts(sort: 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, dtype_if_empty: nil) ⇒ Series
Create a new Series.
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 35 def initialize(name = nil, values = nil, dtype: nil, strict: true, nan_to_null: false, dtype_if_empty: nil) # Handle case where values are passed as the first argument if !name.nil? && !name.is_a?(::String) if values.nil? values = name name = nil else raise ArgumentError, "Series name must be a string." end end name = "" if name.nil? # TODO improve if values.is_a?(Range) && values.begin.is_a?(::String) values = values.to_a end if values.nil? self._s = sequence_to_rbseries(name, [], dtype: dtype, dtype_if_empty: dtype_if_empty) elsif values.is_a?(Series) self._s = series_to_rbseries(name, values) elsif values.is_a?(Range) self._s = Polars.arange( values.first, values.last + (values.exclude_end? ? 0 : 1), step: 1, eager: true, dtype: dtype ) .rename(name, in_place: true) ._s elsif values.is_a?(::Array) self._s = sequence_to_rbseries(name, values, dtype: dtype, strict: strict, dtype_if_empty: dtype_if_empty) elsif defined?(Numo::NArray) && values.is_a?(Numo::NArray) self._s = numo_to_rbseries(name, values, strict: strict, nan_to_null: nan_to_null) if !dtype.nil? self._s = self.cast(dtype, strict: true)._s end else raise ArgumentError, "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.
402 403 404 405 406 407 |
# File 'lib/polars/series.rb', line 402 def ! if dtype == Boolean return Utils.wrap_s(_s.not) end raise NotImplementedError end |
#!=(other) ⇒ Series
Not equal.
185 186 187 |
# File 'lib/polars/series.rb', line 185 def !=(other) _comp(other, :neq) end |
#%(other) ⇒ Series
Returns the modulo.
382 383 384 385 386 387 |
# File 'lib/polars/series.rb', line 382 def %(other) if is_datelike raise ArgumentError, "first cast to integer before applying modulo on datelike dtypes" end _arithmetic(other, :rem) end |
#&(other) ⇒ Series
Bitwise AND.
148 149 150 151 152 153 |
# File 'lib/polars/series.rb', line 148 def &(other) if !other.is_a?(Series) other = Series.new([other]) end Utils.wrap_s(_s.bitand(other._s)) end |
#*(other) ⇒ Series
Performs multiplication.
354 355 356 357 358 359 360 361 362 |
# File 'lib/polars/series.rb', line 354 def *(other) if is_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.
392 393 394 395 396 397 |
# File 'lib/polars/series.rb', line 392 def **(power) if is_datelike 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.
340 341 342 |
# File 'lib/polars/series.rb', line 340 def +(other) _arithmetic(other, :add) end |
#-(other) ⇒ Series
Performs subtraction.
347 348 349 |
# File 'lib/polars/series.rb', line 347 def -(other) _arithmetic(other, :sub) end |
#-@ ⇒ Series
Performs negation.
412 413 414 |
# File 'lib/polars/series.rb', line 412 def -@ 0 - self end |
#/(other) ⇒ Series
Performs division.
367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/polars/series.rb', line 367 def /(other) if is_temporal raise ArgumentError, "first cast to integer before dividing datelike dtypes" end if is_float return _arithmetic(other, :div) end cast(Float64) / other end |
#<(other) ⇒ Series
Less than.
199 200 201 |
# File 'lib/polars/series.rb', line 199 def <(other) _comp(other, :lt) end |
#<=(other) ⇒ Series
Less than or equal.
213 214 215 |
# File 'lib/polars/series.rb', line 213 def <=(other) _comp(other, :lt_eq) end |
#==(other) ⇒ Series
Equal.
178 179 180 |
# File 'lib/polars/series.rb', line 178 def ==(other) _comp(other, :eq) end |
#>(other) ⇒ Series
Greater than.
192 193 194 |
# File 'lib/polars/series.rb', line 192 def >(other) _comp(other, :gt) end |
#>=(other) ⇒ Series
Greater than or equal.
206 207 208 |
# File 'lib/polars/series.rb', line 206 def >=(other) _comp(other, :gt_eq) end |
#[](item) ⇒ Object
Returns elements of the Series.
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
# File 'lib/polars/series.rb', line 430 def [](item) if item.is_a?(Series) && [UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64].include?(item.dtype) return Utils.wrap_s(_s.take_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_idx(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.take_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.
461 462 463 464 465 466 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 |
# File 'lib/polars/series.rb', line 461 def []=(key, value) if value.is_a?(::Array) if is_numeric || is_datelike 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(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.
168 169 170 171 172 173 |
# File 'lib/polars/series.rb', line 168 def ^(other) if !other.is_a?(Series) other = Series.new([other]) end Utils.wrap_s(_s.bitxor(other._s)) end |
#_hash(seed = 0, seed_1 = nil, seed_2 = nil, seed_3 = nil) ⇒ Series
Hash the Series.
The hash value is of type :u64
.
3582 3583 3584 |
# File 'lib/polars/series.rb', line 3582 def _hash(seed = 0, seed_1 = nil, seed_2 = nil, seed_3 = nil) super end |
#abs ⇒ Series
Compute absolute values.
3623 3624 3625 |
# File 'lib/polars/series.rb', line 3623 def abs super end |
#alias(name) ⇒ Series
Return a copy of the Series with a new alias/name.
1180 1181 1182 1183 1184 |
# File 'lib/polars/series.rb', line 1180 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
.
546 547 548 549 550 551 552 |
# File 'lib/polars/series.rb', line 546 def all?(ignore_nulls: true, &block) if block_given? apply(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
.
534 535 536 537 538 539 540 |
# File 'lib/polars/series.rb', line 534 def any?(ignore_nulls: true, &block) if block_given? apply(skip_nulls: ignore_nulls, &block).any? else _s.any(ignore_nulls) end end |
#append(other, append_chunks: true) ⇒ Series
Append a Series to this one.
1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 |
# File 'lib/polars/series.rb', line 1437 def append(other, append_chunks: true) begin if append_chunks _s.append(other._s) else _s.extend(other._s) end rescue => e if e. == "Already mutably borrowed" append(other.clone, append_chunks) else raise e end end self end |
#arccos ⇒ Series Also known as: acos
Compute the element-wise value for the inverse cosine.
2695 2696 2697 |
# File 'lib/polars/series.rb', line 2695 def arccos super end |
#arccosh ⇒ Series Also known as: acosh
Compute the element-wise value for the inverse hyperbolic cosine.
2756 2757 2758 |
# File 'lib/polars/series.rb', line 2756 def arccosh super end |
#arcsin ⇒ Series Also known as: asin
Compute the element-wise value for the inverse sine.
2675 2676 2677 |
# File 'lib/polars/series.rb', line 2675 def arcsin super end |
#arcsinh ⇒ Series Also known as: asinh
Compute the element-wise value for the inverse hyperbolic sine.
2735 2736 2737 |
# File 'lib/polars/series.rb', line 2735 def arcsinh super end |
#arctan ⇒ Series Also known as: atan
Compute the element-wise value for the inverse tangent.
2715 2716 2717 |
# File 'lib/polars/series.rb', line 2715 def arctan super end |
#arctanh ⇒ Series Also known as: atanh
Compute the element-wise value for the inverse hyperbolic tangent.
2780 2781 2782 |
# File 'lib/polars/series.rb', line 2780 def arctanh super end |
#arg_max ⇒ Integer?
Get the index of the maximal value.
1702 1703 1704 |
# File 'lib/polars/series.rb', line 1702 def arg_max _s.arg_max end |
#arg_min ⇒ Integer?
Get the index of the minimal value.
1690 1691 1692 |
# File 'lib/polars/series.rb', line 1690 def arg_min _s.arg_min end |
#arg_sort(reverse: false, nulls_last: false) ⇒ Series
Get the index values that would sort this Series.
1645 1646 1647 |
# File 'lib/polars/series.rb', line 1645 def arg_sort(reverse: false, nulls_last: false) super end |
#arg_true ⇒ Series
Get index values where Boolean Series evaluate true
.
1978 1979 1980 |
# File 'lib/polars/series.rb', line 1978 def arg_true Polars.arg_where(self, eager: true) end |
#arg_unique ⇒ Series
Get unique index as Series.
1678 1679 1680 |
# File 'lib/polars/series.rb', line 1678 def arg_unique super end |
#argsort(reverse: false, nulls_last: false) ⇒ Series
Get the index values that would sort this Series.
Alias for #arg_sort.
1659 1660 1661 |
# File 'lib/polars/series.rb', line 1659 def argsort(reverse: false, nulls_last: false) super end |
#arr ⇒ ArrayNameSpace
Create an object namespace of all array related methods.
4100 4101 4102 |
# File 'lib/polars/series.rb', line 4100 def arr ArrayNameSpace.new(self) end |
#bin ⇒ BinaryNameSpace
Create an object namespace of all binary related methods.
4107 4108 4109 |
# File 'lib/polars/series.rb', line 4107 def bin BinaryNameSpace.new(self) end |
#bottom_k(k: 5) ⇒ Boolean
Return the k
smallest elements.
1619 1620 1621 |
# File 'lib/polars/series.rb', line 1619 def bottom_k(k: 5) super end |
#cast(dtype, strict: true) ⇒ Series
Cast between data types.
2123 2124 2125 |
# File 'lib/polars/series.rb', line 2123 def cast(dtype, strict: true) super end |
#cat ⇒ CatNameSpace
Create an object namespace of all categorical related methods.
4114 4115 4116 |
# File 'lib/polars/series.rb', line 4114 def cat CatNameSpace.new(self) end |
#ceil ⇒ Series
Rounds up to the nearest integer value.
Only works on floating point Series.
2514 2515 2516 |
# File 'lib/polars/series.rb', line 2514 def ceil super end |
#chunk_lengths ⇒ Array
Get the length of each individual chunk.
1222 1223 1224 |
# File 'lib/polars/series.rb', line 1222 def chunk_lengths _s.chunk_lengths end |
#cleared ⇒ Series
Create an empty copy of the current Series.
The copy has identical name/dtype but no data.
2395 2396 2397 |
# File 'lib/polars/series.rb', line 2395 def cleared len > 0 ? limit(0) : clone end |
#clip(min_val, max_val) ⇒ Series
Clip (limit) the values in an array to a min
and max
boundary.
Only works for numerical types.
If you want to clip other dtypes, consider writing a "when, then, otherwise" expression. See Functions#when for more information.
3807 3808 3809 |
# File 'lib/polars/series.rb', line 3807 def clip(min_val, max_val) super end |
#clip_max(max_val) ⇒ Series
Clip (limit) the values in an array to a max
boundary.
Only works for numerical types.
If you want to clip other dtypes, consider writing a "when, then, otherwise" expression. See Functions#when for more information.
3837 3838 3839 |
# File 'lib/polars/series.rb', line 3837 def clip_max(max_val) super end |
#clip_min(min_val) ⇒ Series
Clip (limit) the values in an array to a min
boundary.
Only works for numerical types.
If you want to clip other dtypes, consider writing a "when, then, otherwise" expression. See Functions#when for more information.
3822 3823 3824 |
# File 'lib/polars/series.rb', line 3822 def clip_min(min_val) super end |
#cos ⇒ Series
Compute the element-wise value for the cosine.
2637 2638 2639 |
# File 'lib/polars/series.rb', line 2637 def cos super end |
#cosh ⇒ Series
Compute the element-wise value for the hyperbolic cosine.
2819 2820 2821 |
# File 'lib/polars/series.rb', line 2819 def cosh super end |
#count ⇒ Integer
Return the number of elements in the Series.
2085 2086 2087 |
# File 'lib/polars/series.rb', line 2085 def count len - null_count end |
#cum_max(reverse: false) ⇒ Series Also known as: cummax
Get an array with the cumulative max computed at every element.
1313 1314 1315 |
# File 'lib/polars/series.rb', line 1313 def cum_max(reverse: false) super end |
#cum_min(reverse: false) ⇒ Series Also known as: cummin
Get an array with the cumulative min computed at every element.
1290 1291 1292 |
# File 'lib/polars/series.rb', line 1290 def cum_min(reverse: false) super end |
#cum_prod(reverse: false) ⇒ Series Also known as: cumprod
Dtypes :i8
, :u8
, :i16
, and :u16
are cast to
:i64
before multiplying to prevent overflow issues.
Get an array with the cumulative product computed at every element.
1340 1341 1342 |
# File 'lib/polars/series.rb', line 1340 def cum_prod(reverse: false) super end |
#cum_sum(reverse: false) ⇒ Series Also known as: cumsum
Dtypes :i8
, :u8
, :i16
, and :u16
are cast to
:i64
before summing to prevent overflow issues.
Get an array with the cumulative sum computed at every element.
1267 1268 1269 |
# File 'lib/polars/series.rb', line 1267 def cum_sum(reverse: false) super end |
#cumulative_eval(expr, min_periods: 1, parallel: false) ⇒ 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.
1166 1167 1168 |
# File 'lib/polars/series.rb', line 1166 def cumulative_eval(expr, min_periods: 1, parallel: false) super end |
#cut(breaks, labels: nil, left_closed: false, include_breaks: false) ⇒ Series
Bin continuous values into discrete categories.
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 |
# File 'lib/polars/series.rb', line 904 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 ⇒ DataFrame
Quick summary statistics of a series.
Series with mixed datatypes will return summary statistics for the datatype of the first value.
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
# File 'lib/polars/series.rb', line 651 def describe if len == 0 raise ArgumentError, "Series must contain at least one value" elsif is_numeric s = cast(:f64) stats = { "min" => s.min, "max" => s.max, "null_count" => s.null_count, "mean" => s.mean, "std" => s.std, "count" => s.len } elsif is_boolean stats = { "sum" => sum, "null_count" => null_count, "count" => len } elsif is_utf8 stats = { "unique" => unique.length, "null_count" => null_count, "count" => len } elsif is_datelike # we coerce all to string, because a polars column # only has a single dtype and dates: datetime and count: int don't match stats = { "min" => dt.min.to_s, "max" => dt.max.to_s, "null_count" => null_count.to_s, "count" => len.to_s } else raise TypeError, "This type is not supported" end Polars::DataFrame.new( {"statistic" => stats.keys, "value" => stats.values} ) end |
#diff(n: 1, null_behavior: "ignore") ⇒ Series
Calculate the n-th discrete difference.
3691 3692 3693 |
# File 'lib/polars/series.rb', line 3691 def diff(n: 1, null_behavior: "ignore") super end |
#dot(other) ⇒ Numeric
Compute the dot/inner product between two Series.
2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 |
# File 'lib/polars/series.rb', line 2552 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.
601 602 603 |
# File 'lib/polars/series.rb', line 601 def drop_nans super end |
#drop_nulls ⇒ Series
Create a new Series that copies data from this Series without null values.
594 595 596 |
# File 'lib/polars/series.rb', line 594 def drop_nulls super end |
#dt ⇒ DateTimeNameSpace
Create an object namespace of all datetime related methods.
4121 4122 4123 |
# File 'lib/polars/series.rb', line 4121 def dt DateTimeNameSpace.new(self) end |
#dtype ⇒ Symbol
Get the data type of this Series.
91 92 93 |
# File 'lib/polars/series.rb', line 91 def dtype _s.dtype end |
#each ⇒ Object
Returns an enumerator.
419 420 421 422 423 424 425 |
# File 'lib/polars/series.rb', line 419 def each return to_enum(:each) unless block_given? length.times do |i| yield self[i] end end |
#entropy(base: Math::E, normalize: false) ⇒ Float?
Computes the entropy.
Uses the formula -sum(pk * log(pk)
where pk
are discrete probabilities.
1128 1129 1130 |
# File 'lib/polars/series.rb', line 1128 def entropy(base: Math::E, normalize: false) Polars.select(Polars.lit(self).entropy(base: base, normalize: normalize)).to_series[0] end |
#eq(other) ⇒ Series
Method equivalent of operator expression series == other
.
234 235 236 |
# File 'lib/polars/series.rb', line 234 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.
270 271 272 273 274 275 |
# File 'lib/polars/series.rb', line 270 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, null_equal: false, strict: false) ⇒ Boolean Also known as: series_equal
Check if series is equal with another Series.
2072 2073 2074 |
# File 'lib/polars/series.rb', line 2072 def equals(other, null_equal: false, strict: false) _s.equals(other._s, null_equal, strict) 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.
519 520 521 522 |
# File 'lib/polars/series.rb', line 519 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_periods: 1) ⇒ Series
Exponentially-weighted moving average.
3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 |
# File 'lib/polars/series.rb', line 3984 def ewm_mean( com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, min_periods: 1 ) super end |
#ewm_std(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_periods: 1) ⇒ Series
Exponentially-weighted moving standard deviation.
3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 |
# File 'lib/polars/series.rb', line 3998 def ewm_std( com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_periods: 1 ) super end |
#ewm_var(com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_periods: 1) ⇒ Series
Exponentially-weighted moving variance.
4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 |
# File 'lib/polars/series.rb', line 4013 def ewm_var( com: nil, span: nil, half_life: nil, alpha: nil, adjust: true, bias: false, min_periods: 1 ) super end |
#exp ⇒ Series
Compute the exponential, element-wise.
587 588 589 |
# File 'lib/polars/series.rb', line 587 def exp super end |
#explode ⇒ Series
Explode a list or utf8 Series.
This means that every item is expanded to a new row.
2049 2050 2051 |
# File 'lib/polars/series.rb', line 2049 def explode super end |
#extend_constant(value, n) ⇒ Series
Extend the Series with given number of values.
4048 4049 4050 |
# File 'lib/polars/series.rb', line 4048 def extend_constant(value, n) Utils.wrap_s(_s.extend_constant(value, n)) end |
#fill_nan(fill_value) ⇒ Series
Fill floating point NaN value with a fill value.
2420 2421 2422 |
# File 'lib/polars/series.rb', line 2420 def fill_nan(fill_value) super end |
#fill_null(value = nil, strategy: nil, limit: nil) ⇒ Series
Fill null values using the specified value or strategy.
2472 2473 2474 |
# File 'lib/polars/series.rb', line 2472 def fill_null(value = nil, strategy: nil, limit: nil) super end |
#filter(predicate) ⇒ Series
Filter elements by a boolean mask.
1472 1473 1474 1475 1476 1477 |
# File 'lib/polars/series.rb', line 1472 def filter(predicate) if predicate.is_a?(::Array) predicate = Series.new("", predicate) end Utils.wrap_s(_s.filter(predicate._s)) end |
#flags ⇒ Hash
Get flags that are set on the Series.
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/polars/series.rb', line 98 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.
2493 2494 2495 |
# File 'lib/polars/series.rb', line 2493 def floor Utils.wrap_s(_s.floor) end |
#ge(other) ⇒ Series
Method equivalent of operator expression series >= other
.
326 327 328 |
# File 'lib/polars/series.rb', line 326 def ge(other) self >= other end |
#gt(other) ⇒ Series
Method equivalent of operator expression series > other
.
333 334 335 |
# File 'lib/polars/series.rb', line 333 def gt(other) self > other end |
#has_validity ⇒ 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.
1777 1778 1779 |
# File 'lib/polars/series.rb', line 1777 def has_validity _s.has_validity end |
#head(n = 10) ⇒ Series
Get the first n
rows.
1496 1497 1498 |
# File 'lib/polars/series.rb', line 1496 def head(n = 10) to_frame.select(Utils.col(name).head(n)).to_series end |
#inner_dtype ⇒ Symbol
Get the inner dtype in of a List typed Series.
112 113 114 |
# File 'lib/polars/series.rb', line 112 def inner_dtype _s.inner_dtype end |
#interpolate(method: "linear") ⇒ Series
Interpolate intermediate values. The interpolation method is linear.
3616 3617 3618 |
# File 'lib/polars/series.rb', line 3616 def interpolate(method: "linear") super end |
#is_boolean ⇒ Boolean Also known as: boolean?, is_bool, bool?
Check if this Series is a Boolean.
2245 2246 2247 |
# File 'lib/polars/series.rb', line 2245 def is_boolean dtype == Boolean end |
#is_datelike ⇒ Boolean Also known as: datelike?, is_temporal, temporal?
Check if this Series datatype is datelike.
2217 2218 2219 |
# File 'lib/polars/series.rb', line 2217 def is_datelike [Date, Time].include?(dtype) || dtype.is_a?(Datetime) || dtype.is_a?(Duration) end |
#is_duplicated ⇒ Series
Get mask of all duplicated values.
2025 2026 2027 |
# File 'lib/polars/series.rb', line 2025 def is_duplicated super end |
#is_empty ⇒ Boolean Also known as: empty?
Check if the Series is empty.
1789 1790 1791 |
# File 'lib/polars/series.rb', line 1789 def is_empty len == 0 end |
#is_finite ⇒ Series
Returns a boolean Series indicating which values are finite.
1849 1850 1851 |
# File 'lib/polars/series.rb', line 1849 def is_finite super end |
#is_first ⇒ Series
Get a mask of the first unique value.
2005 2006 2007 |
# File 'lib/polars/series.rb', line 2005 def is_first super end |
#is_float ⇒ Boolean Also known as: float?
Check if this Series has floating point numbers.
2232 2233 2234 |
# File 'lib/polars/series.rb', line 2232 def is_float [Float32, Float64].include?(dtype) end |
#is_in(other) ⇒ Series Also known as: in?
Check if elements of this Series are in the other Series.
1960 1961 1962 |
# File 'lib/polars/series.rb', line 1960 def is_in(other) super end |
#is_infinite ⇒ Series
Returns a boolean Series indicating which values are infinite.
1868 1869 1870 |
# File 'lib/polars/series.rb', line 1868 def is_infinite super end |
#is_nan ⇒ Series
Returns a boolean Series indicating which values are NaN.
1888 1889 1890 |
# File 'lib/polars/series.rb', line 1888 def is_nan super end |
#is_not_nan ⇒ Series
Returns a boolean Series indicating which values are not NaN.
1908 1909 1910 |
# File 'lib/polars/series.rb', line 1908 def is_not_nan super end |
#is_not_null ⇒ Series
Returns a boolean Series indicating which values are not null.
1830 1831 1832 |
# File 'lib/polars/series.rb', line 1830 def is_not_null super end |
#is_null ⇒ Series
Returns a boolean Series indicating which values are null.
1810 1811 1812 |
# File 'lib/polars/series.rb', line 1810 def is_null super end |
#is_numeric ⇒ Boolean Also known as: numeric?
Check if this Series datatype is numeric.
2204 2205 2206 |
# File 'lib/polars/series.rb', line 2204 def is_numeric [Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Float32, Float64].include?(dtype) end |
#is_unique ⇒ Series
Get mask of all unique values.
1998 1999 2000 |
# File 'lib/polars/series.rb', line 1998 def is_unique super end |
#is_utf8 ⇒ Boolean Also known as: utf8?
Check if this Series datatype is a Utf8.
2260 2261 2262 |
# File 'lib/polars/series.rb', line 2260 def is_utf8 dtype == String 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
3777 3778 3779 |
# File 'lib/polars/series.rb', line 3777 def kurtosis(fisher: true, bias: true) _s.kurtosis(fisher, bias) end |
#le(other) ⇒ Series
Method equivalent of operator expression series <= other
.
220 221 222 |
# File 'lib/polars/series.rb', line 220 def le(other) self <= other end |
#len ⇒ Integer Also known as: length, size
Return the number of elements in the Series.
2097 2098 2099 |
# File 'lib/polars/series.rb', line 2097 def len _s.len end |
#limit(n = 10) ⇒ Series
Get the first n
rows.
Alias for #head.
1364 1365 1366 |
# File 'lib/polars/series.rb', line 1364 def limit(n = 10) to_frame.select(Utils.col(name).limit(n)).to_series end |
#list ⇒ ListNameSpace
Create an object namespace of all list related methods.
4093 4094 4095 |
# File 'lib/polars/series.rb', line 4093 def list ListNameSpace.new(self) end |
#log(base = Math::E) ⇒ Series
Compute the logarithm to a given base.
573 574 575 |
# File 'lib/polars/series.rb', line 573 def log(base = Math::E) super end |
#log10 ⇒ Series
Compute the base 10 logarithm of the input array, element-wise.
580 581 582 |
# File 'lib/polars/series.rb', line 580 def log10 super end |
#lt(other) ⇒ Series
Method equivalent of operator expression series < other
.
227 228 229 |
# File 'lib/polars/series.rb', line 227 def lt(other) self < other end |
#map_elements(return_dtype: nil, skip_nulls: true, &func) ⇒ Series Also known as: map, apply
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.
2869 2870 2871 2872 2873 2874 2875 2876 |
# File 'lib/polars/series.rb', line 2869 def map_elements(return_dtype: nil, skip_nulls: true, &func) if return_dtype.nil? pl_return_dtype = nil else pl_return_dtype = Utils.rb_type_to_dtype(return_dtype) end Utils.wrap_s(_s.apply_lambda(func, pl_return_dtype, skip_nulls)) end |
#max ⇒ Object
Get the maximum value in this Series.
749 750 751 |
# File 'lib/polars/series.rb', line 749 def max _s.max end |
#mean ⇒ Float?
Reduce this Series to the mean value.
718 719 720 |
# File 'lib/polars/series.rb', line 718 def mean _s.mean end |
#median ⇒ Float?
Get the median of this Series.
815 816 817 |
# File 'lib/polars/series.rb', line 815 def median _s.median end |
#min ⇒ Object
Get the minimal value in this Series.
737 738 739 |
# File 'lib/polars/series.rb', line 737 def min _s.min end |
#mode ⇒ Series
Compute the most occurring value(s).
Can return multiple Values.
2578 2579 2580 |
# File 'lib/polars/series.rb', line 2578 def mode super end |
#n_chunks ⇒ Integer
Get the number of chunks that this Series contains.
1241 1242 1243 |
# File 'lib/polars/series.rb', line 1241 def n_chunks _s.n_chunks end |
#n_unique ⇒ Integer
Count the number of unique values in this Series.
3535 3536 3537 |
# File 'lib/polars/series.rb', line 3535 def n_unique _s.n_unique end |
#name ⇒ String
Get the name of this Series.
119 120 121 |
# File 'lib/polars/series.rb', line 119 def name _s.name end |
#nan_max ⇒ Object
Get maximum value, but propagate/poison encountered NaN values.
756 757 758 |
# File 'lib/polars/series.rb', line 756 def nan_max to_frame.select(Polars.col(name).nan_max)[0, 0] end |
#nan_min ⇒ Object
Get minimum value, but propagate/poison encountered NaN values.
763 764 765 |
# File 'lib/polars/series.rb', line 763 def nan_min to_frame.select(Polars.col(name).nan_min)[0, 0] end |
#ne(other) ⇒ Series
Method equivalent of operator expression series != other
.
280 281 282 |
# File 'lib/polars/series.rb', line 280 def ne(other) self != other end |
#ne_missing(other) ⇒ Object
Method equivalent of equality operator series != other
where None == None
.
This differs from the standard ne
where null values are propagated.
316 317 318 319 320 321 |
# File 'lib/polars/series.rb', line 316 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.
4076 4077 4078 |
# File 'lib/polars/series.rb', line 4076 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
.
558 559 560 561 562 563 564 |
# File 'lib/polars/series.rb', line 558 def none?(&block) if block_given? apply(&block).none? else to_frame.select(Polars.col(name).is_not.all).to_series[0] end end |
#null_count ⇒ Integer
Count the null values in this Series.
1767 1768 1769 |
# File 'lib/polars/series.rb', line 1767 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.
3742 3743 3744 |
# File 'lib/polars/series.rb', line 3742 def pct_change(n: 1) super end |
#peak_max ⇒ Series
Get a boolean mask of the local maximum peaks.
3502 3503 3504 |
# File 'lib/polars/series.rb', line 3502 def peak_max super end |
#peak_min ⇒ Series
Get a boolean mask of the local minimum peaks.
3523 3524 3525 |
# File 'lib/polars/series.rb', line 3523 def peak_min super end |
#product ⇒ Numeric
Reduce this Series to the product value.
725 726 727 |
# File 'lib/polars/series.rb', line 725 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.
989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 |
# File 'lib/polars/series.rb', line 989 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.
832 833 834 |
# File 'lib/polars/series.rb', line 832 def quantile(quantile, interpolation: "nearest") _s.quantile(quantile, interpolation) end |
#rank(method: "average", reverse: false) ⇒ Series
Assign ranks to data, dealing with ties appropriately.
3679 3680 3681 |
# File 'lib/polars/series.rb', line 3679 def rank(method: "average", reverse: false) super end |
#rechunk(in_place: false) ⇒ Series
Create a single chunk of memory for this Series.
2172 2173 2174 2175 |
# File 'lib/polars/series.rb', line 2172 def rechunk(in_place: false) opt_s = _s.rechunk(in_place) in_place ? self : Utils.wrap_s(opt_s) end |
#reinterpret(signed: true) ⇒ Series
Reinterpret the underlying bits as a signed/unsigned integer.
This operation is only allowed for 64bit integers. For lower bits integers, you can safely use that cast operation.
3595 3596 3597 |
# File 'lib/polars/series.rb', line 3595 def reinterpret(signed: true) super end |
#rename(name, in_place: false) ⇒ Series
Rename this Series.
1198 1199 1200 1201 1202 1203 1204 1205 |
# File 'lib/polars/series.rb', line 1198 def rename(name, in_place: false) if in_place _s.rename(name) self else self.alias(name) end end |
#replace(old, new = Expr::NO_DEFAULT, default: Expr::NO_DEFAULT, return_dtype: nil) ⇒ Series
Replace values by different values.
3944 3945 3946 |
# File 'lib/polars/series.rb', line 3944 def replace(old, new = Expr::NO_DEFAULT, default: Expr::NO_DEFAULT, return_dtype: nil) super end |
#reshape(dims) ⇒ Series
Reshape this Series to a flat Series or a Series of Lists.
3955 3956 3957 |
# File 'lib/polars/series.rb', line 3955 def reshape(dims) super end |
#reverse ⇒ Series
Return Series in reverse order.
2192 2193 2194 |
# File 'lib/polars/series.rb', line 2192 def reverse super end |
#rle ⇒ Series
Get the lengths of runs of identical values.
1032 1033 1034 |
# File 'lib/polars/series.rb', line 1032 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.
1060 1061 1062 |
# File 'lib/polars/series.rb', line 1060 def rle_id super end |
#rolling_max(window_size, weights: nil, min_periods: 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.
3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 |
# File 'lib/polars/series.rb', line 3051 def rolling_max( window_size, weights: nil, min_periods: nil, center: false ) to_frame .select( Polars.col(name).rolling_max( window_size, weights: weights, min_periods: min_periods, center: center ) ) .to_series end |
#rolling_mean(window_size, weights: nil, min_periods: 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.
3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 |
# File 'lib/polars/series.rb', line 3101 def rolling_mean( window_size, weights: nil, min_periods: nil, center: false ) to_frame .select( Polars.col(name).rolling_mean( window_size, weights: weights, min_periods: min_periods, center: center ) ) .to_series end |
#rolling_median(window_size, weights: nil, min_periods: nil, center: false, warn_if_unsorted: true) ⇒ Series
Compute a rolling median.
3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 |
# File 'lib/polars/series.rb', line 3311 def rolling_median( window_size, weights: nil, min_periods: nil, center: false, warn_if_unsorted: true ) if min_periods.nil? min_periods = window_size end to_frame .select( Polars.col(name).rolling_median( window_size, weights: weights, min_periods: min_periods, center: center, warn_if_unsorted: warn_if_unsorted ) ) .to_series end |
#rolling_min(window_size, weights: nil, min_periods: 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.
3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 |
# File 'lib/polars/series.rb', line 3001 def rolling_min( window_size, weights: nil, min_periods: nil, center: false ) to_frame .select( Polars.col(name).rolling_min( window_size, weights: weights, min_periods: min_periods, center: center ) ) .to_series end |
#rolling_quantile(quantile, interpolation: "nearest", window_size: 2, weights: nil, min_periods: nil, center: false, warn_if_unsorted: true) ⇒ Series
Compute a rolling quantile.
3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 |
# File 'lib/polars/series.rb', line 3382 def rolling_quantile( quantile, interpolation: "nearest", window_size: 2, weights: nil, min_periods: nil, center: false, warn_if_unsorted: true ) if min_periods.nil? min_periods = window_size end to_frame .select( Polars.col(name).rolling_quantile( quantile, interpolation: interpolation, window_size: window_size, weights: weights, min_periods: min_periods, center: center, warn_if_unsorted: warn_if_unsorted ) ) .to_series end |
#rolling_skew(window_size, bias: true) ⇒ Series
Compute a rolling skew.
3433 3434 3435 |
# File 'lib/polars/series.rb', line 3433 def rolling_skew(window_size, bias: true) super end |
#rolling_std(window_size, weights: nil, min_periods: nil, center: false, ddof: 1, warn_if_unsorted: true) ⇒ 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.
3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 |
# File 'lib/polars/series.rb', line 3202 def rolling_std( window_size, weights: nil, min_periods: nil, center: false, ddof: 1, warn_if_unsorted: true ) to_frame .select( Polars.col(name).rolling_std( window_size, weights: weights, min_periods: min_periods, center: center, ddof: ddof, warn_if_unsorted: warn_if_unsorted ) ) .to_series end |
#rolling_sum(window_size, weights: nil, min_periods: 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.
3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 |
# File 'lib/polars/series.rb', line 3151 def rolling_sum( window_size, weights: nil, min_periods: nil, center: false ) to_frame .select( Polars.col(name).rolling_sum( window_size, weights: weights, min_periods: min_periods, center: center ) ) .to_series end |
#rolling_var(window_size, weights: nil, min_periods: nil, center: false, ddof: 1, warn_if_unsorted: true) ⇒ 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.
3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 |
# File 'lib/polars/series.rb', line 3257 def rolling_var( window_size, weights: nil, min_periods: nil, center: false, ddof: 1, warn_if_unsorted: true ) to_frame .select( Polars.col(name).rolling_var( window_size, weights: weights, min_periods: min_periods, center: center, ddof: ddof, warn_if_unsorted: warn_if_unsorted ) ) .to_series end |
#round(decimals = 0) ⇒ Series
Round underlying floating point data by decimals
digits.
2536 2537 2538 |
# File 'lib/polars/series.rb', line 2536 def round(decimals = 0) super end |
#sample(n: nil, frac: nil, with_replacement: false, shuffle: false, seed: nil) ⇒ Series
Sample from this Series.
3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 |
# File 'lib/polars/series.rb', line 3464 def sample( n: nil, frac: nil, with_replacement: false, shuffle: false, seed: nil ) if !n.nil? && !frac.nil? raise ArgumentError, "cannot specify both `n` and `frac`" end if n.nil? && !frac.nil? return Utils.wrap_s(_s.sample_frac(frac, with_replacement, shuffle, seed)) end if n.nil? n = 1 end Utils.wrap_s(_s.sample_n(n, with_replacement, shuffle, seed)) end |
#scatter(idx, value) ⇒ Series Also known as: set_at_idx
Set values at the index locations.
2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 |
# File 'lib/polars/series.rb', line 2357 def scatter(idx, value) if idx.is_a?(Integer) idx = [idx] end if idx.length == 0 return self end idx = Series.new("", idx) if value.is_a?(Integer) || value.is_a?(Float) || Utils.bool?(value) || value.is_a?(::String) || value.nil? value = Series.new("", [value]) # if we need to set more than a single value, we extend it if idx.length > 0 value = value.extend_constant(value[0], idx.length - 1) end elsif !value.is_a?(Series) value = Series.new("", value) end _s.scatter(idx._s, value._s) self end |
#search_sorted(element, side: "any") ⇒ Integer
Find indices where elements should be inserted to maintain order.
1712 1713 1714 1715 1716 1717 1718 |
# File 'lib/polars/series.rb', line 1712 def search_sorted(element, side: "any") if element.is_a?(Integer) || element.is_a?(Float) return Polars.select(Polars.lit(self).search_sorted(element, side: side)).item end element = Series.new(element) Polars.select(Polars.lit(self).search_sorted(element, side: side)).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.
2333 2334 2335 |
# File 'lib/polars/series.rb', line 2333 def set(filter, value) Utils.wrap_s(_s.send("set_with_mask_#{DTYPE_TO_FFINAME.fetch(dtype.class)}", filter._s, value)) end |
#set_sorted(reverse: 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.
4069 4070 4071 |
# File 'lib/polars/series.rb', line 4069 def set_sorted(reverse: false) Utils.wrap_s(_s.set_sorted(reverse)) end |
#shape ⇒ Array
Shape of this Series.
126 127 128 |
# File 'lib/polars/series.rb', line 126 def shape [_s.len] end |
#shift(periods = 1) ⇒ Series
Shift the values by a given period.
2909 2910 2911 |
# File 'lib/polars/series.rb', line 2909 def shift(periods = 1) super end |
#shift_and_fill(periods, fill_value) ⇒ Series
Shift the values by a given period and fill the resulting null values.
2921 2922 2923 |
# File 'lib/polars/series.rb', line 2921 def shift_and_fill(periods, fill_value) 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.
4086 4087 4088 |
# File 'lib/polars/series.rb', line 4086 def shrink_dtype super 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).
3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 |
# File 'lib/polars/series.rb', line 3545 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.
3977 3978 3979 |
# File 'lib/polars/series.rb', line 3977 def shuffle(seed: nil) super end |
#sign ⇒ Series
Compute the element-wise indication of the sign.
2599 2600 2601 |
# File 'lib/polars/series.rb', line 2599 def sign super end |
#sin ⇒ Series
Compute the element-wise value for the sine.
2618 2619 2620 |
# File 'lib/polars/series.rb', line 2618 def sin super end |
#sinh ⇒ Series
Compute the element-wise value for the hyperbolic sine.
2800 2801 2802 |
# File 'lib/polars/series.rb', line 2800 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.
3758 3759 3760 |
# File 'lib/polars/series.rb', line 3758 def skew(bias: true) _s.skew(bias) end |
#slice(offset, length = nil) ⇒ Series
Get a slice of this Series.
1388 1389 1390 |
# File 'lib/polars/series.rb', line 1388 def slice(offset, length = nil) super end |
#sort(reverse: false, nulls_last: false, in_place: false) ⇒ Series
Sort this Series.
1570 1571 1572 1573 1574 1575 1576 1577 |
# File 'lib/polars/series.rb', line 1570 def sort(reverse: false, nulls_last: false, in_place: false) if in_place self._s = _s.sort(reverse, nulls_last) self else Utils.wrap_s(_s.sort(reverse, nulls_last)) end end |
#sqrt ⇒ Series
Compute the square root of the elements.
527 528 529 |
# File 'lib/polars/series.rb', line 527 def sqrt self**0.5 end |
#std(ddof: 1) ⇒ Float?
Get the standard deviation of this Series.
779 780 781 782 783 784 785 |
# File 'lib/polars/series.rb', line 779 def std(ddof: 1) if !is_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.
4128 4129 4130 |
# File 'lib/polars/series.rb', line 4128 def str StringNameSpace.new(self) end |
#struct ⇒ StructNameSpace
Create an object namespace of all struct related methods.
4135 4136 4137 |
# File 'lib/polars/series.rb', line 4135 def struct StructNameSpace.new(self) end |
#sum ⇒ Numeric
Dtypes :i8
, :u8
, :i16
, and :u16
are cast to
:i64
before summing to prevent overflow issues.
Reduce this Series to the sum value.
706 707 708 |
# File 'lib/polars/series.rb', line 706 def sum _s.sum end |
#tail(n = 10) ⇒ Series
Get the last n
rows.
1517 1518 1519 |
# File 'lib/polars/series.rb', line 1517 def tail(n = 10) to_frame.select(Utils.col(name).tail(n)).to_series end |
#take(indices) ⇒ Series
Take values by index.
1760 1761 1762 |
# File 'lib/polars/series.rb', line 1760 def take(indices) to_frame.select(Polars.col(name).take(indices)).to_series end |
#take_every(n) ⇒ Series
Take every nth value in the Series and return as new Series.
1535 1536 1537 |
# File 'lib/polars/series.rb', line 1535 def take_every(n) super end |
#tan ⇒ Series
Compute the element-wise value for the tangent.
2656 2657 2658 |
# File 'lib/polars/series.rb', line 2656 def tan super end |
#tanh ⇒ Series
Compute the element-wise value for the hyperbolic tangent.
2838 2839 2840 |
# File 'lib/polars/series.rb', line 2838 def tanh super end |
#time_unit ⇒ String
Get the time unit of underlying Datetime Series as "ns"
, "us"
, or "ms"
.
133 134 135 |
# File 'lib/polars/series.rb', line 133 def time_unit _s.time_unit end |
#to_a ⇒ Array
Convert this Series to a Ruby Array. This operation clones data.
2162 2163 2164 |
# File 'lib/polars/series.rb', line 2162 def to_a _s.to_a end |
#to_dummies(separator: "_", drop_first: false) ⇒ DataFrame
Get dummy variables.
854 855 856 |
# File 'lib/polars/series.rb', line 854 def to_dummies(separator: "_", drop_first: false) Utils.wrap_df(_s.to_dummies(separator, drop_first)) end |
#to_frame ⇒ DataFrame
Cast this Series to a DataFrame.
608 609 610 |
# File 'lib/polars/series.rb', line 608 def to_frame 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.
2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 |
# File 'lib/polars/series.rb', line 2278 def to_numo if !has_validity if is_datelike Numo::RObject.cast(to_a) elsif is_numeric # TODO make more efficient { UInt8 => Numo::UInt8, UInt16 => Numo::UInt16, UInt32 => Numo::UInt32, UInt64 => Numo::UInt64, Int8 => Numo::Int8, Int16 => Numo::Int16, Int32 => Numo::Int32, Int64 => Numo::Int64, Float32 => Numo::SFloat, Float64 => Numo::DFloat }.fetch(dtype.class).cast(to_a) elsif is_boolean Numo::Bit.cast(to_a) else _s.to_numo end elsif is_datelike Numo::RObject.cast(to_a) else _s.to_numo end end |
#to_physical ⇒ Series
Cast to physical representation of the logical dtype.
:date
->:i32
:datetime
->:i64
:time
->:i64
:duration
->:i64
:cat
->:u32
- other data types will be left unchanged.
2150 2151 2152 |
# File 'lib/polars/series.rb', line 2150 def to_physical super end |
#to_s ⇒ String Also known as: inspect
Returns a string representing the Series.
140 141 142 |
# File 'lib/polars/series.rb', line 140 def to_s _s.to_s end |
#top_k(k: 5) ⇒ Boolean
Return the k
largest elements.
1597 1598 1599 |
# File 'lib/polars/series.rb', line 1597 def top_k(k: 5) super end |
#unique(maintain_order: false) ⇒ Series Also known as: uniq
Get unique elements in series.
1738 1739 1740 |
# File 'lib/polars/series.rb', line 1738 def unique(maintain_order: false) super end |
#unique_counts ⇒ Series
Return a count of the unique values in the order of appearance.
1104 1105 1106 |
# File 'lib/polars/series.rb', line 1104 def unique_counts super end |
#value_counts(sort: false) ⇒ DataFrame
Count the unique values in a Series.
1085 1086 1087 |
# File 'lib/polars/series.rb', line 1085 def value_counts(sort: false) Utils.wrap_df(_s.value_counts(sort)) end |
#var(ddof: 1) ⇒ Float?
Get variance of this Series.
799 800 801 802 803 804 805 |
# File 'lib/polars/series.rb', line 799 def var(ddof: 1) if !is_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.
2965 2966 2967 |
# File 'lib/polars/series.rb', line 2965 def zip_with(mask, other) Utils.wrap_s(_s.zip_with(mask._s, other._s)) end |