Class: Polars::StructNameSpace
- Inherits:
-
Object
- Object
- Polars::StructNameSpace
- Defined in:
- lib/polars/struct_name_space.rb
Overview
Series.struct namespace.
Instance Method Summary collapse
-
#[](item) ⇒ Series
Retrieve one of the fields of this
Struct
as a new Series. -
#field(name) ⇒ Series
Retrieve one of the fields of this
Struct
as a new Series. -
#fields ⇒ Array
Get the names of the fields.
-
#rename_fields(names) ⇒ Series
Rename the fields of the struct.
-
#schema ⇒ Object
Get the struct definition as a name/dtype schema dict.
-
#unnest ⇒ DataFrame
Convert this struct Series to a DataFrame with a separate column for each field.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Polars::ExprDispatch
Instance Method Details
#[](item) ⇒ Series
Retrieve one of the fields of this Struct
as a new Series.
16 17 18 19 20 21 22 23 24 |
# File 'lib/polars/struct_name_space.rb', line 16 def [](item) if item.is_a?(Integer) field(fields[item]) elsif item.is_a?(::String) field(item) else raise ArgumentError, "expected type Integer or String, got #{item.class.name}" end end |
#field(name) ⇒ Series
Retrieve one of the fields of this Struct
as a new Series.
59 60 61 |
# File 'lib/polars/struct_name_space.rb', line 59 def field(name) super end |
#fields ⇒ Array
Get the names of the fields.
34 35 36 37 38 39 40 |
# File 'lib/polars/struct_name_space.rb', line 34 def fields if _s.nil? [] else _s.struct_fields end end |
#rename_fields(names) ⇒ Series
Rename the fields of the struct.
79 80 81 |
# File 'lib/polars/struct_name_space.rb', line 79 def rename_fields(names) super end |
#schema ⇒ Object
Get the struct definition as a name/dtype schema dict.
91 92 93 94 95 96 97 |
# File 'lib/polars/struct_name_space.rb', line 91 def schema if _s.nil? {} else _s.dtype.to_schema end end |
#unnest ⇒ DataFrame
Convert this struct Series to a DataFrame with a separate column for each field.
116 117 118 |
# File 'lib/polars/struct_name_space.rb', line 116 def unnest Utils.wrap_df(_s.struct_unnest) end |