Class: Polars::Array
- Inherits:
-
NestedType
- Object
- DataType
- NestedType
- Polars::Array
- Defined in:
- lib/polars/data_types.rb
Overview
Nested list/array type.
Instance Attribute Summary collapse
-
#inner ⇒ Object
readonly
Returns the value of attribute inner.
-
#shape ⇒ Object
readonly
Returns the value of attribute shape.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(inner, shape) ⇒ Array
constructor
A new instance of Array.
- #to_s ⇒ Object
Constructor Details
#initialize(inner, shape) ⇒ Array
Returns a new instance of Array.
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 |
# File 'lib/polars/data_types.rb', line 466 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
#inner ⇒ Object (readonly)
Returns the value of attribute inner.
464 465 466 |
# File 'lib/polars/data_types.rb', line 464 def inner @inner end |
#shape ⇒ Object (readonly)
Returns the value of attribute shape.
464 465 466 |
# File 'lib/polars/data_types.rb', line 464 def shape @shape end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
464 465 466 |
# File 'lib/polars/data_types.rb', line 464 def size @size end |
Instance Method Details
#==(other) ⇒ Object
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/polars/data_types.rb', line 495 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_s ⇒ Object
511 512 513 |
# File 'lib/polars/data_types.rb', line 511 def to_s "#{self.class.name}(#{inner}, shape: #{shape.inspect})" end |