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
Struct
as a new Series. -
#field(name) ⇒ Expr
Retrieve one of the fields of this
Struct
as 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) ⇒ Expr
Retrieve one of the fields of this Struct
as a new Series.
56 57 58 |
# File 'lib/polars/struct_expr.rb', line 56 def field(name) Utils.wrap_expr(_rbexpr.struct_field_by_name(name)) end |
#json_encode ⇒ Expr
Convert this struct to a string column with json values.
146 147 148 |
# File 'lib/polars/struct_expr.rb', line 146 def json_encode Utils.wrap_expr(_rbexpr.struct_json_encode) end |
#rename_fields(names) ⇒ Expr
Rename the fields of the struct.
124 125 126 |
# File 'lib/polars/struct_expr.rb', line 124 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("*")
.
86 87 88 |
# File 'lib/polars/struct_expr.rb', line 86 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
.
188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/polars/struct_expr.rb', line 188 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 |