Class: Polars::MetaExpr
- Inherits:
-
Object
- Object
- Polars::MetaExpr
- Defined in:
- lib/polars/meta_expr.rb
Overview
Namespace for expressions on a meta level.
Instance Method Summary collapse
-
#!=(other) ⇒ Boolean
Not equal.
-
#==(other) ⇒ Boolean
Equal.
-
#as_expression ⇒ Expr
Return the original expression.
-
#as_selector ⇒ Expr
Try to turn this expression in a selector.
-
#eq(other) ⇒ Boolean
Indicate if this expression is the same as another expression.
-
#has_multiple_outputs ⇒ Boolean
Indicate if this expression expands into multiple expressions.
-
#is_column ⇒ Boolean
Indicate if this expression is a basic (non-regex) unaliased column.
-
#is_column_selection(allow_aliasing: false) ⇒ Boolean
Indicate if this expression only selects columns (optionally with aliasing).
-
#is_literal(allow_aliasing: false) ⇒ Boolean
Indicate if this expression is a literal value (optionally aliased).
-
#is_regex_projection ⇒ Boolean
Indicate if this expression expands to columns that match a regex pattern.
-
#ne(other) ⇒ Boolean
Indicate if this expression is NOT the same as another expression.
-
#output_name(raise_if_undetermined: true) ⇒ String
Get the column name that this expression would produce.
-
#pop(schema: nil) ⇒ Array
Pop the latest expression and return the input(s) of the popped expression.
-
#root_names ⇒ Array
Get a list with the root column name.
-
#serialize(file = nil) ⇒ Object
Serialize this expression to a file or string.
-
#show_graph(show: true, output_path: nil, raw_output: false, figsize: [16.0, 12.0], schema: nil) ⇒ Object
Format the expression as a Graphviz graph.
-
#tree_format(return_as_string: false, schema: nil) ⇒ String
Format the expression as a tree.
-
#undo_aliases ⇒ Expr
Undo any renaming operation like
aliasorkeep_name.
Instance Method Details
#!=(other) ⇒ Boolean
Not equal.
22 23 24 |
# File 'lib/polars/meta_expr.rb', line 22 def !=(other) !(self == other) end |
#==(other) ⇒ Boolean
Equal.
15 16 17 |
# File 'lib/polars/meta_expr.rb', line 15 def ==(other) _rbexpr.(other._rbexpr) end |
#as_expression ⇒ Expr
Return the original expression.
246 247 248 |
# File 'lib/polars/meta_expr.rb', line 246 def as_expression Utils.wrap_expr(_rbexpr) end |
#as_selector ⇒ Expr
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.
259 260 261 |
# File 'lib/polars/meta_expr.rb', line 259 def as_selector Selector._from_rbselector(_rbexpr.into_selector) end |
#eq(other) ⇒ Boolean
Indicate if this expression is the same as another expression.
38 39 40 |
# File 'lib/polars/meta_expr.rb', line 38 def eq(other) _rbexpr.(other._rbexpr) end |
#has_multiple_outputs ⇒ Boolean
Indicate if this expression expands into multiple expressions.
66 67 68 |
# File 'lib/polars/meta_expr.rb', line 66 def has_multiple_outputs _rbexpr. end |
#is_column ⇒ Boolean
Indicate if this expression is a basic (non-regex) unaliased column.
84 85 86 |
# File 'lib/polars/meta_expr.rb', line 84 def is_column _rbexpr. 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.
139 140 141 |
# File 'lib/polars/meta_expr.rb', line 139 def is_column_selection(allow_aliasing: false) _rbexpr.(allow_aliasing) end |
#is_literal(allow_aliasing: false) ⇒ Boolean
Indicate if this expression is a literal value (optionally aliased).
160 161 162 |
# File 'lib/polars/meta_expr.rb', line 160 def is_literal(allow_aliasing: false) _rbexpr.(allow_aliasing) end |
#is_regex_projection ⇒ Boolean
Indicate if this expression expands to columns that match a regex pattern.
96 97 98 |
# File 'lib/polars/meta_expr.rb', line 96 def is_regex_projection _rbexpr. end |
#ne(other) ⇒ Boolean
Indicate if this expression is NOT the same as another expression.
54 55 56 |
# File 'lib/polars/meta_expr.rb', line 54 def ne(other) !eq(other) end |
#output_name(raise_if_undetermined: true) ⇒ String
Get the column name that this expression would produce.
183 184 185 186 187 188 189 190 |
# File 'lib/polars/meta_expr.rb', line 183 def output_name(raise_if_undetermined: true) _rbexpr. rescue Polars::ComputeError if !raise_if_undetermined return nil end raise end |
#pop(schema: nil) ⇒ Array
Pop the latest expression and return the input(s) of the popped expression.
203 204 205 |
# File 'lib/polars/meta_expr.rb', line 203 def pop(schema: nil) _rbexpr.(schema).map { |e| Utils.wrap_expr(e) } end |
#root_names ⇒ Array
Get a list with the root column name.
224 225 226 |
# File 'lib/polars/meta_expr.rb', line 224 def root_names _rbexpr. end |
#serialize(file = nil) ⇒ Object
Serialization is not stable across Polars versions: a LazyFrame serialized in one Polars version may not be deserializable in another Polars version.
Serialize this expression to a file or string.
280 281 282 283 284 285 286 |
# File 'lib/polars/meta_expr.rb', line 280 def serialize(file = nil) raise Todo unless _rbexpr.respond_to?(:serialize_binary) serializer = _rbexpr.method(:serialize_binary) Utils.serialize_polars_object(serializer, file) end |
#show_graph(show: true, output_path: nil, raw_output: false, figsize: [16.0, 12.0], schema: nil) ⇒ Object
Format the expression as a Graphviz graph.
Note that Graphviz must be installed to render the visualization (if not already present, you can download it here: https://graphviz.org/download.
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/polars/meta_expr.rb', line 327 def show_graph( show: true, output_path: nil, raw_output: false, figsize: [16.0, 12.0], schema: nil ) dot = _rbexpr.(schema) Utils.display_dot_graph( dot: dot, show: show, output_path: output_path, raw_output: raw_output, figsize: figsize ) end |
#tree_format(return_as_string: false, schema: nil) ⇒ String
Format the expression as a tree.
298 299 300 301 302 303 304 305 306 |
# File 'lib/polars/meta_expr.rb', line 298 def tree_format(return_as_string: false, schema: nil) s = _rbexpr.(schema) if return_as_string s else puts s nil end end |
#undo_aliases ⇒ Expr
Undo any renaming operation like alias or keep_name.
239 240 241 |
# File 'lib/polars/meta_expr.rb', line 239 def undo_aliases Utils.wrap_expr(_rbexpr.) end |