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.



277
278
279
280
281
282
283
# File 'lib/polars/data_types.rb', line 277

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.



275
276
277
# File 'lib/polars/data_types.rb', line 275

def fields
  @fields
end

Instance Method Details

#==(other) ⇒ Object



285
286
287
288
289
290
291
292
293
# File 'lib/polars/data_types.rb', line 285

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

#to_sObject



295
296
297
# File 'lib/polars/data_types.rb', line 295

def to_s
  "#{self.class.name}([#{fields.map(&:to_s).join("\n")}])"
end

#to_schemaObject



299
300
301
# File 'lib/polars/data_types.rb', line 299

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