Method: Polars::Functions#ones

Defined in:
lib/polars/functions/repeat.rb

#ones(n, dtype: Float64, eager: false) ⇒ Object

Construct a column of length n filled with ones.

This is syntactic sugar for the repeat function.

Examples:

Polars.ones(3, dtype: Polars::Int8, eager: true)
# =>
# shape: (3,)
# Series: 'ones' [i8]
# [
#         1
#         1
#         1
# ]

Parameters:

  • n (Integer)

    Length of the resulting column.

  • dtype (Object) (defaults to: Float64)

    Data type of the resulting column. Defaults to Float64.

  • eager (Boolean) (defaults to: false)

    Evaluate immediately and return a Series. If set to false, return an expression instead.

Returns:



76
77
78
79
80
81
82
83
# File 'lib/polars/functions/repeat.rb', line 76

def ones(n, dtype: Float64, eager: false)
  if (zero = _one_or_zero_by_dtype(1, dtype)).nil?
    msg = "invalid dtype for `ones`; found #{dtype}"
    raise TypeError, msg
  end

  repeat(zero, n, dtype: dtype, eager: eager).alias("ones")
end