Class: Nanoarrow::Array

Inherits:
Object
  • Object
show all
Defined in:
lib/nanoarrow/array.rb

Class Method Summary collapse

Instance Method Summary collapse

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_streamObject



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

#eachObject



85
86
87
# File 'lib/nanoarrow/array.rb', line 85

def each
  RbIterator.get_iterator(self)
end

#each_childObject



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_chunkObject



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

#inspectObject



93
94
95
# File 'lib/nanoarrow/array.rb', line 93

def inspect
  "#<#{self.class.name} #{schema.inspect}[#{length.inspect}]>"
end

#lengthObject Also known as: size



80
81
82
# File 'lib/nanoarrow/array.rb', line 80

def length
  @data.length
end

#n_childrenObject



48
49
50
# File 'lib/nanoarrow/array.rb', line 48

def n_children
  @data.schema.n_children
end

#n_chunksObject



64
65
66
# File 'lib/nanoarrow/array.rb', line 64

def n_chunks
  @data.n_arrays
end

#schemaObject



44
45
46
# File 'lib/nanoarrow/array.rb', line 44

def schema
  Schema.new(@data.schema)
end

#to_aObject



89
90
91
# File 'lib/nanoarrow/array.rb', line 89

def to_a
  each.to_a
end