33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/object_table.rb', line 33
def stack!(*others)
new_values = Hash[colnames.zip(ncols.times.map{[]})]
others.each do |x|
case x
when ObjectTable::TableMethods
x = x.columns
when ObjectTable::BasicGrid
x._ensure_uniform_columns!
end
raise "Don't know how to append a #{x.class}" unless x.is_a?(ObjectTable::BasicGrid)
next if x.empty?
raise 'Mismatch in column names' unless (colnames | x.keys) == (colnames & x.keys)
x.each do |k, v|
new_values[k].push NArray.to_na(v)
end
end
return self if new_values.empty?
new_rows = new_values.values.first.map{|x| x.shape[-1]}.reduce(:+)
return self unless (new_rows and new_rows != 0)
new_rows += nrows
new_values.each do |k, v|
@columns[k] = @columns[k].stack(*v)
end
self
end
|