Class: Polars::StructNameSpace

Inherits:
Object
  • Object
show all
Defined in:
lib/polars/struct_name_space.rb

Overview

Series.struct namespace.

Instance Method Summary collapse

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

#fieldsArray

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

#to_frameDataFrame

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