Method: Polars::Functions#format
- Defined in:
- lib/polars/functions/as_datatype.rb
#format(f_string, *args) ⇒ Expr
Format expressions as a string.
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 |
# File 'lib/polars/functions/as_datatype.rb', line 582 def format(f_string, *args) if f_string.scan("{}").length != args.length raise ArgumentError, "number of placeholders should equal the number of arguments" end exprs = [] arguments = args.each f_string.split(/(\{\})/).each do |s| if s == "{}" e = Utils.wrap_expr(Utils.parse_into_expression(arguments.next)) exprs << e elsif s.length > 0 exprs << lit(s) end end concat_str(exprs, separator: "") end |