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

Turn this expression in a selector.

Returns:



177
178
179
# File 'lib/polars/meta_expr.rb', line 177

def _as_selector
  Utils.wrap_expr(_rbexpr._meta_as_selector)
end

#_selector_add(other) ⇒ Expr

Add selectors.

Returns:



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

def _selector_add(other)
  Utils.wrap_expr(_rbexpr._meta_selector_add(other._rbexpr))
end

#_selector_and(other) ⇒ Expr

& selectors.

Returns:



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

def _selector_and(other)
  Utils.wrap_expr(_rbexpr._meta_selector_and(other._rbexpr))
end

#_selector_sub(other) ⇒ Expr

Subtract selectors.

Returns:



191
192
193
# File 'lib/polars/meta_expr.rb', line 191

def _selector_sub(other)
  Utils.wrap_expr(_rbexpr._meta_selector_sub(other._rbexpr))
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_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:



119
120
121
# File 'lib/polars/meta_expr.rb', line 119

def output_name
  _rbexpr.meta_output_name
end

#popArray

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

Examples:

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

Returns:



134
135
136
# File 'lib/polars/meta_expr.rb', line 134

def pop
  _rbexpr.meta_pop.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:



155
156
157
# File 'lib/polars/meta_expr.rb', line 155

def root_names
  _rbexpr.meta_roots
end

#tree_format(return_as_string: false) ⇒ 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:



212
213
214
215
216
217
218
219
220
# File 'lib/polars/meta_expr.rb', line 212

def tree_format(return_as_string: false)
  s = _rbexpr.meta_tree_format
  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:



170
171
172
# File 'lib/polars/meta_expr.rb', line 170

def undo_aliases
  Utils.wrap_expr(_rbexpr.meta_undo_aliases)
end