Class: Polars::Struct

Inherits:
NestedType show all
Defined in:
lib/polars/data_types.rb

Overview

Struct composite type.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fields) ⇒ Struct

Returns a new instance of Struct.



442
443
444
445
446
447
448
# File 'lib/polars/data_types.rb', line 442

def initialize(fields)
  if fields.is_a?(Hash)
    @fields = fields.map { |n, d| Field.new(n, d) }
  else
    @fields = fields
  end
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



440
441
442
# File 'lib/polars/data_types.rb', line 440

def fields
  @fields
end

Instance Method Details

#==(other) ⇒ Object



450
451
452
453
454
455
456
457
458
# File 'lib/polars/data_types.rb', line 450

def ==(other)
  if other.eql?(Struct)
    true
  elsif other.is_a?(Struct)
    fields == other.fields
  else
    false
  end
end

#to_sObject



460
461
462
# File 'lib/polars/data_types.rb', line 460

def to_s
  "#{self.class.name}(#{fields.to_h { |f| [f.name, f.dtype] }})"
end

#to_schemaObject



464
465
466
# File 'lib/polars/data_types.rb', line 464

def to_schema
  @fields.to_h { |f| [f.name, f.dtype] }
end