14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/rust/core/csv.rb', line 14
def self.read(filename, **options)
hash = {}
labels = nil
infer_numbers = options.has_key?(:infer_numbers) ? options.delete(:infer_numbers) : true
infer_integers = options.delete(:infer_integers)
::CSV.foreach(filename, **options) do |row|
unless options[:headers]
options[:headers] = (1..row.size).to_a.map { |e| "X#{e}" }
return CSV.read(filename, **options)
end
unless labels
labels = row.
labels.each do |label|
hash[label] = []
end
end
labels.each do |label|
hash[label] << row[label]
end
end
result = Rust::DataFrame.new(hash)
if infer_numbers
result = self.auto_infer_types(result, infer_integers)
end
return result
end
|