41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/object_table/table_methods.rb', line 41
def set_column(name, value, *args)
column = get_column(name)
new_column = column.nil?
value = value.to_a if value.is_a?(Range)
is_vector = (value.is_a?(Array) or value.is_a?(NArray))
if new_column
if is_vector and args.empty?
value = NArray.to_na(value)
unless (value.shape[-1] or 0) == nrows
raise ArgumentError.new("Expected size of last dimension to be #{nrows}, was #{value.shape[-1].inspect}")
end
args = [value.typecode] + value.shape[0...-1]
end
column = add_column(name, *args)
end
return column if column.empty? and (!is_vector or value.empty?)
begin
column[] = value
rescue Exception => e
pop_column(name) if new_column
raise e
end
end
|