Class: Polars::Array

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

Overview

Nested list/array type.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inner, shape) ⇒ Array

Returns a new instance of Array.



470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
# File 'lib/polars/data_types.rb', line 470

def initialize(inner, shape)
  if shape.nil?
    msg = "Array constructor is missing the required argument `shape`"
    raise TypeError, msg
  end

  inner_parsed = Utils.parse_into_dtype(inner)
  inner_shape = inner_parsed.is_a?(Array) ? inner_parsed.shape : []

  if shape.is_a?(Integer)
    @inner = inner_parsed
    @size = shape
    @shape = [shape] + inner_shape

  elsif shape.is_a?(::Array) && shape[0].is_a?(Integer)
    if shape.length > 1
      inner_parsed = Array.new(inner_parsed, shape[1..])
    end

    @inner = inner_parsed
    @size = shape[0]
    @shape = shape + inner_shape

  else
    msg = "invalid input for shape: #{shape.inspect}"
    raise TypeError, msg
  end
end

Instance Attribute Details

#innerObject (readonly)

Returns the value of attribute inner.



468
469
470
# File 'lib/polars/data_types.rb', line 468

def inner
  @inner
end

#shapeObject (readonly)

Returns the value of attribute shape.



468
469
470
# File 'lib/polars/data_types.rb', line 468

def shape
  @shape
end

#sizeObject (readonly)

Returns the value of attribute size.



468
469
470
# File 'lib/polars/data_types.rb', line 468

def size
  @size
end

Instance Method Details

#==(other) ⇒ Object



499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
# File 'lib/polars/data_types.rb', line 499

def ==(other)
  if other.eql?(Array)
    true
  elsif other.is_a?(Array)
    if @shape != other.shape
      false
    elsif @inner.nil? || other.inner.nil?
      true
    else
      @inner == other.inner
    end
  else
    false
  end
end

#to_sObject



515
516
517
# File 'lib/polars/data_types.rb', line 515

def to_s
  "#{self.class.name}(#{inner}, shape: #{shape.inspect})"
end