Class: Nanoarrow::Array
- Inherits:
-
Object
- Object
- Nanoarrow::Array
- Defined in:
- lib/nanoarrow/array.rb
Class Method Summary collapse
Instance Method Summary collapse
- #arrow_c_stream ⇒ Object
- #child(i) ⇒ Object
- #chunk(i) ⇒ Object
- #each ⇒ Object
- #each_child ⇒ Object
- #each_chunk ⇒ Object
-
#initialize(obj, schema = nil) ⇒ Array
constructor
A new instance of Array.
- #inspect ⇒ Object
- #length ⇒ Object (also: #size)
- #n_children ⇒ Object
- #n_chunks ⇒ Object
- #schema ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(obj, schema = nil) ⇒ Array
Returns a new instance of Array.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/nanoarrow/array.rb', line 3 def initialize(obj, schema = nil) if obj.is_a?(CMaterializedArrayStream) && schema.nil? @data = obj return end if obj.is_a?(Array) && schema.nil? @data = obj.instance_variable_get(:@data) return end if obj.is_a?(CArray) && schema.nil? @data = CMaterializedArrayStream.from_c_array(obj) return end stream = Utils.c_array_stream(obj, schema) @data = CMaterializedArrayStream.from_c_array_stream(stream) end |
Class Method Details
.from_chunks(obj, schema = nil, validate: true) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/nanoarrow/array.rb', line 23 def self.from_chunks(obj, schema = nil, validate: true) if schema.nil? raise Todo else out_schema = Utils.c_schema(schema) end data = CMaterializedArrayStream.from_c_arrays( obj.map { |item| Utils.c_array(item, schema) }, out_schema, validate ) Array.new(data) end |
Instance Method Details
#arrow_c_stream ⇒ Object
40 41 42 |
# File 'lib/nanoarrow/array.rb', line 40 def arrow_c_stream @data.arrow_c_stream end |
#child(i) ⇒ Object
52 53 54 |
# File 'lib/nanoarrow/array.rb', line 52 def child(i) Array.new(@data.child(i)) end |
#chunk(i) ⇒ Object
68 69 70 |
# File 'lib/nanoarrow/array.rb', line 68 def chunk(i) Array.new(@data.array(i)) end |
#each ⇒ Object
85 86 87 |
# File 'lib/nanoarrow/array.rb', line 85 def each RbIterator.get_iterator(self) end |
#each_child ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/nanoarrow/array.rb', line 56 def each_child return to_enum(:each_child) unless block_given? n_children.times do |i| yield child(i) end end |
#each_chunk ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/nanoarrow/array.rb', line 72 def each_chunk return to_enum(:each_chunk) unless block_given? n_chunks.times do |i| yield chunk(i) end end |
#inspect ⇒ Object
93 94 95 |
# File 'lib/nanoarrow/array.rb', line 93 def inspect "#<#{self.class.name} #{schema.inspect}[#{length.inspect}]>" end |
#length ⇒ Object Also known as: size
80 81 82 |
# File 'lib/nanoarrow/array.rb', line 80 def length @data.length end |
#n_children ⇒ Object
48 49 50 |
# File 'lib/nanoarrow/array.rb', line 48 def n_children @data.schema.n_children end |
#n_chunks ⇒ Object
64 65 66 |
# File 'lib/nanoarrow/array.rb', line 64 def n_chunks @data.n_arrays end |
#schema ⇒ Object
44 45 46 |
# File 'lib/nanoarrow/array.rb', line 44 def schema Schema.new(@data.schema) end |
#to_a ⇒ Object
89 90 91 |
# File 'lib/nanoarrow/array.rb', line 89 def to_a each.to_a end |