mikon 0.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +160 -0
- data/Rakefile +1 -0
- data/example/Mikon_Manipuration.ipynb +582 -0
- data/example/Mikon_stats.ipynb +352 -0
- data/example/Plotting.ipynb +503 -0
- data/lib/mikon.rb +9 -0
- data/lib/mikon/core/array.rb +139 -0
- data/lib/mikon/core/dataframe.rb +400 -0
- data/lib/mikon/core/index.rb +30 -0
- data/lib/mikon/core/series.rb +139 -0
- data/lib/mikon/pivot.rb +36 -0
- data/lib/mikon/plot.rb +66 -0
- data/lib/mikon/stats.rb +227 -0
- data/lib/mikon/version.rb +3 -0
- data/mikon.gemspec +26 -0
- data/spec/core/array_spec.rb +0 -0
- data/spec/core/dataframe_spec.rb +200 -0
- data/spec/core/series_spec.rb +0 -0
- data/spec/data/no_header.csv +2 -0
- data/spec/data/test.csv +3 -0
- data/spec/data/test.tsv +3 -0
- data/spec/spec_helper.rb +2 -0
- metadata +147 -0
data/mikon.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mikon/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mikon"
|
8
|
+
spec.version = Mikon::VERSION
|
9
|
+
spec.authors = ["Naoki Nishida"]
|
10
|
+
spec.email = ["domitry@gmail.com"]
|
11
|
+
spec.summary = %q{DataFrame library for Ruby}
|
12
|
+
spec.description = %q{DataFrame works with NMatrix, Statsample, and Nyaplot}
|
13
|
+
spec.homepage = "http://github.com/domitry/mikon"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "nmatrix", "~> 0.1.0.rc5"
|
22
|
+
spec.add_runtime_dependency "formatador", "~> 0.2.5"
|
23
|
+
spec.add_runtime_dependency "nyaplot", "~> 0.1.1"
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
File without changes
|
@@ -0,0 +1,200 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mikon::DataFrame do
|
4
|
+
before(:each) do
|
5
|
+
@df = Mikon::DataFrame.new([{a: 1, b: 5}, {a: 2, b: 2}, {a: 3, b: 4}])
|
6
|
+
end
|
7
|
+
|
8
|
+
context ".new" do
|
9
|
+
{
|
10
|
+
hash_in_array: [{a: 1, b: 2}, {a: 2, b: 3}, {a: 3, b: 4}],
|
11
|
+
darray_in_array: [[1, 2, 3], [2, 3, 4]].map{|column| Mikon::DArray.new(column)},
|
12
|
+
row_in_array: [1, 2, 3].map{|val| Mikon::Row.new([:a, :b], [val, val+1], [0, 1])},
|
13
|
+
array_in_array: [[1, 2, 3], [2, 3, 4]],
|
14
|
+
array_in_hash: {a: [1,2,3], b: [2,3,4]}
|
15
|
+
}.each do |name, input|
|
16
|
+
it "should accept " + name.to_s + " input" do
|
17
|
+
df = Mikon::DataFrame.new(input, labels: [:a, :b])
|
18
|
+
expect(df[:a].to_a).to eq([1, 2, 3])
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be able to be specified its indices" do
|
22
|
+
df = Mikon::DataFrame.new(input, index: [:a, :b, :c])
|
23
|
+
expect(df.index).to eq([:a, :b, :c])
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be able to be specified its labels" do
|
27
|
+
df = Mikon::DataFrame.new(input, labels: [:foo, :bar])
|
28
|
+
expect(df.labels).to eq([:foo, :bar])
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should assign unique id to each dataframe" do
|
32
|
+
df1, df2 = [0, 1].map{Mikon::DataFrame.new(input, labels: [:a, :b])}
|
33
|
+
expect(df1.name == df2.name).to eq(false)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context ".from_csv" do
|
39
|
+
it "should accept csv file" do
|
40
|
+
path = File.expand_path("../../data/test.csv", __FILE__)
|
41
|
+
df = Mikon::DataFrame.from_csv(path)
|
42
|
+
expect(df[:a].to_a).to eq([1, 3])
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should accept tsv file" do
|
46
|
+
path = File.expand_path("../../data/test.tsv", __FILE__)
|
47
|
+
df = Mikon::DataFrame.from_csv(path, col_sep: "\t")
|
48
|
+
expect(df[:a].to_a).to eq([1, 3])
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should accept no-header csv" do
|
52
|
+
path = File.expand_path("../../data/no_header.csv", __FILE__)
|
53
|
+
df = Mikon::DataFrame.from_csv(path, headers: [:a, :b])
|
54
|
+
expect(df[:a].to_a).to eq([1, 3])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "#head" do
|
59
|
+
it "should be return a partial dataframe" do
|
60
|
+
expect(@df.head(2).class).to eq(Mikon::DataFrame)
|
61
|
+
expect(@df.head(2)[:a].to_a).to eq([1, 2])
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should keep index number" do
|
65
|
+
expect(@df.head(2).index).to eq([0, 1])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "#tail" do
|
70
|
+
it "should be return a partial dataframe" do
|
71
|
+
expect(@df.tail(2).class).to eq(Mikon::DataFrame)
|
72
|
+
expect(@df.tail(2)[:a].to_a).to eq([2, 3])
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should keep index number" do
|
76
|
+
expect(@df.tail(2).index).to eq([1, 2])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "#length" do
|
81
|
+
it "should return the length of each column" do
|
82
|
+
@df.labels.each do |label|
|
83
|
+
expect(@df.length).to eq(@df[label].length)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "#[]" do
|
89
|
+
it "should return an instance of Mikon::Series if Symbol is passed" do
|
90
|
+
expect(@df[:a].to_a).to eq([1,2,3])
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should return partial dataframe if Array of Numerics is passed" do
|
94
|
+
expect(@df[0..1][:a].to_a).to eq([1,2])
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "#to_html" do
|
99
|
+
it "should return a valid html" do
|
100
|
+
html = @df.to_html
|
101
|
+
expect(html.count("<")).to eq(html.count(">"))
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "#to_json" do
|
106
|
+
it "should return a valid json" do
|
107
|
+
json = @df.to_json
|
108
|
+
expect(json.count("{")).to eq(json.count("}"))
|
109
|
+
expect(json.count("[")).to eq(json.count("]"))
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "#select" do
|
114
|
+
it "should return Enumurator if block is not passed" do
|
115
|
+
expect(@df.select.class).to eq(Enumerator)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should return partial dataframe" do
|
119
|
+
df = @df.select{ a < 2}
|
120
|
+
expect(df.class).to eq(Mikon::DataFrame)
|
121
|
+
expect(df.length).to eq(1)
|
122
|
+
expect(df[:a].to_a).to eq([1])
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context "#map" do
|
127
|
+
it "should return Enumurator if block is not passed" do
|
128
|
+
expect(@df.map.class).to eq(Enumerator)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should return an instance of Mikon::Series" do
|
132
|
+
series = @df.map{a*2}.name(:c)
|
133
|
+
expect(series.class).to eq(Mikon::Series)
|
134
|
+
expect(series.to_a).to eq([2, 4, 6])
|
135
|
+
expect(series.name).to eq(:c)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context "#all?" do
|
140
|
+
it "should accept Mikon::Row DSL" do
|
141
|
+
expect(@df.all?{a<=3 && b<0}).to eq(false)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context "#any?" do
|
146
|
+
it "should accept Mikon::Row DSL" do
|
147
|
+
expect(@df.any?{b<3}).to eq(true)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context "#sort_by" do
|
152
|
+
it "should accept Mikon::Row DSL" do
|
153
|
+
expect(@df.sort_by{b}.index).to eq([1, 2, 0])
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "#sort" do
|
158
|
+
it "should decide which column to sort with by the first argument" do
|
159
|
+
# b: [5, 2, 4]
|
160
|
+
expect(@df.sort(:b).index).to eq([1, 2, 0])
|
161
|
+
end
|
162
|
+
it "shoudl decide if do ascending sort by the second argument" do
|
163
|
+
expect(@df.sort(:b, false).index).to eq([1, 2, 0].reverse)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context "#insert_column" do
|
168
|
+
it "should use Mikon::Row DSL when block is passed" do
|
169
|
+
@df.insert_column(:c){a*2}
|
170
|
+
expect(@df[:c].to_a).to eq([2, 4, 6])
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should accept Array as a second argument" do
|
174
|
+
@df.insert_column(:c, [2, 4, 6])
|
175
|
+
expect(@df[:c].to_a).to eq([2, 4, 6])
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should accept Series as a second argument" do
|
179
|
+
@df.insert_column((@df[:a]*2).name(:c))
|
180
|
+
expect(@df[:c].to_a).to eq([2, 4, 6])
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context "row" do
|
185
|
+
it "should return row whose index is specified one" do
|
186
|
+
row = @df.row(1)
|
187
|
+
expect(row.class).to eq(Mikon::Row)
|
188
|
+
expect(row.index).to eq(1)
|
189
|
+
expect(row.labels).to eq([:a, :b])
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
context "#each_row" do
|
194
|
+
it "should be iterate row as Mikon::Row" do
|
195
|
+
check = []
|
196
|
+
@df.each_row{|row| check.push(row.is_a?(Mikon::Row))}
|
197
|
+
expect(check.all?{|val| val}).to eq(true)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
File without changes
|
data/spec/data/test.csv
ADDED
data/spec/data/test.tsv
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mikon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.rc1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Naoki Nishida
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nmatrix
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.0.rc5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.0.rc5
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: formatador
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.5
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.5
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nyaplot
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.1.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.1.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: DataFrame works with NMatrix, Statsample, and Nyaplot
|
84
|
+
email:
|
85
|
+
- domitry@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- example/Mikon_Manipuration.ipynb
|
96
|
+
- example/Mikon_stats.ipynb
|
97
|
+
- example/Plotting.ipynb
|
98
|
+
- lib/mikon.rb
|
99
|
+
- lib/mikon/core/array.rb
|
100
|
+
- lib/mikon/core/dataframe.rb
|
101
|
+
- lib/mikon/core/index.rb
|
102
|
+
- lib/mikon/core/series.rb
|
103
|
+
- lib/mikon/pivot.rb
|
104
|
+
- lib/mikon/plot.rb
|
105
|
+
- lib/mikon/stats.rb
|
106
|
+
- lib/mikon/version.rb
|
107
|
+
- mikon.gemspec
|
108
|
+
- spec/core/array_spec.rb
|
109
|
+
- spec/core/dataframe_spec.rb
|
110
|
+
- spec/core/series_spec.rb
|
111
|
+
- spec/data/no_header.csv
|
112
|
+
- spec/data/test.csv
|
113
|
+
- spec/data/test.tsv
|
114
|
+
- spec/spec_helper.rb
|
115
|
+
homepage: http://github.com/domitry/mikon
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 1.3.1
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.2.2
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: DataFrame library for Ruby
|
139
|
+
test_files:
|
140
|
+
- spec/core/array_spec.rb
|
141
|
+
- spec/core/dataframe_spec.rb
|
142
|
+
- spec/core/series_spec.rb
|
143
|
+
- spec/data/no_header.csv
|
144
|
+
- spec/data/test.csv
|
145
|
+
- spec/data/test.tsv
|
146
|
+
- spec/spec_helper.rb
|
147
|
+
has_rdoc:
|