daru 0.0.2.1 → 0.0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1106a4a4200cc9b58f8979f7e5c84549f88acf7
4
- data.tar.gz: c57bc9be84f3821f2327a78d20619818da750b9e
3
+ metadata.gz: 6266fb09be80748530baa8b92aface148f47bac6
4
+ data.tar.gz: 37f2301d6b3fed23b15e11c5608892935befb04e
5
5
  SHA512:
6
- metadata.gz: de39382a8aa349a97fdac79b9df6540a752095194adbae9a72a901401276d3ac9a200f658ce1c5af08936cefad2647494632e306710a7e1db7ed0f4827699b38
7
- data.tar.gz: 8a8a1abb43f9f1d7b6fa0b524572f6a32a01e71462c12e7247189c207872db2b5b1af0f75693410af74cc314148de673ae4b32d8870518829358766d45b86668
6
+ metadata.gz: fa67c4506dea445619c1cf79270c5194cd189da302705b8d0dcad6689b3c3717f08bc11ce15af9670c7245fc746b3ce8feb0e82ea22c69aa06bf8da15003f947
7
+ data.tar.gz: 17d35384cf2daf28eca33aef370789edf7854da821094207e3eda9732933889ce23a44777e9aa451e62c732048a472d74378affb97e1a193cfe235426d83428e
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ Gemfile.lock
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- daru (0.0.2)
4
+ daru (0.0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -31,7 +31,8 @@ Then switch to MRI, do a normal `bundle install` followed by `rspec` for testing
31
31
 
32
32
  ## Roadmap
33
33
 
34
- * Integration with IRuby
34
+ * Print dataframe in same order as fields.
35
+ * Return rows in same order as that of fields.
35
36
  * Automate testing for both MRI and JRuby.
36
37
  * Enable creation of DataFrame by only specifying an NMatrix/MDArray in initialize. Vector naming happens automatically (alphabetic) or is specified in an Array.
37
38
  * Add support for missing values in vectors.
@@ -43,3 +44,11 @@ Then switch to MRI, do a normal `bundle install` followed by `rspec` for testing
43
44
  - Creation of correlation, covariance matrices
44
45
  - Verification of data in a vector
45
46
  - Basic vector statistics - mean, median, variance, etc.
47
+ * Add indexing on vectors.
48
+ - Creation of vector by supplying an index-value hash.
49
+ - Auto generation of real numbered indices for any vector.
50
+ - Ability to separately specify index for each element of a vector.
51
+ - Runtime alteration of index.
52
+ * Indexing on DataFrame.
53
+ * Vector arithmetic - elementwise addition, subtraction, multiplication, division.
54
+ * Transpose a dataframe.
@@ -66,8 +66,24 @@ module Daru
66
66
 
67
67
  # end
68
68
 
69
- def [](name)
70
- column name
69
+ def [](*name)
70
+ unless name[1]
71
+ return column(name[0])
72
+ end
73
+
74
+ h = {}
75
+ req_fields = @fields & name
76
+
77
+ req_fields.each do |f|
78
+ h[f] = @vectors[f]
79
+ end
80
+
81
+ DataFrame.new h, req_fields, @name
82
+ end
83
+
84
+ def ==(other)
85
+ @name == other.name and @vectors == other.vectors and
86
+ @size == other.size and @fields == other.fields
71
87
  end
72
88
 
73
89
  def []=(name, vector)
@@ -90,21 +106,35 @@ module Daru
90
106
  end
91
107
 
92
108
  def each_row
93
- 0.upto(@size) do |index|
109
+ 0.upto(@size-1) do |index|
94
110
  yield row(index)
95
111
  end
112
+
113
+ self
96
114
  end
97
115
 
98
116
  def each_row_with_index
99
- 0.upto(@size) do |index|
117
+ 0.upto(@size-1) do |index|
100
118
  yield row(index), index
101
119
  end
120
+
121
+ self
102
122
  end
103
123
 
104
124
  def each_column
105
- @vectors.values.each do |column|
106
- yield column
125
+ @fields.each do |field|
126
+ yield @vectors[field]
107
127
  end
128
+
129
+ self
130
+ end
131
+
132
+ def each_column_with_name
133
+ @fields.each do |field|
134
+ yield @vectors[field], field
135
+ end
136
+
137
+ self
108
138
  end
109
139
 
110
140
  def insert_vector name, vector
@@ -127,6 +157,10 @@ module Daru
127
157
  def to_html(threshold=15)
128
158
  html = '<table>'
129
159
 
160
+ html += '<tr>'
161
+ @fields.each { |f| html.concat('<td>' + f.to_s + '</td>') }
162
+ html += '</tr>'
163
+
130
164
  self.each_row_with_index do |row, index|
131
165
  break if index > threshold and index <= @size
132
166
  html += '<tr>'
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Daru
2
- VERSION = "0.0.2.1"
2
+ VERSION = "0.0.2.2"
3
3
  end
@@ -5,7 +5,8 @@ describe Daru::DataFrame do
5
5
 
6
6
  before :each do
7
7
  @df = Daru::DataFrame.new({a: Daru::Vector.new(1..3),
8
- b: (50..52).daru_vector, b_bad: ['Jesse', 'Walter', 'Hank'].daru_vector})
8
+ b: (50..52).daru_vector, b_bad: ['Jesse', 'Walter', 'Hank'].daru_vector},
9
+ [:b_bad, :a, :b], :muddler)
9
10
 
10
11
  @vector = Daru::Vector.new 1..3, :a
11
12
  end
@@ -35,14 +36,18 @@ describe Daru::DataFrame do
35
36
  it "returns a row" do
36
37
  r = @df.row 0
37
38
 
38
- expect(r).to eq([1,50,'Jesse'])
39
+ expect(r).to eq(['Jesse',1,50])
39
40
  end
40
41
 
41
- it "iterates over columns" do
42
- @df.each_column do |col|
42
+ it "iterates over columns in the specified order" do
43
+ cols = []
44
+ df = @df.each_column do |col|
43
45
  expect(col.is_a?(Daru::Vector)).to be(true)
44
- expect([:a, :b, :b_bad].include? col.name).to be(true)
46
+ cols << col.name
45
47
  end
48
+
49
+ expect(cols).to eq([:b_bad, :a, :b])
50
+ expect(df).to eq(@df)
46
51
  end
47
52
 
48
53
  it "iterates over rows" do
@@ -52,7 +57,7 @@ describe Daru::DataFrame do
52
57
  end
53
58
 
54
59
  it "shows column fields" do
55
- expect(@df.fields).to eq([:a, :b, :b_bad])
60
+ expect(@df.fields).to eq([:b_bad, :a, :b])
56
61
  end
57
62
 
58
63
  it "inserts a new vector" do
@@ -62,7 +67,7 @@ describe Daru::DataFrame do
62
67
  end
63
68
 
64
69
  it "inserts a new row" do
65
- @df.insert_row [6,6,"Fred"]
70
+ @df.insert_row ["Fred",6, 6]
66
71
 
67
72
  expect(@df.a.vector) .to eq([1,2,3,6])
68
73
  expect(@df.b.vector) .to eq([50,51,52,6])
@@ -78,6 +83,13 @@ describe Daru::DataFrame do
78
83
 
79
84
  expect(@df.fields.include? :a).to be(false)
80
85
  end
86
+
87
+ it "returns a DataFrame of requested fields" do
88
+ req = @df = Daru::DataFrame.new({a: Daru::Vector.new(1..3),
89
+ b: (50..52).daru_vector}, [:a, :b], :muddler)
90
+
91
+ expect(@df[:a, :b]).to eq(req)
92
+ end
81
93
  end
82
94
 
83
95
  context "DataFrame loads from files" do
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.2.1
4
+ version: 0.0.2.2
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-10-09 00:00:00.000000000 Z
11
+ date: 2014-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -61,6 +61,7 @@ executables: []
61
61
  extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
+ - ".gitignore"
64
65
  - ".rspec"
65
66
  - ".travis.yml"
66
67
  - Gemfile