daru 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.build.sh +6 -6
- data/.gitignore +2 -0
- data/CONTRIBUTING.md +7 -3
- data/History.md +36 -0
- data/README.md +21 -13
- data/Rakefile +16 -1
- data/benchmarks/TradeoffData.csv +65 -0
- data/benchmarks/dataframe_creation.rb +39 -0
- data/benchmarks/group_by.rb +32 -0
- data/benchmarks/row_access.rb +41 -0
- data/benchmarks/row_assign.rb +36 -0
- data/benchmarks/sorting.rb +44 -0
- data/benchmarks/vector_access.rb +31 -0
- data/benchmarks/vector_assign.rb +42 -0
- data/benchmarks/where_clause.rb +48 -0
- data/benchmarks/where_vs_filter.rb +28 -0
- data/daru.gemspec +29 -5
- data/lib/daru.rb +30 -1
- data/lib/daru/accessors/array_wrapper.rb +2 -2
- data/lib/daru/accessors/nmatrix_wrapper.rb +6 -6
- data/lib/daru/core/group_by.rb +112 -31
- data/lib/daru/core/merge.rb +170 -0
- data/lib/daru/core/query.rb +95 -0
- data/lib/daru/dataframe.rb +335 -223
- data/lib/daru/date_time/index.rb +550 -0
- data/lib/daru/date_time/offsets.rb +397 -0
- data/lib/daru/index.rb +266 -54
- data/lib/daru/io/io.rb +1 -2
- data/lib/daru/maths/arithmetic/dataframe.rb +2 -2
- data/lib/daru/maths/arithmetic/vector.rb +2 -2
- data/lib/daru/maths/statistics/dataframe.rb +58 -8
- data/lib/daru/maths/statistics/vector.rb +229 -0
- data/lib/daru/vector.rb +230 -80
- data/lib/daru/version.rb +1 -1
- data/spec/core/group_by_spec.rb +16 -16
- data/spec/core/merge_spec.rb +52 -0
- data/spec/core/query_spec.rb +171 -0
- data/spec/dataframe_spec.rb +278 -280
- data/spec/date_time/data_spec.rb +199 -0
- data/spec/date_time/index_spec.rb +433 -0
- data/spec/date_time/offsets_spec.rb +371 -0
- data/spec/fixtures/stock_data.csv +500 -0
- data/spec/index_spec.rb +317 -11
- data/spec/io/io_spec.rb +18 -17
- data/spec/math/arithmetic/dataframe_spec.rb +3 -3
- data/spec/math/statistics/dataframe_spec.rb +39 -1
- data/spec/math/statistics/vector_spec.rb +163 -1
- data/spec/monkeys_spec.rb +4 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/vector_spec.rb +125 -60
- metadata +71 -14
- data/lib/daru/accessors/dataframe_by_vector.rb +0 -17
- data/lib/daru/multi_index.rb +0 -216
- data/spec/multi_index_spec.rb +0 -216
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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sameer Deshmukh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: reportbuilder
|
@@ -66,6 +66,34 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.10'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: rserve-client
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -151,23 +179,26 @@ dependencies:
|
|
151
179
|
- !ruby/object:Gem::Version
|
152
180
|
version: '0.7'
|
153
181
|
- !ruby/object:Gem::Dependency
|
154
|
-
name: gsl
|
182
|
+
name: rb-gsl
|
155
183
|
requirement: !ruby/object:Gem::Requirement
|
156
184
|
requirements:
|
157
185
|
- - "~>"
|
158
186
|
- !ruby/object:Gem::Version
|
159
|
-
version: '1.
|
187
|
+
version: '1.16'
|
160
188
|
type: :development
|
161
189
|
prerelease: false
|
162
190
|
version_requirements: !ruby/object:Gem::Requirement
|
163
191
|
requirements:
|
164
192
|
- - "~>"
|
165
193
|
- !ruby/object:Gem::Version
|
166
|
-
version: '1.
|
167
|
-
description:
|
168
|
-
|
169
|
-
|
170
|
-
|
194
|
+
version: '1.16'
|
195
|
+
description: |
|
196
|
+
Daru (Data Analysis in RUby) is a library for analysis, manipulation and visualization
|
197
|
+
of data. Daru works seamlessly accross interpreters and leverages interpreter-specific
|
198
|
+
optimizations whenever they are available.
|
199
|
+
|
200
|
+
It is the default data storage gem for all the statsample gems (glm, timeseries, etc.)
|
201
|
+
and can be used with many others like mixed_models, gnuplotrb, nyaplot and iruby.
|
171
202
|
email:
|
172
203
|
- sameer.deshmukh93@gmail.com
|
173
204
|
executables: []
|
@@ -184,16 +215,29 @@ files:
|
|
184
215
|
- LICENSE
|
185
216
|
- README.md
|
186
217
|
- Rakefile
|
218
|
+
- benchmarks/TradeoffData.csv
|
219
|
+
- benchmarks/dataframe_creation.rb
|
220
|
+
- benchmarks/group_by.rb
|
221
|
+
- benchmarks/row_access.rb
|
222
|
+
- benchmarks/row_assign.rb
|
223
|
+
- benchmarks/sorting.rb
|
224
|
+
- benchmarks/vector_access.rb
|
225
|
+
- benchmarks/vector_assign.rb
|
226
|
+
- benchmarks/where_clause.rb
|
227
|
+
- benchmarks/where_vs_filter.rb
|
187
228
|
- daru.gemspec
|
188
229
|
- lib/daru.rb
|
189
230
|
- lib/daru/accessors/array_wrapper.rb
|
190
231
|
- lib/daru/accessors/dataframe_by_row.rb
|
191
|
-
- lib/daru/accessors/dataframe_by_vector.rb
|
192
232
|
- lib/daru/accessors/gsl_wrapper.rb
|
193
233
|
- lib/daru/accessors/mdarray_wrapper.rb
|
194
234
|
- lib/daru/accessors/nmatrix_wrapper.rb
|
195
235
|
- lib/daru/core/group_by.rb
|
236
|
+
- lib/daru/core/merge.rb
|
237
|
+
- lib/daru/core/query.rb
|
196
238
|
- lib/daru/dataframe.rb
|
239
|
+
- lib/daru/date_time/index.rb
|
240
|
+
- lib/daru/date_time/offsets.rb
|
197
241
|
- lib/daru/extensions/rserve.rb
|
198
242
|
- lib/daru/index.rb
|
199
243
|
- lib/daru/io/io.rb
|
@@ -202,15 +246,19 @@ files:
|
|
202
246
|
- lib/daru/maths/statistics/dataframe.rb
|
203
247
|
- lib/daru/maths/statistics/vector.rb
|
204
248
|
- lib/daru/monkeys.rb
|
205
|
-
- lib/daru/multi_index.rb
|
206
249
|
- lib/daru/plotting/dataframe.rb
|
207
250
|
- lib/daru/plotting/vector.rb
|
208
251
|
- lib/daru/vector.rb
|
209
252
|
- lib/daru/version.rb
|
210
253
|
- spec/accessors/wrappers_spec.rb
|
211
254
|
- spec/core/group_by_spec.rb
|
255
|
+
- spec/core/merge_spec.rb
|
256
|
+
- spec/core/query_spec.rb
|
212
257
|
- spec/daru_spec.rb
|
213
258
|
- spec/dataframe_spec.rb
|
259
|
+
- spec/date_time/data_spec.rb
|
260
|
+
- spec/date_time/index_spec.rb
|
261
|
+
- spec/date_time/offsets_spec.rb
|
214
262
|
- spec/extensions/rserve_spec.rb
|
215
263
|
- spec/fixtures/bank2.dat
|
216
264
|
- spec/fixtures/countries.json
|
@@ -219,6 +267,7 @@ files:
|
|
219
267
|
- spec/fixtures/repeated_fields.csv
|
220
268
|
- spec/fixtures/sales-funnel.csv
|
221
269
|
- spec/fixtures/scientific_notation.csv
|
270
|
+
- spec/fixtures/stock_data.csv
|
222
271
|
- spec/fixtures/test_xls.xls
|
223
272
|
- spec/index_spec.rb
|
224
273
|
- spec/io/io_spec.rb
|
@@ -227,14 +276,17 @@ files:
|
|
227
276
|
- spec/math/statistics/dataframe_spec.rb
|
228
277
|
- spec/math/statistics/vector_spec.rb
|
229
278
|
- spec/monkeys_spec.rb
|
230
|
-
- spec/multi_index_spec.rb
|
231
279
|
- spec/spec_helper.rb
|
232
280
|
- spec/vector_spec.rb
|
233
281
|
homepage: http://github.com/v0dro/daru
|
234
282
|
licenses:
|
235
283
|
- BSD-2
|
236
284
|
metadata: {}
|
237
|
-
post_install_message:
|
285
|
+
post_install_message: "*************************************************************************\nThank
|
286
|
+
you for installing daru!\n\n oOOOOOo \n ,| oO\n//| |\n\\| |\n `| |\n
|
287
|
+
\ `-----`\n\n\nHope you love daru! For enhanced interactivity and better visualizations,
|
288
|
+
\nconsider using gnuplotrb and nyaplot with iruby. For statistics use the \nstatsample
|
289
|
+
family.\n\nRead the README for interesting use cases and examples.\n\nCheers!\n*************************************************************************\n"
|
238
290
|
rdoc_options: []
|
239
291
|
require_paths:
|
240
292
|
- lib
|
@@ -257,8 +309,13 @@ summary: Data Analysis in RUby
|
|
257
309
|
test_files:
|
258
310
|
- spec/accessors/wrappers_spec.rb
|
259
311
|
- spec/core/group_by_spec.rb
|
312
|
+
- spec/core/merge_spec.rb
|
313
|
+
- spec/core/query_spec.rb
|
260
314
|
- spec/daru_spec.rb
|
261
315
|
- spec/dataframe_spec.rb
|
316
|
+
- spec/date_time/data_spec.rb
|
317
|
+
- spec/date_time/index_spec.rb
|
318
|
+
- spec/date_time/offsets_spec.rb
|
262
319
|
- spec/extensions/rserve_spec.rb
|
263
320
|
- spec/fixtures/bank2.dat
|
264
321
|
- spec/fixtures/countries.json
|
@@ -267,6 +324,7 @@ test_files:
|
|
267
324
|
- spec/fixtures/repeated_fields.csv
|
268
325
|
- spec/fixtures/sales-funnel.csv
|
269
326
|
- spec/fixtures/scientific_notation.csv
|
327
|
+
- spec/fixtures/stock_data.csv
|
270
328
|
- spec/fixtures/test_xls.xls
|
271
329
|
- spec/index_spec.rb
|
272
330
|
- spec/io/io_spec.rb
|
@@ -275,7 +333,6 @@ test_files:
|
|
275
333
|
- spec/math/statistics/dataframe_spec.rb
|
276
334
|
- spec/math/statistics/vector_spec.rb
|
277
335
|
- spec/monkeys_spec.rb
|
278
|
-
- spec/multi_index_spec.rb
|
279
336
|
- spec/spec_helper.rb
|
280
337
|
- spec/vector_spec.rb
|
281
338
|
has_rdoc:
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Daru
|
2
|
-
module Accessors
|
3
|
-
class DataFrameByVector
|
4
|
-
def initialize data_frame
|
5
|
-
@data_frame = data_frame
|
6
|
-
end
|
7
|
-
|
8
|
-
def [](*names)
|
9
|
-
@data_frame[*names, :vector]
|
10
|
-
end
|
11
|
-
|
12
|
-
def []=(name, vectors)
|
13
|
-
@data_frame[name, :vector] = vectors
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/lib/daru/multi_index.rb
DELETED
@@ -1,216 +0,0 @@
|
|
1
|
-
module Daru
|
2
|
-
# Class for holding multi index on Vector and DataFrame.
|
3
|
-
class MultiIndex
|
4
|
-
include Enumerable
|
5
|
-
|
6
|
-
def each(&block)
|
7
|
-
to_a.each(&block)
|
8
|
-
self
|
9
|
-
end
|
10
|
-
|
11
|
-
def map(&block)
|
12
|
-
to_a.map(&block)
|
13
|
-
end
|
14
|
-
|
15
|
-
attr_reader :relation_hash
|
16
|
-
attr_reader :size
|
17
|
-
attr_reader :values
|
18
|
-
|
19
|
-
# Initialize a MultiIndex by passing a tuple of indexes. The order assigned
|
20
|
-
# to the multi index corresponds to the position of the tuple in the array
|
21
|
-
# of tuples.
|
22
|
-
#
|
23
|
-
# Although you can create your own hierarchially indexed Vectors and DataFrames,
|
24
|
-
# this class currently contains minimal error checking and is mainly used
|
25
|
-
# internally for summarizing, splitting and grouping of data.
|
26
|
-
#
|
27
|
-
# == Arguments
|
28
|
-
#
|
29
|
-
# * +source+ - The array of arrays from which the multi index is to be created.
|
30
|
-
#
|
31
|
-
# == Usage
|
32
|
-
#
|
33
|
-
# tuples = [:a,:a,:b,:b].zip([:one,:two,:one,:two])
|
34
|
-
# #=> [[:a, :one], [:a, :two], [:b, :one], [:b, :two]]
|
35
|
-
# Daru::MultiIndex.new(tuples)
|
36
|
-
def initialize source, values=nil
|
37
|
-
@relation_hash = {}
|
38
|
-
@size = source.size
|
39
|
-
values = Array.new(source.size) { |i| i } if values.nil?
|
40
|
-
create_relation_hash source, values
|
41
|
-
@relation_hash.freeze
|
42
|
-
@values = values
|
43
|
-
end
|
44
|
-
|
45
|
-
def [] *indexes
|
46
|
-
indexes.flatten!
|
47
|
-
location = indexes[0]
|
48
|
-
|
49
|
-
if location.is_a?(Symbol)
|
50
|
-
result = read_relation_hash @relation_hash, indexes, 0
|
51
|
-
return nil if result.nil?
|
52
|
-
result.is_a?(Integer) ? result : Daru::MultiIndex.new(*make_tuples(result))
|
53
|
-
else
|
54
|
-
case location
|
55
|
-
when Integer
|
56
|
-
self[@relation_hash.keys[location]]
|
57
|
-
when Range
|
58
|
-
first = location.first
|
59
|
-
last = location.last
|
60
|
-
|
61
|
-
hsh = {}
|
62
|
-
first.upto(last) do |index|
|
63
|
-
key = @relation_hash.keys[index]
|
64
|
-
hsh[key] = read_relation_hash(@relation_hash, [key], 0)
|
65
|
-
end
|
66
|
-
Daru::MultiIndex.new(*make_tuples(hsh))
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def + other
|
72
|
-
other.flatten!
|
73
|
-
tuples = to_a
|
74
|
-
raise ArgumentError, "Incomplete tuple #{other}" unless
|
75
|
-
tuples.all? { |t| t.size == other.size }
|
76
|
-
|
77
|
-
Daru::MultiIndex.new(tuples << (other))
|
78
|
-
end
|
79
|
-
|
80
|
-
def empty?
|
81
|
-
@relation_hash.empty?
|
82
|
-
end
|
83
|
-
|
84
|
-
# Compare two MultiIndex objects for equality based on the contents of their
|
85
|
-
# relation hashes. Does not take object_id into account.
|
86
|
-
def == other
|
87
|
-
return false if size != other.size
|
88
|
-
deep_compare @relation_hash, other.relation_hash
|
89
|
-
end
|
90
|
-
|
91
|
-
# Convert a MultiIndex back to tuples (array of arrays). Will retain the
|
92
|
-
# order of creation.
|
93
|
-
def to_a
|
94
|
-
make_tuples(@relation_hash)[0]
|
95
|
-
end
|
96
|
-
|
97
|
-
# Completely duplicate a MultiIndex object and its contents.
|
98
|
-
def dup
|
99
|
-
Daru::MultiIndex.new to_a
|
100
|
-
end
|
101
|
-
|
102
|
-
# Check whether a tuple or identifier number exists in the multi index.
|
103
|
-
# The argument *tuple* can either a complete or incomplete tuple, or a number.
|
104
|
-
def include? tuple
|
105
|
-
tuple = [tuple] unless tuple.is_a?(Array)
|
106
|
-
tuple.flatten!
|
107
|
-
!!read_relation_hash(@relation_hash, tuple, 0)
|
108
|
-
end
|
109
|
-
|
110
|
-
# Obtain the tuple that correponds with the indentifier number.
|
111
|
-
#
|
112
|
-
# == Arguments
|
113
|
-
#
|
114
|
-
# * +key+ - A number for which the tuple is to be obtained.
|
115
|
-
#
|
116
|
-
# == Usage
|
117
|
-
#
|
118
|
-
# mi.key(3) #=> [:a,:two,:baz]
|
119
|
-
def key key
|
120
|
-
tuple = find_tuple_for(@relation_hash, key)
|
121
|
-
tuple.empty? ? nil : tuple
|
122
|
-
end
|
123
|
-
|
124
|
-
def size
|
125
|
-
to_a.size
|
126
|
-
end
|
127
|
-
|
128
|
-
private
|
129
|
-
|
130
|
-
# Deep compare two hashes
|
131
|
-
def deep_compare this, other
|
132
|
-
if this == other
|
133
|
-
return true if this.is_a?(Integer) and other.is_a?(Integer)
|
134
|
-
this.each_key do |key|
|
135
|
-
deep_compare this[key], other[key]
|
136
|
-
end
|
137
|
-
else
|
138
|
-
return false
|
139
|
-
end
|
140
|
-
true
|
141
|
-
end
|
142
|
-
|
143
|
-
# Create tuples out of the relation hash based on the order of the identifier
|
144
|
-
# numbers. Returns an array of arrays containing the tuples and another
|
145
|
-
# containing their corresponding index numbers.
|
146
|
-
def make_tuples relation_hash
|
147
|
-
tuples = []
|
148
|
-
new_vals = []
|
149
|
-
values.each do |number|
|
150
|
-
tuple = find_tuple_for(relation_hash, number)
|
151
|
-
unless tuple.empty?
|
152
|
-
tuples << tuple
|
153
|
-
new_vals << number
|
154
|
-
end
|
155
|
-
end
|
156
|
-
[tuples,new_vals]
|
157
|
-
end
|
158
|
-
|
159
|
-
# Finds and returns a single tuple for a particular identifier number
|
160
|
-
def find_tuple_for relation_hash, number
|
161
|
-
tuple = []
|
162
|
-
search_for_number number, relation_hash, tuple
|
163
|
-
tuple.reverse
|
164
|
-
end
|
165
|
-
|
166
|
-
# Search for a number and store its corresponding tuple in *tuple*. Returns
|
167
|
-
# true if the number is successfully found.
|
168
|
-
def search_for_number number, relation_hash, tuple
|
169
|
-
found = false
|
170
|
-
relation_hash.each_key do |key|
|
171
|
-
value = relation_hash[key]
|
172
|
-
if value.is_a?(Hash)
|
173
|
-
if search_for_number(number, value, tuple)
|
174
|
-
tuple << key
|
175
|
-
found = true
|
176
|
-
end
|
177
|
-
elsif value == number
|
178
|
-
tuple << key
|
179
|
-
found = true
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
found
|
184
|
-
end
|
185
|
-
|
186
|
-
# Read the relation hash and return a sub-relation hash or the number to which
|
187
|
-
# indexes belogs to.
|
188
|
-
def read_relation_hash relation_hash, indexes, index
|
189
|
-
identifier = indexes[index]
|
190
|
-
value = relation_hash[identifier]
|
191
|
-
|
192
|
-
indexes[index+1].nil? ? value : read_relation_hash(value,indexes,index+1)
|
193
|
-
end
|
194
|
-
|
195
|
-
# Create the relation hash from supplied tuples.
|
196
|
-
def create_relation_hash source, values
|
197
|
-
source.each_with_index do |tuple, idx|
|
198
|
-
populate @relation_hash, tuple, 0, values[idx]
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
def populate relation_hash, tuple, index, number
|
203
|
-
identifier = tuple[index]
|
204
|
-
|
205
|
-
if identifier
|
206
|
-
if tuple[index+1]
|
207
|
-
relation_hash[identifier] ||= {}
|
208
|
-
else
|
209
|
-
relation_hash[identifier] = number
|
210
|
-
return
|
211
|
-
end
|
212
|
-
populate relation_hash[identifier], tuple, index+1, number
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
data/spec/multi_index_spec.rb
DELETED
@@ -1,216 +0,0 @@
|
|
1
|
-
require 'spec_helper.rb'
|
2
|
-
|
3
|
-
describe Daru::MultiIndex do
|
4
|
-
before(:each) do
|
5
|
-
@index_tuples = [
|
6
|
-
[:a,:one,:bar],
|
7
|
-
[:a,:one,:baz],
|
8
|
-
[:a,:two,:bar],
|
9
|
-
[:a,:two,:baz],
|
10
|
-
[:b,:one,:bar],
|
11
|
-
[:b,:two,:bar],
|
12
|
-
[:b,:two,:baz],
|
13
|
-
[:b,:one,:foo],
|
14
|
-
[:c,:one,:bar],
|
15
|
-
[:c,:one,:baz],
|
16
|
-
[:c,:two,:foo],
|
17
|
-
[:c,:two,:bar]
|
18
|
-
]
|
19
|
-
@multi_mi = Daru::MultiIndex.new(@index_tuples)
|
20
|
-
end
|
21
|
-
|
22
|
-
context "#initialize" do
|
23
|
-
it "creates 2 layer MultiIndex from tuples" do
|
24
|
-
tuples = [[:a, :one], [:a, :two], [:b, :one], [:b, :two], [:c, :one], [:c, :two]]
|
25
|
-
mi = Daru::MultiIndex.new(tuples)
|
26
|
-
expect(mi.relation_hash).to eq({
|
27
|
-
:a => {
|
28
|
-
:one => 0,
|
29
|
-
:two => 1
|
30
|
-
},
|
31
|
-
:b => {
|
32
|
-
:one => 2,
|
33
|
-
:two => 3
|
34
|
-
},
|
35
|
-
:c => {
|
36
|
-
:one => 4,
|
37
|
-
:two => 5
|
38
|
-
}
|
39
|
-
})
|
40
|
-
end
|
41
|
-
|
42
|
-
it "creates a triple layer MultiIndex from tuples" do
|
43
|
-
expect(@multi_mi.relation_hash).to eq({
|
44
|
-
:a => {
|
45
|
-
:one => {
|
46
|
-
:bar => 0,
|
47
|
-
:baz => 1
|
48
|
-
},
|
49
|
-
:two => {
|
50
|
-
:bar => 2,
|
51
|
-
:baz => 3
|
52
|
-
}
|
53
|
-
},
|
54
|
-
:b => {
|
55
|
-
:one => {
|
56
|
-
:bar => 4,
|
57
|
-
:foo => 7
|
58
|
-
},
|
59
|
-
:two => {
|
60
|
-
:bar => 5,
|
61
|
-
:baz => 6
|
62
|
-
}
|
63
|
-
},
|
64
|
-
:c => {
|
65
|
-
:one => {
|
66
|
-
:bar => 8,
|
67
|
-
:baz => 9
|
68
|
-
},
|
69
|
-
:two => {
|
70
|
-
:foo => 10,
|
71
|
-
:bar => 11,
|
72
|
-
}
|
73
|
-
}
|
74
|
-
})
|
75
|
-
end
|
76
|
-
|
77
|
-
it "accepts array index values externally" do
|
78
|
-
mi = Daru::MultiIndex.new([
|
79
|
-
[:a,:one,:bar],
|
80
|
-
[:a,:one,:baz],
|
81
|
-
[:a,:two,:bar],
|
82
|
-
[:a,:two,:baz],
|
83
|
-
[:b,:one,:bar]
|
84
|
-
], [6,3,1,2,9])
|
85
|
-
|
86
|
-
expect(mi[:a,:two,:baz]).to eq(2)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context "#size" do
|
91
|
-
it "returns size of MultiIndex" do
|
92
|
-
expect(@multi_mi.size).to eq(12)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
context "#[]" do
|
97
|
-
it "returns the row number when specifying the complete tuple" do
|
98
|
-
expect(@multi_mi[:a, :one, :baz]).to eq(1)
|
99
|
-
end
|
100
|
-
|
101
|
-
it "returns a MultiIndex when specifying incomplete tuple" do
|
102
|
-
expect(@multi_mi[:b]).to eq(Daru::MultiIndex.new([
|
103
|
-
[:one,:bar],
|
104
|
-
[:two,:bar],
|
105
|
-
[:two,:baz],
|
106
|
-
[:one,:foo]
|
107
|
-
], [4,5,6,7])
|
108
|
-
)
|
109
|
-
|
110
|
-
expect(@multi_mi[:b, :one]).to eq(Daru::MultiIndex.new([
|
111
|
-
[:bar],
|
112
|
-
[:foo]
|
113
|
-
], [4,7])
|
114
|
-
)
|
115
|
-
# TODO: Return Daru::Index if a single layer of indexes is present.
|
116
|
-
end
|
117
|
-
|
118
|
-
it "returns a MultiIndex when specifying as an integer index" do
|
119
|
-
expect(@multi_mi[1]).to eq(Daru::MultiIndex.new([
|
120
|
-
[:one,:bar],
|
121
|
-
[:two,:bar],
|
122
|
-
[:two,:baz],
|
123
|
-
[:one,:foo]
|
124
|
-
],[4,5,6,7])
|
125
|
-
)
|
126
|
-
end
|
127
|
-
|
128
|
-
it "supports numeric Ranges" do
|
129
|
-
expect(@multi_mi[0..1]).to eq(Daru::MultiIndex.new([
|
130
|
-
[:a,:one,:bar],
|
131
|
-
[:a,:one,:baz],
|
132
|
-
[:a,:two,:bar],
|
133
|
-
[:a,:two,:baz],
|
134
|
-
[:b,:one,:bar],
|
135
|
-
[:b,:two,:bar],
|
136
|
-
[:b,:two,:baz],
|
137
|
-
[:b,:one,:foo]
|
138
|
-
]))
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
context "#include?" do
|
143
|
-
it "checks if a completely specified tuple exists" do
|
144
|
-
expect(@multi_mi.include?([:a,:one,:bar])).to eq(true)
|
145
|
-
end
|
146
|
-
|
147
|
-
it "checks if a top layer incomplete tuple exists" do
|
148
|
-
expect(@multi_mi.include?([:a])).to eq(true)
|
149
|
-
end
|
150
|
-
|
151
|
-
it "checks if a middle layer incomplete tuple exists" do
|
152
|
-
expect(@multi_mi.include?([:a, :one])).to eq(true)
|
153
|
-
end
|
154
|
-
|
155
|
-
it "checks for non-existence of a tuple" do
|
156
|
-
expect(@multi_mi.include?([:boo])).to eq(false)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
context "#key" do
|
161
|
-
it "returns the tuple of the specified number" do
|
162
|
-
expect(@multi_mi.key(3)).to eq([:a,:two,:baz])
|
163
|
-
end
|
164
|
-
|
165
|
-
it "returns nil for non-existent pointer number" do
|
166
|
-
expect(@multi_mi.key(100)).to eq(nil)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
context "#to_a" do
|
171
|
-
it "returns tuples as an Array" do
|
172
|
-
expect(@multi_mi.to_a).to eq(@index_tuples)
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
context "#dup" do
|
177
|
-
it "completely duplicates the object" do
|
178
|
-
duplicate = @multi_mi.dup
|
179
|
-
|
180
|
-
expect(duplicate) .to eq(@multi_mi)
|
181
|
-
expect(duplicate.object_id).to_not eq(@multi_mi.object_id)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
context "#==" do
|
186
|
-
it "returns false for unequal MultiIndex comparisons" do
|
187
|
-
mi1 = Daru::MultiIndex.new([
|
188
|
-
[:a, :one, :bar],
|
189
|
-
[:a, :two, :baz],
|
190
|
-
[:b, :one, :foo],
|
191
|
-
[:b, :two, :bar]
|
192
|
-
])
|
193
|
-
mi2 = Daru::MultiIndex.new([
|
194
|
-
[:a, :two, :bar],
|
195
|
-
[:b, :one, :foo],
|
196
|
-
[:a, :one, :baz],
|
197
|
-
[:b, :two, :baz]
|
198
|
-
])
|
199
|
-
|
200
|
-
expect(mi1 == mi2).to eq(false)
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
context "#values" do
|
205
|
-
it "returns an array of indices in order" do
|
206
|
-
mi = Daru::MultiIndex.new([
|
207
|
-
[:a, :one, :bar],
|
208
|
-
[:a, :two, :baz],
|
209
|
-
[:b, :one, :foo],
|
210
|
-
[:b, :two, :bar]
|
211
|
-
], [3,5,1,6])
|
212
|
-
|
213
|
-
expect(mi.values).to eq([3,5,1,6])
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|