Class: Polars::MetaExpr

Inherits:
Object
  • Object
show all
Defined in:
lib/polars/meta_expr.rb

Overview

Namespace for expressions on a meta level.

Instance Method Summary collapse

Instance Method Details

#!=(other) ⇒ Boolean

Not equal.

Returns:



22
23
24
# File 'lib/polars/meta_expr.rb', line 22

def !=(other)
  !(self == other)
end

#==(other) ⇒ Boolean

Equal.

Returns:



15
16
17
# File 'lib/polars/meta_expr.rb', line 15

def ==(other)
  _rbexpr.meta_eq(other._rbexpr)
end

#as_selectorExpr

Note:

This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.

Try to turn this expression in a selector.

Raises if the underlying expressions is not a column or selector.

Returns:



247
248
249
# File 'lib/polars/meta_expr.rb', line 247

def as_selector
  Selector._from_rbselector(_rbexpr.into_selector)
end

#eq(other) ⇒ Boolean

Indicate if this expression is the same as another expression.

Examples:

foo_bar = Polars.col("foo").alias("bar")
foo = Polars.col("foo")
foo_bar.meta.eq(foo)
# => false
foo_bar2 = Polars.col("foo").alias("bar")
foo_bar.meta.eq(foo_bar2)
# => true

Returns:



38
39
40
# File 'lib/polars/meta_expr.rb', line 38

def eq(other)
  _rbexpr.meta_eq(other._rbexpr)
end

#has_multiple_outputsBoolean

Indicate if this expression expands into multiple expressions.

Examples:

e = Polars.col(["a", "b"]).alias("bar")
e.meta.has_multiple_outputs
# => true

Returns:



66
67
68
# File 'lib/polars/meta_expr.rb', line 66

def has_multiple_outputs
  _rbexpr.meta_has_multiple_outputs
end

#is_columnBoolean

Indicate if this expression is a basic (non-regex) unaliased column.

Examples:

e = Polars.col("foo")
e.meta.is_column
# => true
e = Polars.col("foo") * Polars.col("bar")
e.meta.is_column
# => false
e = Polars.col("^col.*\d+$")
e.meta.is_column
# => false

Returns:



84
85
86
# File 'lib/polars/meta_expr.rb', line 84

def is_column
  _rbexpr.meta_is_column
end

#is_column_selection(allow_aliasing: false) ⇒ Boolean

Indicate if this expression only selects columns (optionally with aliasing).

This can include bare columns, columns matched by regex or dtype, selectors and exclude ops, and (optionally) column/expression aliasing.

Examples:

e = Polars.col("foo")
e.meta.is_column_selection
# => true
e = Polars.col("foo").alias("bar")
e.meta.is_column_selection
# => false
e.meta.is_column_selection(allow_aliasing: true)
# => true
e = Polars.col("foo") * Polars.col("bar")
e.meta.is_column_selection
# => false
e = Polars.cs.starts_with("foo")
e.meta.is_column_selection
# => true
e = Polars.cs.starts_with("foo").exclude("foo!")
e.meta.is_column_selection
# => true

Parameters:

  • allow_aliasing (Boolean) (defaults to: false)

    If false (default), any aliasing is not considered to be column selection. Set true to allow for column selection that also includes aliasing.

Returns:



139
140
141
# File 'lib/polars/meta_expr.rb', line 139

def is_column_selection(allow_aliasing: false)
  _rbexpr.meta_is_column_selection(allow_aliasing)
end

#is_literal(allow_aliasing: false) ⇒ Boolean

Indicate if this expression is a literal value (optionally aliased).

Examples:

e = Polars.lit(123)
e.meta.is_literal
# => true
e = Polars.lit(987.654321).alias("foo")
e.meta.is_literal
# => false

Parameters:

  • allow_aliasing (Boolean) (defaults to: false)

    If false (default), only a bare literal will match. Set true to also allow for aliased literals.

Returns:



160
161
162
# File 'lib/polars/meta_expr.rb', line 160

def is_literal(allow_aliasing: false)
  _rbexpr.meta_is_literal(allow_aliasing)
end

#is_regex_projectionBoolean

Indicate if this expression expands to columns that match a regex pattern.

Examples:

e = Polars.col("^.*$").alias("bar")
e.meta.is_regex_projection
# => true

Returns:



96
97
98
# File 'lib/polars/meta_expr.rb', line 96

def is_regex_projection
  _rbexpr.meta_is_regex_projection
end

#ne(other) ⇒ Boolean

Indicate if this expression is NOT the same as another expression.

Examples:

foo_bar = Polars.col("foo").alias("bar")
foo = Polars.col("foo")
foo_bar.meta.ne(foo)
# => true
foo_bar2 = Polars.col("foo").alias("bar")
foo_bar.meta.ne(foo_bar2)
# => false

Returns:



54
55
56
# File 'lib/polars/meta_expr.rb', line 54

def ne(other)
  !eq(other)
end

#output_nameString

Get the column name that this expression would produce.

Examples:

e = Polars.col("foo") * Polars.col("bar")
e.meta.output_name
# => "foo"
e_filter = Polars.col("foo").filter(Polars.col("bar") == 13)
e_filter.meta.output_name
# => "foo"
e_sum_over = Polars.sum("foo").over("groups")
e_sum_over.meta.output_name
# => "foo"
e_sum_slice = Polars.sum("foo").slice(Polars.len - 10, Polars.col("bar"))
e_sum_slice.meta.output_name
# => "foo"
Polars.len.meta.output_name
# => "len"

Returns:



183
184
185
# File 'lib/polars/meta_expr.rb', line 183

def output_name
  _rbexpr.meta_output_name
end

#pop(schema: nil) ⇒ Array

Pop the latest expression and return the input(s) of the popped expression.

Examples:

e = Polars.col("foo") + Polars.col("bar")
first = e.meta.pop[0]
_ = first.meta == Polars.col("bar")
# => true
_ = first.meta == Polars.col("foo")
# => false

Returns:



198
199
200
# File 'lib/polars/meta_expr.rb', line 198

def pop(schema: nil)
  _rbexpr.meta_pop(schema).map { |e| Utils.wrap_expr(e) }
end

#root_namesArray

Get a list with the root column name.

Examples:

e = Polars.col("foo") * Polars.col("bar")
e.meta.root_names
# => ["foo", "bar"]
e_filter = Polars.col("foo").filter(Polars.col("bar") == 13)
e_filter.meta.root_names
# => ["foo", "bar"]
e_sum_over = Polars.sum("foo").over("groups")
e_sum_over.meta.root_names
# => ["foo", "groups"]
e_sum_slice = Polars.sum("foo").slice(Polars.len - 10, Polars.col("bar"))
e_sum_slice.meta.root_names
# => ["foo", "bar"]

Returns:



219
220
221
# File 'lib/polars/meta_expr.rb', line 219

def root_names
  _rbexpr.meta_roots
end

#tree_format(return_as_string: false, schema: nil) ⇒ String

Format the expression as a tree.

Examples:

e = (Polars.col("foo") * Polars.col("bar")).sum.over(Polars.col("ham")) / 2
e.meta.tree_format(return_as_string: true)

Parameters:

  • return_as_string (Boolean) (defaults to: false)

    If true, return as string rather than printing to stdout.

Returns:



261
262
263
264
265
266
267
268
269
# File 'lib/polars/meta_expr.rb', line 261

def tree_format(return_as_string: false, schema: nil)
  s = _rbexpr.meta_tree_format(schema)
  if return_as_string
    s
  else
    puts s
    nil
  end
end

#undo_aliasesExpr

Undo any renaming operation like alias or keep_name.

Examples:

e = Polars.col("foo").alias("bar")
_ = e.meta.undo_aliases.meta == Polars.col("foo")
# => true
e = Polars.col("foo").sum.over("bar")
_ = e.name.keep.meta.undo_aliases.meta == e
# => true

Returns:



234
235
236
# File 'lib/polars/meta_expr.rb', line 234

def undo_aliases
  Utils.wrap_expr(_rbexpr.meta_undo_aliases)
end