daru_lite 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/daru_lite/dataframe.rb +1 -1
- data/lib/daru_lite/index/index.rb +1 -1
- data/lib/daru_lite/index/multi_index.rb +9 -0
- data/lib/daru_lite/version.rb +1 -1
- data/spec/data_frame/filterable_example.rb +174 -15
- data/spec/index/categorical_index_spec.rb +27 -8
- data/spec/index/index_spec.rb +16 -3
- data/spec/index/multi_index_spec.rb +85 -76
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe2a3da2352dd68322a62e048c7870ad34f243a31bcd0cf18725b15583e4c5e8
|
4
|
+
data.tar.gz: 889d0714e1188240f43dc741f2b58b0ce3fe8731a07b39ee4d366f54ce301f6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 370f64692790e1661642c2e40ec4b56baa8fd8ac000be5623293013b169b7d96c0e5d5fe122801bbea40945761710b0b94c148fae27c67a42ab1825683416876
|
7
|
+
data.tar.gz: ebb89b2307548a0deaeda39e8e72a899a0f4e20c0e5a5ee16515c7aaea5ac95e8f7da3dc752b80a7dba64ec2f4e19717ba3703c06ee0793111c36da968ed5b02
|
data/lib/daru_lite/dataframe.rb
CHANGED
@@ -289,8 +289,8 @@ module DaruLite
|
|
289
289
|
def delete_at_position(position)
|
290
290
|
raise IndexError, "Position #{position} does not exist." unless position < size
|
291
291
|
|
292
|
-
each_vector { |vector| vector.delete_at_position(position) }
|
293
292
|
@index = @index.delete_at(position)
|
293
|
+
each_vector { |vector| vector.delete_at_position(position) }
|
294
294
|
|
295
295
|
set_size
|
296
296
|
end
|
@@ -196,6 +196,15 @@ module DaruLite
|
|
196
196
|
DaruLite::MultiIndex.from_tuples(to_a + [indexes])
|
197
197
|
end
|
198
198
|
|
199
|
+
# Takes a positional value and returns a new Index without the element at given position
|
200
|
+
# @param position [Integer] positional value
|
201
|
+
# @return [object] index object
|
202
|
+
def delete_at(position)
|
203
|
+
indexes = to_a
|
204
|
+
indexes.delete_at(position)
|
205
|
+
self.class.from_tuples(indexes)
|
206
|
+
end
|
207
|
+
|
199
208
|
def reorder(new_order)
|
200
209
|
from = to_a
|
201
210
|
MultiIndex.from_tuples(new_order.map { |i| from[i] })
|
data/lib/daru_lite/version.rb
CHANGED
@@ -128,8 +128,6 @@ shared_examples_for 'a filterable DataFrame' do
|
|
128
128
|
end
|
129
129
|
|
130
130
|
describe "#keep_row_if" do
|
131
|
-
subject { df.keep_row_if { |row| row[:a] % 10 == 0 } }
|
132
|
-
|
133
131
|
let(:index) { [:one, :two, :three, :four, :five] }
|
134
132
|
let(:order) { [:a, :b, :c] }
|
135
133
|
let(:df) do
|
@@ -143,33 +141,194 @@ shared_examples_for 'a filterable DataFrame' do
|
|
143
141
|
)
|
144
142
|
end
|
145
143
|
|
146
|
-
|
144
|
+
shared_examples_for '#keep_row_if' do
|
145
|
+
before { subject }
|
146
|
+
|
147
147
|
it "keeps row if block evaluates to true" do
|
148
|
-
|
149
|
-
|
148
|
+
expect(df).to eq(expected_df)
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'returns correct index' do
|
152
|
+
expect(df.index).to eq(expected_index)
|
153
|
+
end
|
154
|
+
|
155
|
+
it "all vectors have the same index" do
|
156
|
+
expect(df.map(&:index)).to all(eq(expected_index))
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'a single row is removed' do
|
161
|
+
context DaruLite::Index do
|
162
|
+
subject { df.keep_row_if { |row| row.name != :four } }
|
163
|
+
|
164
|
+
let(:expected_index) { DaruLite::Index.new([:one, :two, :three, :five]) }
|
165
|
+
let(:expected_df) do
|
150
166
|
DaruLite::DataFrame.new(
|
151
|
-
{ b: [10, 12, 20], a: [50, 30, 30], c: [10, 20, 30] },
|
167
|
+
{ b: [10, 12, 20, 30], a: [50, 30, 30, 5], c: [10, 20, 30, 50] },
|
152
168
|
order:,
|
153
|
-
index:
|
169
|
+
index: expected_index
|
154
170
|
)
|
155
|
-
|
171
|
+
end
|
172
|
+
|
173
|
+
it_behaves_like '#keep_row_if'
|
174
|
+
end
|
175
|
+
|
176
|
+
context DaruLite::CategoricalIndex do
|
177
|
+
subject { df.keep_row_if { |row| row.name != :a } }
|
178
|
+
|
179
|
+
let (:index) { DaruLite::CategoricalIndex.new([:a, 1, 1, :a, :c]) }
|
180
|
+
let(:expected_index) { DaruLite::CategoricalIndex.new([1, 1, :c]) }
|
181
|
+
let(:expected_df) do
|
182
|
+
DaruLite::DataFrame.new(
|
183
|
+
{
|
184
|
+
b: [12, 20, 30],
|
185
|
+
a: [30, 30, 5],
|
186
|
+
c: [20, 30, 50]
|
187
|
+
},
|
188
|
+
order:,
|
189
|
+
index: expected_index
|
190
|
+
)
|
191
|
+
end
|
192
|
+
|
193
|
+
it_behaves_like '#keep_row_if'
|
194
|
+
end
|
195
|
+
|
196
|
+
context DaruLite::MultiIndex do
|
197
|
+
subject { df.keep_row_if { |row| !row.name.include?('two') } }
|
198
|
+
|
199
|
+
let(:index) do
|
200
|
+
DaruLite::MultiIndex.from_tuples([[:a, :one], [:a, :two], [:b, :one], [:b, :two], [:c, :one]])
|
201
|
+
end
|
202
|
+
let(:expected_index) do
|
203
|
+
DaruLite::MultiIndex.from_tuples([[:a, :one], [:b, :one], [:c, :one]])
|
204
|
+
end
|
205
|
+
let(:expected_df) do
|
206
|
+
DaruLite::DataFrame.new(
|
207
|
+
{
|
208
|
+
b: [10, 20, 30],
|
209
|
+
a: [50, 30, 5],
|
210
|
+
c: [10, 30, 50]
|
211
|
+
},
|
212
|
+
order:,
|
213
|
+
index: expected_index
|
214
|
+
)
|
215
|
+
end
|
216
|
+
|
217
|
+
it_behaves_like '#keep_row_if'
|
156
218
|
end
|
157
219
|
end
|
158
220
|
|
159
|
-
context
|
160
|
-
|
221
|
+
context 'several rows are removed' do
|
222
|
+
subject { df.keep_row_if { |row| row[:a] % 10 == 0 } }
|
161
223
|
|
162
|
-
|
163
|
-
|
164
|
-
|
224
|
+
context DaruLite::Index do
|
225
|
+
let(:expected_index) { DaruLite::Index.new([:one, :two, :three]) }
|
226
|
+
let(:expected_df) do
|
227
|
+
DaruLite::DataFrame.new(
|
228
|
+
{ b: [10, 12, 20], a: [50, 30, 30], c: [10, 20, 30] },
|
229
|
+
order:,
|
230
|
+
index: expected_index
|
231
|
+
)
|
232
|
+
end
|
233
|
+
|
234
|
+
it_behaves_like '#keep_row_if'
|
235
|
+
end
|
236
|
+
|
237
|
+
context DaruLite::CategoricalIndex do
|
238
|
+
let (:index) { DaruLite::CategoricalIndex.new([:a, 1, 1, :a, :c]) }
|
239
|
+
let(:expected_index) { DaruLite::CategoricalIndex.new([:a, 1, 1]) }
|
240
|
+
let(:expected_df) do
|
165
241
|
DaruLite::DataFrame.new(
|
166
242
|
{ b: [10, 12, 20], a: [50, 30, 30], c: [10, 20, 30] },
|
167
243
|
order:,
|
168
|
-
index:
|
244
|
+
index: expected_index
|
169
245
|
)
|
170
|
-
|
246
|
+
end
|
247
|
+
|
248
|
+
it_behaves_like '#keep_row_if'
|
249
|
+
end
|
250
|
+
|
251
|
+
context DaruLite::MultiIndex do
|
252
|
+
let(:index) { DaruLite::MultiIndex.from_tuples([[:a, :one], [:a, :two], [:b, :one], [:b, :two], [:c, :one]]) }
|
253
|
+
let(:expected_index) do
|
254
|
+
DaruLite::MultiIndex.from_tuples([[:a, :one], [:a, :two], [:b, :one]])
|
255
|
+
end
|
256
|
+
let(:expected_df) do
|
257
|
+
DaruLite::DataFrame.new(
|
258
|
+
{ b: [10, 12, 20], a: [50, 30, 30], c: [10, 20, 30] },
|
259
|
+
order:,
|
260
|
+
index: expected_index
|
261
|
+
)
|
262
|
+
end
|
263
|
+
|
264
|
+
it_behaves_like '#keep_row_if'
|
171
265
|
end
|
172
266
|
end
|
267
|
+
|
268
|
+
# context DaruLite::MultiIndex do
|
269
|
+
# subject { df.keep_row_if { |row| row.name != 'No answer' } }
|
270
|
+
|
271
|
+
# let(:df) do
|
272
|
+
# order = DaruLite::MultiIndex.from_tuples(
|
273
|
+
# [
|
274
|
+
# [:a, :total],
|
275
|
+
# [:a, "Male"],
|
276
|
+
# [:a, "Female"],
|
277
|
+
# [:a, "Prefer not to answer"],
|
278
|
+
# [:a, "No answer"],
|
279
|
+
# [:b, :total],
|
280
|
+
# [:b, "Male"],
|
281
|
+
# [:b, "Female"],
|
282
|
+
# [:b, "Prefer not to answer"],
|
283
|
+
# [:b, "No answer"],
|
284
|
+
# [:c, :total],
|
285
|
+
# [:c, "Male"],
|
286
|
+
# [:c, "Female"],
|
287
|
+
# [:c, "Prefer not to answer"],
|
288
|
+
# [:c, "No answer"]
|
289
|
+
# ]
|
290
|
+
# )
|
291
|
+
# index = [
|
292
|
+
# :base,
|
293
|
+
# "Single Malt Whisky",
|
294
|
+
# "Blended/ Other Whisky",
|
295
|
+
# "Vodka",
|
296
|
+
# "Cognac",
|
297
|
+
# "Brandy",
|
298
|
+
# "Rum",
|
299
|
+
# "Gin",
|
300
|
+
# "Tequila",
|
301
|
+
# "No answer",
|
302
|
+
# "NET"
|
303
|
+
# ]
|
304
|
+
# DaruLite::DataFrame.new(
|
305
|
+
# [
|
306
|
+
# [0.0, nil, nil, nil, nil, nil, nil, nil, nil],
|
307
|
+
# [nil, nil, nil, nil, nil, nil, nil, nil, nil],
|
308
|
+
# [nil, nil, nil, nil, nil, nil, nil, nil, nil],
|
309
|
+
# [nil, nil, nil, nil, nil, nil, nil, nil, nil],
|
310
|
+
# [nil, nil, nil, nil, nil, nil, nil, nil, nil],
|
311
|
+
# [Float::NAN, nil, nil, nil, nil, nil, nil, nil, nil],
|
312
|
+
# [nil, nil, nil, nil, nil, nil, nil, nil, nil],
|
313
|
+
# [nil, nil, nil, nil, nil, nil, nil, nil, nil],
|
314
|
+
# [nil, nil, nil, nil, nil, nil, nil, nil, nil],
|
315
|
+
# [nil, nil, nil, nil, nil, nil, nil, nil, nil],
|
316
|
+
# [0, nil, nil, nil, nil, nil, nil, nil, nil],
|
317
|
+
# [0, nil, nil, nil, nil, nil, nil, nil, nil],
|
318
|
+
# [0, nil, nil, nil, nil, nil, nil, nil, nil],
|
319
|
+
# [0, nil, nil, nil, nil, nil, nil, nil, nil],
|
320
|
+
# [0, nil, nil, nil, nil, nil, nil, nil, nil],
|
321
|
+
# ],
|
322
|
+
# index:,
|
323
|
+
# order:
|
324
|
+
# )
|
325
|
+
# end
|
326
|
+
|
327
|
+
# it "all vectors have the same index" do
|
328
|
+
# subject
|
329
|
+
# expect(df.map(&:index)).to all(eq(df.index))
|
330
|
+
# end
|
331
|
+
# end
|
173
332
|
end
|
174
333
|
|
175
334
|
describe "#keep_vector_if" do
|
@@ -1,36 +1,47 @@
|
|
1
1
|
require 'spec_helper.rb'
|
2
2
|
|
3
3
|
describe DaruLite::CategoricalIndex do
|
4
|
+
let(:index) { described_class.new(keys) }
|
5
|
+
let(:keys) { [:a, :b, :a, :a, :c] }
|
6
|
+
|
7
|
+
describe "#to_a" do
|
8
|
+
subject { index.to_a }
|
9
|
+
|
10
|
+
it { is_expected.to eq(keys) }
|
11
|
+
|
12
|
+
it 'the returns array is not a variable of the index' do
|
13
|
+
expect { subject << 'four' }.not_to change { index.to_a }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
4
17
|
context "#pos" do
|
5
18
|
context "when the category is non-numeric" do
|
6
|
-
let(:idx) { described_class.new [:a, :b, :a, :a, :c] }
|
7
|
-
|
8
19
|
context "single category" do
|
9
|
-
subject {
|
20
|
+
subject { index.pos :a }
|
10
21
|
|
11
22
|
it { is_expected.to eq [0, 2, 3] }
|
12
23
|
end
|
13
24
|
|
14
25
|
context "multiple categories" do
|
15
|
-
subject {
|
26
|
+
subject { index.pos :a, :c }
|
16
27
|
|
17
28
|
it { is_expected.to eq [0, 2, 3, 4] }
|
18
29
|
end
|
19
30
|
|
20
31
|
context "invalid category" do
|
21
|
-
it { expect {
|
32
|
+
it { expect { index.pos :e }.to raise_error IndexError }
|
22
33
|
end
|
23
34
|
|
24
35
|
context "positional index" do
|
25
|
-
it { expect(
|
36
|
+
it { expect(index.pos 0).to eq 0 }
|
26
37
|
end
|
27
38
|
|
28
39
|
context "invalid positional index" do
|
29
|
-
it { expect {
|
40
|
+
it { expect { index.pos 5 }.to raise_error IndexError }
|
30
41
|
end
|
31
42
|
|
32
43
|
context "multiple positional indexes" do
|
33
|
-
subject {
|
44
|
+
subject { index.pos 0, 1, 2 }
|
34
45
|
|
35
46
|
it { is_expected.to be_a Array }
|
36
47
|
its(:size) { is_expected.to eq 3 }
|
@@ -167,4 +178,12 @@ describe DaruLite::CategoricalIndex do
|
|
167
178
|
it { expect(idx.valid? :a, 1, 5).to eq false }
|
168
179
|
end
|
169
180
|
end
|
181
|
+
|
182
|
+
describe '#delete_at' do
|
183
|
+
subject { index.delete_at(3) }
|
184
|
+
|
185
|
+
let(:index) { described_class.new([:a, 1, :a, 1, 'c']) }
|
186
|
+
|
187
|
+
it { is_expected.to eq(described_class.new([:a, 1, :a, 'c'])) }
|
188
|
+
end
|
170
189
|
end
|
data/spec/index/index_spec.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'spec_helper.rb'
|
2
2
|
|
3
3
|
describe DaruLite::Index do
|
4
|
+
let(:index) { described_class.new(keys) }
|
5
|
+
let(:keys) { ['one', 'two', 'three'] }
|
6
|
+
|
4
7
|
context ".new" do
|
5
8
|
it "creates an Index object if Index-like data is supplied" do
|
6
9
|
i = DaruLite::Index.new [:one, 'one', 1, 2, :two]
|
@@ -147,6 +150,16 @@ describe DaruLite::Index do
|
|
147
150
|
end
|
148
151
|
end
|
149
152
|
|
153
|
+
describe "#to_a" do
|
154
|
+
subject { index.to_a }
|
155
|
+
|
156
|
+
it { is_expected.to eq(keys) }
|
157
|
+
|
158
|
+
it 'the returns array is not a variable of the index' do
|
159
|
+
expect { subject << 'four' }.not_to change { index.to_a }
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
150
163
|
context "#&" do
|
151
164
|
before :each do
|
152
165
|
@left = DaruLite::Index.new [:miles, :geddy, :eric]
|
@@ -390,11 +403,11 @@ describe DaruLite::Index do
|
|
390
403
|
end
|
391
404
|
|
392
405
|
describe '#delete_at' do
|
393
|
-
subject {
|
406
|
+
subject { index.delete_at(1) }
|
394
407
|
|
395
|
-
let(:
|
408
|
+
let(:index) { described_class.new([:a, :b, 1, 2]) }
|
396
409
|
|
397
|
-
it { is_expected.to eq
|
410
|
+
it { is_expected.to eq(described_class.new([:a, 1, 2])) }
|
398
411
|
end
|
399
412
|
|
400
413
|
context '#to_df' do
|
@@ -1,22 +1,22 @@
|
|
1
1
|
require 'spec_helper.rb'
|
2
2
|
|
3
3
|
describe DaruLite::MultiIndex do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
[:a
|
8
|
-
[:a
|
9
|
-
[:a
|
10
|
-
[:
|
11
|
-
[:b
|
12
|
-
[:b
|
13
|
-
[:b
|
14
|
-
[:
|
15
|
-
[:c
|
16
|
-
[:c
|
17
|
-
[:c
|
4
|
+
let(:index) { described_class.from_tuples(index_tuples) }
|
5
|
+
let(:index_tuples) do
|
6
|
+
[
|
7
|
+
[:a, :one, :bar],
|
8
|
+
[:a, :one, :baz],
|
9
|
+
[:a, :two, :bar],
|
10
|
+
[:a, :two, :baz],
|
11
|
+
[:b, :one, :bar],
|
12
|
+
[:b, :two, :bar],
|
13
|
+
[:b, :two, :baz],
|
14
|
+
[:b, :one, :foo],
|
15
|
+
[:c, :one, :bar],
|
16
|
+
[:c, :one, :baz],
|
17
|
+
[:c, :two, :foo],
|
18
|
+
[:c, :two, :bar]
|
18
19
|
]
|
19
|
-
@multi_mi = DaruLite::MultiIndex.from_tuples(@index_tuples)
|
20
20
|
end
|
21
21
|
|
22
22
|
context ".initialize" do
|
@@ -71,16 +71,16 @@ describe DaruLite::MultiIndex do
|
|
71
71
|
|
72
72
|
it "raises SizeError for wrong number of name" do
|
73
73
|
error_msg = "\'names\' and \'levels\' should be of same size. Size of the \'name\' array is 2 and size of the MultiIndex \'levels\' and \'labels\' is 3.\nIf you do not want to set name for particular level (say level \'i\') then put empty string on index \'i\' of the \'name\' Array."
|
74
|
-
expect {
|
74
|
+
expect { index.name = ['n1', 'n2'] }.to raise_error(SizeError, error_msg)
|
75
75
|
|
76
76
|
error_msg = "'names' and 'levels' should be of same size. Size of the 'name' array is 0 and size of the MultiIndex 'levels' and 'labels' is 3.\nIf you do not want to set name for particular level (say level 'i') then put empty string on index 'i' of the 'name' Array."
|
77
|
-
expect {
|
77
|
+
expect { index.name = [ ] }.to raise_error(SizeError, error_msg)
|
78
78
|
|
79
79
|
error_msg = "'names' and 'levels' should be of same size. Size of the 'name' array is 1 and size of the MultiIndex 'levels' and 'labels' is 3.\nIf you do not want to set name for particular level (say level 'i') then put empty string on index 'i' of the 'name' Array."
|
80
|
-
expect {
|
80
|
+
expect { index.name = [''] }.to raise_error(SizeError, error_msg)
|
81
81
|
|
82
82
|
error_msg = "'names' and 'levels' should be of same size. Size of the 'name' array is 4 and size of the MultiIndex 'levels' and 'labels' is 3."
|
83
|
-
expect {
|
83
|
+
expect { index.name = ['n1', 'n2', 'n3', 'n4'] }.to raise_error(SizeError, error_msg)
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
@@ -101,8 +101,8 @@ describe DaruLite::MultiIndex do
|
|
101
101
|
end
|
102
102
|
|
103
103
|
it "creates a triple layer MultiIndex from tuples" do
|
104
|
-
expect(
|
105
|
-
expect(
|
104
|
+
expect(index.levels).to eq([[:a,:b,:c], [:one, :two],[:bar,:baz,:foo]])
|
105
|
+
expect(index.labels).to eq([
|
106
106
|
[0,0,0,0,1,1,1,1,2,2,2,2],
|
107
107
|
[0,0,1,1,0,1,1,0,0,0,1,1],
|
108
108
|
[0,1,0,1,0,0,1,2,0,1,2,0]
|
@@ -132,23 +132,23 @@ describe DaruLite::MultiIndex do
|
|
132
132
|
|
133
133
|
context "#size" do
|
134
134
|
it "returns size of MultiIndex" do
|
135
|
-
expect(
|
135
|
+
expect(index.size).to eq(12)
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
139
|
context "#[]" do
|
140
140
|
it "returns the row number when specifying the complete tuple" do
|
141
|
-
expect(
|
141
|
+
expect(index[:a, :one, :baz]).to eq(1)
|
142
142
|
end
|
143
143
|
|
144
144
|
it "returns MultiIndex when specifying incomplete tuple" do
|
145
|
-
expect(
|
145
|
+
expect(index[:b]).to eq(DaruLite::MultiIndex.from_tuples([
|
146
146
|
[:b,:one,:bar],
|
147
147
|
[:b,:two,:bar],
|
148
148
|
[:b,:two,:baz],
|
149
149
|
[:b,:one,:foo]
|
150
150
|
]))
|
151
|
-
expect(
|
151
|
+
expect(index[:b, :one]).to eq(DaruLite::MultiIndex.from_tuples([
|
152
152
|
[:b,:one,:bar],
|
153
153
|
[:b,:one,:foo]
|
154
154
|
]))
|
@@ -156,7 +156,7 @@ describe DaruLite::MultiIndex do
|
|
156
156
|
end
|
157
157
|
|
158
158
|
it "returns MultiIndex when specifying wholly numeric ranges" do
|
159
|
-
expect(
|
159
|
+
expect(index[3..6]).to eq(DaruLite::MultiIndex.from_tuples([
|
160
160
|
[:a,:two,:baz],
|
161
161
|
[:b,:one,:bar],
|
162
162
|
[:b,:two,:bar],
|
@@ -165,11 +165,11 @@ describe DaruLite::MultiIndex do
|
|
165
165
|
end
|
166
166
|
|
167
167
|
it "raises error when specifying invalid index" do
|
168
|
-
expect {
|
169
|
-
expect {
|
170
|
-
expect {
|
171
|
-
expect {
|
172
|
-
expect {
|
168
|
+
expect { index[:a, :three] }.to raise_error IndexError
|
169
|
+
expect { index[:a, :one, :xyz] }.to raise_error IndexError
|
170
|
+
expect { index[:x] }.to raise_error IndexError
|
171
|
+
expect { index[:x, :one] }.to raise_error IndexError
|
172
|
+
expect { index[:x, :one, :bar] }.to raise_error IndexError
|
173
173
|
end
|
174
174
|
|
175
175
|
it "works with numerical first levels" do
|
@@ -189,93 +189,89 @@ describe DaruLite::MultiIndex do
|
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
192
|
+
describe "#to_a" do
|
193
|
+
subject { index.to_a }
|
194
|
+
|
195
|
+
it { is_expected.to eq(index_tuples) }
|
196
|
+
|
197
|
+
it 'the returns array is not a variable of the index' do
|
198
|
+
expect { subject << [:d, :one, :bar] }.not_to change { index.to_a }
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
192
202
|
context "#include?" do
|
193
203
|
it "checks if a completely specified tuple exists" do
|
194
|
-
expect(
|
204
|
+
expect(index.include?([:a,:one,:bar])).to eq(true)
|
195
205
|
end
|
196
206
|
|
197
207
|
it "checks if a top layer incomplete tuple exists" do
|
198
|
-
expect(
|
208
|
+
expect(index.include?([:a])).to eq(true)
|
199
209
|
end
|
200
210
|
|
201
211
|
it "checks if a middle layer incomplete tuple exists" do
|
202
|
-
expect(
|
212
|
+
expect(index.include?([:a, :one])).to eq(true)
|
203
213
|
end
|
204
214
|
|
205
215
|
it "checks for non-existence of completely specified tuple" do
|
206
|
-
expect(
|
216
|
+
expect(index.include?([:b, :two, :foo])).to eq(false)
|
207
217
|
end
|
208
218
|
|
209
219
|
it "checks for non-existence of a top layer incomplete tuple" do
|
210
|
-
expect(
|
220
|
+
expect(index.include?([:d])).to eq(false)
|
211
221
|
end
|
212
222
|
|
213
223
|
it "checks for non-existence of a middle layer incomplete tuple" do
|
214
|
-
expect(
|
224
|
+
expect(index.include?([:c, :three])).to eq(false)
|
215
225
|
end
|
216
226
|
end
|
217
227
|
|
218
228
|
context "#key" do
|
219
229
|
it "returns the tuple of the specified number" do
|
220
|
-
expect(
|
230
|
+
expect(index.key(3)).to eq([:a,:two,:baz])
|
221
231
|
end
|
222
232
|
|
223
233
|
it "returns nil for non-existent pointer number" do
|
224
234
|
expect {
|
225
|
-
|
235
|
+
index.key(100)
|
226
236
|
}.to raise_error ArgumentError
|
227
237
|
end
|
228
238
|
end
|
229
239
|
|
230
240
|
context "#to_a" do
|
231
241
|
it "returns tuples as an Array" do
|
232
|
-
expect(
|
242
|
+
expect(index.to_a).to eq(index_tuples)
|
233
243
|
end
|
234
244
|
end
|
235
245
|
|
236
246
|
context "#dup" do
|
237
247
|
it "completely duplicates the object" do
|
238
|
-
duplicate =
|
239
|
-
expect(duplicate) .to eq(
|
240
|
-
expect(duplicate.object_id).to_not eq(
|
248
|
+
duplicate = index.dup
|
249
|
+
expect(duplicate) .to eq(index)
|
250
|
+
expect(duplicate.object_id).to_not eq(index.object_id)
|
241
251
|
end
|
242
252
|
end
|
243
253
|
|
244
254
|
context "#inspect" do
|
245
255
|
context 'small index' do
|
246
|
-
subject {
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
its(:inspect) { is_expected.to eq %Q{
|
264
|
-
|#<DaruLite::MultiIndex(12x3)>
|
265
|
-
| a one bar
|
266
|
-
| baz
|
267
|
-
| two bar
|
268
|
-
| baz
|
269
|
-
| b one bar
|
270
|
-
| two bar
|
271
|
-
| baz
|
272
|
-
| one foo
|
273
|
-
| c one bar
|
274
|
-
| baz
|
275
|
-
| two foo
|
276
|
-
| bar
|
256
|
+
subject { index.inspect }
|
257
|
+
|
258
|
+
it do
|
259
|
+
is_expected.to eq %Q{
|
260
|
+
|#<DaruLite::MultiIndex(12x3)>
|
261
|
+
| a one bar
|
262
|
+
| baz
|
263
|
+
| two bar
|
264
|
+
| baz
|
265
|
+
| b one bar
|
266
|
+
| two bar
|
267
|
+
| baz
|
268
|
+
| one foo
|
269
|
+
| c one bar
|
270
|
+
| baz
|
271
|
+
| two foo
|
272
|
+
| bar
|
277
273
|
}.unindent
|
278
|
-
|
274
|
+
end
|
279
275
|
end
|
280
276
|
|
281
277
|
context 'large index' do
|
@@ -331,7 +327,7 @@ describe DaruLite::MultiIndex do
|
|
331
327
|
|
332
328
|
context 'multi index with name having empty string' do
|
333
329
|
subject {
|
334
|
-
|
330
|
+
DaruLite::MultiIndex.new(
|
335
331
|
levels: [[:a,:b,:c],[:one,:two],[:bar, :baz, :foo]],
|
336
332
|
labels: [
|
337
333
|
[0,0,0,0,1,1,1,1,2,2,2,2],
|
@@ -677,4 +673,17 @@ describe DaruLite::MultiIndex do
|
|
677
673
|
'col3' => %w[bar bar baz foo]
|
678
674
|
)}
|
679
675
|
end
|
676
|
+
|
677
|
+
describe '#delete_at' do
|
678
|
+
subject { index.delete_at(3)}
|
679
|
+
|
680
|
+
let(:index) do
|
681
|
+
DaruLite::MultiIndex.from_tuples([[:a, :one], [:a, :two], [:b, :one], [:b, :two], [:c, :one]])
|
682
|
+
end
|
683
|
+
let(:expected_index) do
|
684
|
+
DaruLite::MultiIndex.from_tuples([[:a, :one], [:a, :two], [:b, :one], [:c, :one]])
|
685
|
+
end
|
686
|
+
|
687
|
+
it { is_expected.to eq(expected_index) }
|
688
|
+
end
|
680
689
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daru_lite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Naude-Filonnière
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2024-09-
|
15
|
+
date: 2024-09-09 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activerecord
|