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.
-
#to_frame ⇒ DataFrame
Convert this Struct Series to a DataFrame.
-
#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.
50 51 52 |
# File 'lib/polars/struct_name_space.rb', line 50 def field(name) super end |
#fields ⇒ Array
Get the names of the fields.
36 37 38 39 40 41 42 |
# File 'lib/polars/struct_name_space.rb', line 36 def fields if _s.nil? [] else _s.struct_fields end end |
#rename_fields(names) ⇒ Series
Rename the fields of the struct.
60 61 62 |
# File 'lib/polars/struct_name_space.rb', line 60 def rename_fields(names) super end |
#schema ⇒ Object
Get the struct definition as a name/dtype schema dict.
67 68 69 70 71 72 73 |
# File 'lib/polars/struct_name_space.rb', line 67 def schema if _s.nil? {} else _s.dtype.to_schema end end |
#to_frame ⇒ DataFrame
Convert this Struct Series to a DataFrame.
29 30 31 |
# File 'lib/polars/struct_name_space.rb', line 29 def to_frame Utils.wrap_df(_s.struct_to_frame) end |
#unnest ⇒ DataFrame
Convert this struct Series to a DataFrame with a separate column for each field.
92 93 94 |
# File 'lib/polars/struct_name_space.rb', line 92 def unnest Utils.wrap_df(_s.struct_unnest) end |