Class: Polars::StructExpr
- Inherits:
-
Object
- Object
- Polars::StructExpr
- Defined in:
- lib/polars/struct_expr.rb
Overview
Namespace for struct related expressions.
Instance Method Summary collapse
-
#[](item) ⇒ Expr
Retrieve one of the fields of this
Structas a new Series. -
#field(name, *more_names) ⇒ Expr
Retrieve one of the fields of this
Structas a new Series. -
#json_encode ⇒ Expr
Convert this struct to a string column with json values.
-
#rename_fields(names) ⇒ Expr
Rename the fields of the struct.
-
#unnest ⇒ Expr
Expand the struct into its individual fields.
-
#with_fields(*exprs, **named_exprs) ⇒ Expr
Add or overwrite fields of this struct.
Instance Method Details
#[](item) ⇒ Expr
Retrieve one of the fields of this Struct as a new Series.
15 16 17 18 19 20 21 22 23 |
# File 'lib/polars/struct_expr.rb', line 15 def [](item) if item.is_a?(::String) field(item) elsif item.is_a?(Integer) Utils.wrap_expr(_rbexpr.struct_field_by_index(item)) else raise ArgumentError, "expected type Integer or String, got #{item.class.name}" end end |
#field(name, *more_names) ⇒ Expr
Retrieve one of the fields of this Struct as a new Series.
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/polars/struct_expr.rb', line 67 def field(name, *more_names) if more_names.any? name = (name.is_a?(::String) ? [name] : name) + more_names end if name.is_a?(::Array) return Utils.wrap_expr(_rbexpr.struct_multiple_fields(name)) end Utils.wrap_expr(_rbexpr.struct_field_by_name(name)) end |
#json_encode ⇒ Expr
Convert this struct to a string column with json values.
164 165 166 |
# File 'lib/polars/struct_expr.rb', line 164 def json_encode Utils.wrap_expr(_rbexpr.struct_json_encode) end |
#rename_fields(names) ⇒ Expr
Rename the fields of the struct.
142 143 144 |
# File 'lib/polars/struct_expr.rb', line 142 def rename_fields(names) Utils.wrap_expr(_rbexpr.struct_rename_fields(names)) end |
#unnest ⇒ Expr
Expand the struct into its individual fields.
Alias for Expr.struct.field("*").
104 105 106 |
# File 'lib/polars/struct_expr.rb', line 104 def unnest field("*") end |
#with_fields(*exprs, **named_exprs) ⇒ Expr
Add or overwrite fields of this struct.
This is similar to with_columns on DataFrame.
206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/polars/struct_expr.rb', line 206 def with_fields( *exprs, **named_exprs ) structify = ENV.fetch("POLARS_AUTO_STRUCTIFY", 0).to_i != 0 rbexprs = Utils.parse_into_list_of_expressions( *exprs, **named_exprs, __structify: structify ) Utils.wrap_expr(_rbexpr.struct_with_fields(rbexprs)) end |