Class: Charty::TableAdapters::ArrowAdapter

Inherits:
BaseAdapter
  • Object
show all
Defined in:
lib/charty/table_adapters/arrow_adapter.rb

Instance Attribute Summary collapse

Attributes inherited from BaseAdapter

#columns, #index

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseAdapter

#==, #column?, #column_names, #drop_na, #group_by, #melt, #sort_values

Constructor Details

#initialize(data) ⇒ ArrowAdapter

Returns a new instance of ArrowAdapter.



10
11
12
13
14
15
# File 'lib/charty/table_adapters/arrow_adapter.rb', line 10

def initialize(data)
  @data = data
  @column_names = @data.columns.map(&:name)
  self.columns = Index.new(@column_names)
  self.index = RangeIndex.new(0 ... length)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



17
18
19
# File 'lib/charty/table_adapters/arrow_adapter.rb', line 17

def data
  @data
end

Class Method Details

.supported?(data) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/charty/table_adapters/arrow_adapter.rb', line 6

def self.supported?(data)
  defined?(Arrow::Table) && data.is_a?(Arrow::Table)
end

Instance Method Details

#[](row, column) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/charty/table_adapters/arrow_adapter.rb', line 36

def [](row, column)
  if row
    @data[column][row]
  else
    case column
    when Array
      Table.new(@data.select_columns(*column))
    else
      column_data = @data[column]
      Vector.new(column_data.data.combine,
                 index: index,
                 name: column_data.name)
    end
  end
end

#column_lengthObject



23
24
25
# File 'lib/charty/table_adapters/arrow_adapter.rb', line 23

def column_length
  @column_names.length
end

#compare_data_equality(other) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/charty/table_adapters/arrow_adapter.rb', line 27

def compare_data_equality(other)
  case other
  when ArrowAdapter
    data == other.data
  else
    super
  end
end

#lengthObject



19
20
21
# File 'lib/charty/table_adapters/arrow_adapter.rb', line 19

def length
  @data.n_rows
end