Class: CADFArray

Inherits:
CAObject
  • Object
show all
Defined in:
lib/carray-dataframe/cadf_array.rb

Overview

CADFArray

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(column_names, column_data, index: nil) ⇒ CADFArray

:nodoc:



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/carray-dataframe/cadf_array.rb', line 8

def initialize (column_names, column_data, index: nil)
  @column_names = column_names
  @column_data  = column_data
  if index
    @index = index
  else
    @index = CArray.int(column_data.first[1].size).seq
  end
  dim = [@column_data[@column_names.first].size, @column_names.size]
  extend CArray::TableMethods
  super(:object, dim, :read_only=>true)
  __create_mask__
end

Instance Attribute Details

#column_namesObject (readonly)

Returns the value of attribute column_names.



22
23
24
# File 'lib/carray-dataframe/cadf_array.rb', line 22

def column_names
  @column_names
end

#indexObject (readonly)

Returns the value of attribute index.



22
23
24
# File 'lib/carray-dataframe/cadf_array.rb', line 22

def index
  @index
end

Instance Method Details

#copy_data(data) ⇒ Object



36
37
38
39
40
# File 'lib/carray-dataframe/cadf_array.rb', line 36

def copy_data (data)
  @column_names.each_with_index do |name, i|
    data[nil,i] = @column_data[name].value
  end
end

#create_maskObject



54
55
56
57
58
# File 'lib/carray-dataframe/cadf_array.rb', line 54

def create_mask
  @column_names.each do |name|
     @column_data[name].instance_eval{ __create_mask__ }
  end
end

#fetch_index(idx) ⇒ Object



24
25
26
27
28
# File 'lib/carray-dataframe/cadf_array.rb', line 24

def fetch_index (idx)
  r, c = *idx
  name = @column_names[c]
  return @column_data[name].value[r]
end

#fill_data(value) ⇒ Object



48
49
50
51
52
# File 'lib/carray-dataframe/cadf_array.rb', line 48

def fill_data (value)
  @column_names.each do |name|
    @column_data[name] = value
  end
end

#mask_copy_data(data) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/carray-dataframe/cadf_array.rb', line 80

def mask_copy_data (data)
  @column_names.each_with_index do |name, i|
    if @column_data[name].has_mask?
      data[nil,i] = @column_data[name].mask
    end
  end
end

#mask_fetch_index(idx) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/carray-dataframe/cadf_array.rb', line 60

def mask_fetch_index (idx)
  r, c = *idx
  name = @column_names[c]
  if @column_data[name].has_mask?
    return @column_data[name].mask[r]
  else
    return 0
  end
end

#mask_fill_data(value) ⇒ Object



94
95
96
97
98
# File 'lib/carray-dataframe/cadf_array.rb', line 94

def mask_fill_data (value)
  @column_names.each do |name|
    @column_data[name].mask[] = value
  end
end

#mask_store_index(idx, value) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/carray-dataframe/cadf_array.rb', line 70

def mask_store_index (idx, value)
  r, c = *idx
  name = @column_names[c]
  if @column_data[name].has_mask?
    return @column_data[name].mask[r] = value
  else
    @column_data[name].mask[r] = value
  end
end

#mask_sync_data(data) ⇒ Object



88
89
90
91
92
# File 'lib/carray-dataframe/cadf_array.rb', line 88

def mask_sync_data (data)
  @column_names.each_with_index do |name, i|
    @column_data[name].mask[] = data[nil,i]
  end
end

#store_index(idx, value) ⇒ Object



30
31
32
33
34
# File 'lib/carray-dataframe/cadf_array.rb', line 30

def store_index (idx, value)
  r, c = *idx
  name = @column_names[c]
  return @column_data[name][r] = value
end

#sync_data(data) ⇒ Object



42
43
44
45
46
# File 'lib/carray-dataframe/cadf_array.rb', line 42

def sync_data (data)
  @column_names.each_with_index do |name, i|
    @column_data[name].value[] = data[nil,i]
  end
end

#to_caObject



100
101
102
103
104
105
# File 'lib/carray-dataframe/cadf_array.rb', line 100

def to_ca
  obj = super
  obj.extend CArray::TableMethods
  obj.column_names = @column_names
  return obj
end