daru 0.0.2.3 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +10 -0
- data/README.md +17 -10
- data/Rakefile +5 -0
- data/daru.gemspec +2 -0
- data/lib/daru.rb +1 -1
- data/lib/daru/dataframe.rb +426 -146
- data/lib/daru/dataframe_by_row.rb +15 -0
- data/lib/daru/dataframe_by_vector.rb +15 -0
- data/lib/daru/index.rb +83 -0
- data/lib/daru/io.rb +30 -0
- data/lib/daru/monkeys.rb +18 -10
- data/lib/daru/vector.rb +178 -47
- data/lib/version.rb +1 -1
- data/spec/dataframe_spec.rb +550 -0
- data/spec/fixtures/countries.json +7794 -0
- data/spec/index_spec.rb +54 -0
- data/spec/io_spec.rb +49 -0
- data/spec/monkeys_spec.rb +6 -0
- data/spec/spec_helper.rb +10 -1
- data/spec/vector_spec.rb +155 -0
- metadata +47 -10
- data/spec/jruby/dataframe_spec.rb +0 -1
- data/spec/jruby/vector_spec.rb +0 -20
- data/spec/mri/dataframe_spec.rb +0 -139
- data/spec/mri/vector_spec.rb +0 -104
data/spec/index_spec.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Daru::Index do
|
4
|
+
context "#initialize" do
|
5
|
+
it "creates an Index from Array" do
|
6
|
+
idx = Daru::Index.new ['speaker', 'mic', 'guitar', 'amp']
|
7
|
+
|
8
|
+
expect(idx.to_a).to eq([:speaker, :mic, :guitar, :amp])
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "#size" do
|
13
|
+
it "correctly returns the size of the index" do
|
14
|
+
idx = Daru::Index.new ['speaker', 'mic', 'guitar', 'amp']
|
15
|
+
|
16
|
+
expect(idx.size).to eq(4)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "#re_index" do
|
21
|
+
before :each do
|
22
|
+
@old = Daru::Index.new [:bob, :fisher, :zakir]
|
23
|
+
end
|
24
|
+
it "returns a new index object" do
|
25
|
+
n = @old.re_index(@old + [:john, :shrinivas])
|
26
|
+
|
27
|
+
expect(n.object_id).not_to eq(@old.object_id)
|
28
|
+
expect(n.to_a).to eq([:bob, :fisher, :zakir, :john, :shrinivas])
|
29
|
+
end
|
30
|
+
|
31
|
+
it "does not over-ride existing indexes" do
|
32
|
+
n = @old.re_index(@old + :bob)
|
33
|
+
|
34
|
+
expect(n.object_id).not_to eq(@old.object_id)
|
35
|
+
expect(n.to_a) .to eq([:bob, :fisher, :zakir])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "#+" do
|
40
|
+
before :each do
|
41
|
+
@left = Daru::Index.new [:miles, :geddy, :eric]
|
42
|
+
@right = Daru::Index.new [:bob, :jimi, :richie]
|
43
|
+
end
|
44
|
+
|
45
|
+
it "adds 2 indexes and returns an Index" do
|
46
|
+
expect(@left + @right).to eq([:miles, :geddy, :eric, :bob, :jimi, :richie].to_index)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "adds an Index and an Array to return an Index" do
|
50
|
+
expect(@left + [:bob, :jimi, :richie]).to eq([:miles, :geddy, :eric,
|
51
|
+
:bob, :jimi, :richie].to_index)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/spec/io_spec.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Daru::DataFrame do
|
4
|
+
context ".from_csv" do
|
5
|
+
it "loads from a CSV file" do
|
6
|
+
df = Daru::DataFrame.from_csv('spec/fixtures/matrix_test.csv',
|
7
|
+
col_sep: ' ', headers: true) do |csv|
|
8
|
+
csv.convert do |field, info|
|
9
|
+
case info[:header]
|
10
|
+
when :true_transform
|
11
|
+
field.split(',').map { |s| s.to_f }
|
12
|
+
else
|
13
|
+
field
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
expect(df.vectors).to eq([:image_resolution, :true_transform, :mls].to_index)
|
19
|
+
expect(df.vector[:image_resolution].first).to eq(6.55779)
|
20
|
+
expect(df.vector[:true_transform].first[15]).to eq(1.0)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "JSON" do
|
25
|
+
it "loads parsed JSON" do
|
26
|
+
require 'json'
|
27
|
+
|
28
|
+
json = File.read 'spec/fixtures/countries.json'
|
29
|
+
df = Daru::DataFrame.new JSON.parse(json)
|
30
|
+
|
31
|
+
expect(df.vectors).to eq([
|
32
|
+
:name, :nativeName, :tld, :cca2, :ccn3, :cca3, :currency, :callingCode,
|
33
|
+
:capital, :altSpellings, :relevance, :region, :subregion, :language,
|
34
|
+
:languageCodes, :translations, :latlng, :demonym, :borders, :area].to_index)
|
35
|
+
|
36
|
+
expect(df.row[0][:name]).to eq("Afghanistan")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "#inspect" do
|
41
|
+
it "prints DataFrame pretty" do
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "#to_csv" do
|
47
|
+
# TODO
|
48
|
+
end
|
49
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/vector_spec.rb
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Daru::Vector do
|
4
|
+
context "#initialize" do
|
5
|
+
it "initializes from an Array" do
|
6
|
+
dv = Daru::Vector.new :ravan, [1,2,3,4,5], [:ek, :don, :teen, :char, :pach]
|
7
|
+
|
8
|
+
expect(dv.name) .to eq(:ravan)
|
9
|
+
expect(dv.index).to eq(Daru::Index.new [:ek, :don, :teen, :char, :pach])
|
10
|
+
end
|
11
|
+
|
12
|
+
it "accepts Index object" do
|
13
|
+
idx = Daru::Index.new [:yoda, :anakin, :obi, :padme, :r2d2]
|
14
|
+
|
15
|
+
dv = Daru::Vector.new :yoga, [1,2,3,4,5], idx
|
16
|
+
|
17
|
+
expect(dv.name) .to eq(:yoga)
|
18
|
+
expect(dv.index).to eq(idx)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "raises error for improper Index" do
|
22
|
+
expect {
|
23
|
+
dv = Daru::Vector.new :yoga, [1,2,3,4,5], [:i, :j, :k]
|
24
|
+
}.to raise_error
|
25
|
+
|
26
|
+
expect {
|
27
|
+
idx = Daru::Index.new [:i, :j, :k]
|
28
|
+
dv = Daru::Vector.new :yoga, [1,2,3,4,5], idx
|
29
|
+
}.to raise_error
|
30
|
+
end
|
31
|
+
|
32
|
+
it "initializes without specifying an index" do
|
33
|
+
dv = Daru::Vector.new :vishnu, [1,2,3,4,5]
|
34
|
+
|
35
|
+
expect(dv.index).to eq(Daru::Index.new [0,1,2,3,4])
|
36
|
+
end
|
37
|
+
|
38
|
+
it "inserts nils for extra indices" do
|
39
|
+
dv = Daru::Vector.new :yoga, [1,2,3], [0,1,2,3,4]
|
40
|
+
|
41
|
+
expect(dv).to eq([1,2,3,nil,nil].dv(:yoga))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "#[]" do
|
46
|
+
before :each do
|
47
|
+
@dv = Daru::Vector.new :yoga, [1,2,3,4,5], [:yoda, :anakin, :obi, :padme, :r2d2]
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns an element after passing an index" do
|
51
|
+
expect(@dv[:yoda]).to eq(1)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "returns an element after passing a numeric index" , :focus => true do
|
55
|
+
expect(@dv[0]).to eq(1)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns a vector with given indices for multiple indices" do
|
59
|
+
expect(@dv[:yoda, :anakin]).to eq(Daru::Vector.new(:yoga, [1,2],
|
60
|
+
[:yoda, :anakin]))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "#[]=" do
|
65
|
+
before :each do
|
66
|
+
@dv = Daru::Vector.new :yoga, [1,2,3,4,5], [:yoda, :anakin, :obi, :padme, :r2d2]
|
67
|
+
end
|
68
|
+
|
69
|
+
it "assigns at the specified index" do
|
70
|
+
@dv[:yoda] = 666
|
71
|
+
|
72
|
+
expect(@dv[:yoda]).to eq(666)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "assigns at the specified Integer index" do
|
76
|
+
@dv[0] = 666
|
77
|
+
|
78
|
+
expect(@dv[:yoda]).to eq(666)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "#concat" do
|
83
|
+
before :each do
|
84
|
+
@dv = Daru::Vector.new :yoga, [1,2,3,4,5], [:warwick, :thompson, :jackson, :fender, :esp]
|
85
|
+
end
|
86
|
+
|
87
|
+
it "concatenates a new element at the end of vector with index" do
|
88
|
+
@dv.concat 6, :ibanez
|
89
|
+
|
90
|
+
expect(@dv.index) .to eq(
|
91
|
+
[:warwick, :thompson, :jackson, :fender, :esp, :ibanez].to_index)
|
92
|
+
expect(@dv[:ibanez]).to eq(6)
|
93
|
+
expect(@dv[5]) .to eq(6)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "concatenates without index if index is default numeric" do
|
97
|
+
vector = Daru::Vector.new :nums, [1,2,3,4,5]
|
98
|
+
|
99
|
+
vector.concat 6
|
100
|
+
|
101
|
+
expect(vector.index).to eq([0,1,2,3,4,5].to_index)
|
102
|
+
expect(vector[5]) .to eq(6)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "raises error if index not specified and non-numeric index" do
|
106
|
+
expect {
|
107
|
+
@dv.concat 6
|
108
|
+
}.to raise_error
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context "#delete" do
|
113
|
+
it "deletes specified value in the vector" do
|
114
|
+
dv = Daru::Vector.new :a, [1,2,3,4,5]
|
115
|
+
|
116
|
+
dv.delete 3
|
117
|
+
|
118
|
+
expect(dv).to eq(Daru::Vector.new :a, [1,2,4,5])
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "#delete_at" do
|
123
|
+
before :each do
|
124
|
+
@dv = Daru::Vector.new :a, [1,2,3,4,5], [:one, :two, :three, :four, :five]
|
125
|
+
end
|
126
|
+
|
127
|
+
it "deletes element of specified index" do
|
128
|
+
@dv.delete_at :one
|
129
|
+
|
130
|
+
expect(@dv).to eq(Daru::Vector.new :a, [2,3,4,5], [:two, :three, :four, :five])
|
131
|
+
end
|
132
|
+
|
133
|
+
it "deletes element of specified integer index" do
|
134
|
+
@dv.delete_at 2
|
135
|
+
|
136
|
+
expect(@dv).to eq(Daru::Vector.new :a, [1,2,4,5], [:one, :two, :four, :five])
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "#index_of" do
|
141
|
+
it "returns index of specified value" do
|
142
|
+
dv = Daru::Vector.new :a, [1,2,3,4,5], [:one, :two, :three, :four, :five]
|
143
|
+
|
144
|
+
expect(dv.index_of(1)).to eq(:one)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context "#to_hash" do
|
149
|
+
it "returns the vector as a hash" do
|
150
|
+
dv = Daru::Vector.new :a, [1,2,3,4,5], [:one, :two, :three, :four, :five]
|
151
|
+
|
152
|
+
expect(dv.to_hash).to eq({one: 1, two: 2, three: 3, four: 4, five: 5})
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end if mri?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sameer Deshmukh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +52,20 @@ dependencies:
|
|
38
52
|
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: awesome_print
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: nmatrix
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -69,18 +97,25 @@ files:
|
|
69
97
|
- History.txt
|
70
98
|
- LICENSE
|
71
99
|
- README.md
|
100
|
+
- Rakefile
|
72
101
|
- daru.gemspec
|
73
102
|
- lib/daru.rb
|
74
103
|
- lib/daru/dataframe.rb
|
104
|
+
- lib/daru/dataframe_by_row.rb
|
105
|
+
- lib/daru/dataframe_by_vector.rb
|
106
|
+
- lib/daru/index.rb
|
107
|
+
- lib/daru/io.rb
|
75
108
|
- lib/daru/monkeys.rb
|
76
109
|
- lib/daru/vector.rb
|
77
110
|
- lib/version.rb
|
111
|
+
- spec/dataframe_spec.rb
|
112
|
+
- spec/fixtures/countries.json
|
78
113
|
- spec/fixtures/matrix_test.csv
|
79
|
-
- spec/
|
80
|
-
- spec/
|
81
|
-
- spec/
|
82
|
-
- spec/mri/vector_spec.rb
|
114
|
+
- spec/index_spec.rb
|
115
|
+
- spec/io_spec.rb
|
116
|
+
- spec/monkeys_spec.rb
|
83
117
|
- spec/spec_helper.rb
|
118
|
+
- spec/vector_spec.rb
|
84
119
|
homepage: http://github.com/v0dro/daru
|
85
120
|
licenses:
|
86
121
|
- BSD-2
|
@@ -106,9 +141,11 @@ signing_key:
|
|
106
141
|
specification_version: 4
|
107
142
|
summary: Data Analysis in RUby
|
108
143
|
test_files:
|
144
|
+
- spec/dataframe_spec.rb
|
145
|
+
- spec/fixtures/countries.json
|
109
146
|
- spec/fixtures/matrix_test.csv
|
110
|
-
- spec/
|
111
|
-
- spec/
|
112
|
-
- spec/
|
113
|
-
- spec/mri/vector_spec.rb
|
147
|
+
- spec/index_spec.rb
|
148
|
+
- spec/io_spec.rb
|
149
|
+
- spec/monkeys_spec.rb
|
114
150
|
- spec/spec_helper.rb
|
151
|
+
- spec/vector_spec.rb
|
@@ -1 +0,0 @@
|
|
1
|
-
# Tests if interpreter is JRuby
|
data/spec/jruby/vector_spec.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper.rb'
|
2
|
-
# Tests if interpreter is JRuby
|
3
|
-
|
4
|
-
describe Daru::Vector do
|
5
|
-
context ".initialize" do
|
6
|
-
it "creates a vector object with an MDArray" do
|
7
|
-
vector = Daru::Vector.new(MDArray.double([5], [1,2,3,4,5]), :uhura)
|
8
|
-
|
9
|
-
expect(vector[1]) .to eq(2)
|
10
|
-
expect(vector.name).to eq(:uhura)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "creates a vector object with a Hash with different values" do
|
14
|
-
vector = Daru::Vector.new({ sulu: MDArray.double([5], [1,2,3,4,5])})
|
15
|
-
|
16
|
-
expect(vector[1]) .to eq(2)
|
17
|
-
expect(vector.name).to eq(:sulu)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end if RUBY_ENGINE == 'jruby'
|
data/spec/mri/dataframe_spec.rb
DELETED
@@ -1,139 +0,0 @@
|
|
1
|
-
require 'spec_helper.rb'
|
2
|
-
|
3
|
-
describe Daru::DataFrame do
|
4
|
-
context "DataFrame of Array" do
|
5
|
-
|
6
|
-
before :each do
|
7
|
-
@df = Daru::DataFrame.new({a: Daru::Vector.new(1..3),
|
8
|
-
b: (50..52).daru_vector, b_bad: ['Jesse', 'Walter', 'Hank'].daru_vector},
|
9
|
-
[:b_bad, :a, :b], :muddler)
|
10
|
-
|
11
|
-
@vector = Daru::Vector.new 1..3, :a
|
12
|
-
end
|
13
|
-
|
14
|
-
it "checks for the size of DataFrame" do
|
15
|
-
expect(@df.size).to eq(3)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "raises exception for uneven vectors" do
|
19
|
-
expect do
|
20
|
-
df = Daru::DataFrame.new({a: (1..5).dv, b: [1,2,3].daru_vector})
|
21
|
-
end.to raise_error
|
22
|
-
end
|
23
|
-
|
24
|
-
it "returns vector by specifying as method" do
|
25
|
-
expect(@df.a).to eq(@vector)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "returns vector by specifying as index" do
|
29
|
-
expect(@df[:a]).to eq(@vector)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "returns vector by specifying as a column argument" do
|
33
|
-
expect(@df.column(:a)).to eq(@vector)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "returns a row" do
|
37
|
-
r = @df.row 0
|
38
|
-
|
39
|
-
expect(r).to eq({:b_bad=> "Jesse", :a=> 1, :b=> 50})
|
40
|
-
end
|
41
|
-
|
42
|
-
it "iterates over columns in the specified order" do
|
43
|
-
cols = []
|
44
|
-
df = @df.each_vector do |col|
|
45
|
-
expect(col.is_a?(Daru::Vector)).to be(true)
|
46
|
-
cols << col.name
|
47
|
-
end
|
48
|
-
|
49
|
-
expect(cols).to eq([:b_bad, :a, :b])
|
50
|
-
expect(df).to eq(@df)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "iterates over rows" do
|
54
|
-
@df.each_row do |row|
|
55
|
-
expect(row.size).to be(@df.fields.size)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
it "filters rows" do
|
60
|
-
res = @df.filter_rows(@df.name) { |row| row[:b] == 50 }
|
61
|
-
|
62
|
-
expect(res).to eq(Daru::DataFrame.new({a: [1].dv, b: [50].dv, b_bad: ['Jesse'].dv},
|
63
|
-
@df.fields, @df.name))
|
64
|
-
end
|
65
|
-
|
66
|
-
it "shows column fields" do
|
67
|
-
expect(@df.fields).to eq([:b_bad, :a, :b])
|
68
|
-
end
|
69
|
-
|
70
|
-
it "inserts a new vector" do
|
71
|
-
@df.insert_vector :c, Daru::Vector.new([3,6,9])
|
72
|
-
|
73
|
-
expect(@df.fields.include?(:c)).to be(true)
|
74
|
-
end
|
75
|
-
|
76
|
-
it "inserts a new row" do
|
77
|
-
@df.insert_row ["Fred",6, 6]
|
78
|
-
|
79
|
-
expect(@df.a.vector) .to eq([1,2,3,6])
|
80
|
-
expect(@df.b.vector) .to eq([50,51,52,6])
|
81
|
-
expect(@df.b_bad.vector).to eq(['Jesse', 'Walter', 'Hank', 'Fred'])
|
82
|
-
end
|
83
|
-
|
84
|
-
it "raises an error for inappropriate row insertion" do
|
85
|
-
expect { @df.insert_row [1,1] }.to raise_error
|
86
|
-
end
|
87
|
-
|
88
|
-
it "deletes a vector" do
|
89
|
-
@df.delete :a
|
90
|
-
|
91
|
-
expect(@df.fields.include? :a).to be(false)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "returns a DataFrame of requested fields" do
|
95
|
-
req = @df = Daru::DataFrame.new({a: Daru::Vector.new(1..3),
|
96
|
-
b: (50..52).daru_vector}, [:a, :b], :muddler)
|
97
|
-
|
98
|
-
expect(@df[:a, :b]).to eq(req)
|
99
|
-
end
|
100
|
-
|
101
|
-
it "creates DataFrame from Array" do
|
102
|
-
a_df = Daru::DataFrame.new({a: [1,2,3,4], b: [10,11,12,13]})
|
103
|
-
|
104
|
-
expect(a_df.a.is_a? Daru::Vector).to eq(true)
|
105
|
-
expect(a_df.a.vector).to eq([1,2,3,4])
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
context "Malformed DataFrame from Array" do
|
110
|
-
it "adds extra nil vectors from fields" do
|
111
|
-
df = Daru::DataFrame.new({a: (1..4).dv, b: (50..53).dv}, [:b, :a, :jazzy, :joe])
|
112
|
-
|
113
|
-
expect(df.fields).to eq([:b, :a, :jazzy, :joe])
|
114
|
-
expect(df.jazzy).to eq(([nil]*4).dv(:jazzy))
|
115
|
-
expect(df.joe).to eq(([nil]*4).dv(:joe))
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context "DataFrame from files" do
|
120
|
-
|
121
|
-
it "loads a DataFrame from CSV" do
|
122
|
-
df = Daru::DataFrame.from_csv('spec/fixtures/matrix_test.csv',
|
123
|
-
{col_sep: ' ', headers: true}) do |csv|
|
124
|
-
csv.convert do |field, info|
|
125
|
-
case info[:header]
|
126
|
-
when :true_transform
|
127
|
-
field.split(',').map { |s| s.to_f }
|
128
|
-
else
|
129
|
-
field
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
expect(df.fields).to eq([:image_resolution, :true_transform, :mls])
|
135
|
-
expect(df[:image_resolution].first).to eq(6.55779)
|
136
|
-
expect(df.column(:true_transform).first[15]).to eq(1.0)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end if RUBY_ENGINE == 'ruby'
|