daru_lite 0.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.
Files changed (149) hide show
  1. checksums.yaml +7 -0
  2. data/.github/ISSUE_TEMPLATE.md +18 -0
  3. data/.github/workflows/ci.yml +33 -0
  4. data/.gitignore +10 -0
  5. data/.rspec +2 -0
  6. data/.rubocop.yml +27 -0
  7. data/.rubocop_todo.yml +137 -0
  8. data/CONTRIBUTING.md +47 -0
  9. data/Gemfile +2 -0
  10. data/History.md +4 -0
  11. data/LICENSE +24 -0
  12. data/README.md +218 -0
  13. data/Rakefile +69 -0
  14. data/ReleasePolicy.md +20 -0
  15. data/benchmarks/TradeoffData.csv +65 -0
  16. data/benchmarks/csv_reading.rb +22 -0
  17. data/benchmarks/dataframe_creation.rb +39 -0
  18. data/benchmarks/db_loading.rb +34 -0
  19. data/benchmarks/duplicating.rb +45 -0
  20. data/benchmarks/group_by.rb +32 -0
  21. data/benchmarks/joining.rb +52 -0
  22. data/benchmarks/row_access.rb +41 -0
  23. data/benchmarks/row_assign.rb +36 -0
  24. data/benchmarks/sorting.rb +51 -0
  25. data/benchmarks/statistics.rb +28 -0
  26. data/benchmarks/vector_access.rb +31 -0
  27. data/benchmarks/vector_assign.rb +42 -0
  28. data/benchmarks/where_clause.rb +48 -0
  29. data/benchmarks/where_vs_filter.rb +28 -0
  30. data/daru_lite.gemspec +55 -0
  31. data/images/README.md +5 -0
  32. data/images/con0.png +0 -0
  33. data/images/con1.png +0 -0
  34. data/images/init0.png +0 -0
  35. data/images/init1.png +0 -0
  36. data/images/man0.png +0 -0
  37. data/images/man1.png +0 -0
  38. data/images/man2.png +0 -0
  39. data/images/man3.png +0 -0
  40. data/images/man4.png +0 -0
  41. data/images/man5.png +0 -0
  42. data/images/man6.png +0 -0
  43. data/lib/daru_lite/accessors/array_wrapper.rb +109 -0
  44. data/lib/daru_lite/accessors/dataframe_by_row.rb +25 -0
  45. data/lib/daru_lite/accessors/mdarray_wrapper.rb +7 -0
  46. data/lib/daru_lite/category.rb +929 -0
  47. data/lib/daru_lite/configuration.rb +34 -0
  48. data/lib/daru_lite/core/group_by.rb +403 -0
  49. data/lib/daru_lite/core/merge.rb +270 -0
  50. data/lib/daru_lite/core/query.rb +109 -0
  51. data/lib/daru_lite/dataframe.rb +3080 -0
  52. data/lib/daru_lite/date_time/index.rb +569 -0
  53. data/lib/daru_lite/date_time/offsets.rb +397 -0
  54. data/lib/daru_lite/exceptions.rb +2 -0
  55. data/lib/daru_lite/extensions/which_dsl.rb +53 -0
  56. data/lib/daru_lite/formatters/table.rb +52 -0
  57. data/lib/daru_lite/helpers/array.rb +53 -0
  58. data/lib/daru_lite/index/categorical_index.rb +201 -0
  59. data/lib/daru_lite/index/index.rb +374 -0
  60. data/lib/daru_lite/index/multi_index.rb +374 -0
  61. data/lib/daru_lite/io/csv/converters.rb +21 -0
  62. data/lib/daru_lite/io/io.rb +294 -0
  63. data/lib/daru_lite/io/sql_data_source.rb +97 -0
  64. data/lib/daru_lite/iruby/helpers.rb +38 -0
  65. data/lib/daru_lite/iruby/templates/dataframe.html.erb +5 -0
  66. data/lib/daru_lite/iruby/templates/dataframe_mi.html.erb +5 -0
  67. data/lib/daru_lite/iruby/templates/dataframe_mi_tbody.html.erb +35 -0
  68. data/lib/daru_lite/iruby/templates/dataframe_mi_thead.html.erb +21 -0
  69. data/lib/daru_lite/iruby/templates/dataframe_tbody.html.erb +28 -0
  70. data/lib/daru_lite/iruby/templates/dataframe_thead.html.erb +21 -0
  71. data/lib/daru_lite/iruby/templates/multi_index.html.erb +12 -0
  72. data/lib/daru_lite/iruby/templates/vector.html.erb +5 -0
  73. data/lib/daru_lite/iruby/templates/vector_mi.html.erb +5 -0
  74. data/lib/daru_lite/iruby/templates/vector_mi_tbody.html.erb +26 -0
  75. data/lib/daru_lite/iruby/templates/vector_mi_thead.html.erb +8 -0
  76. data/lib/daru_lite/iruby/templates/vector_tbody.html.erb +17 -0
  77. data/lib/daru_lite/iruby/templates/vector_thead.html.erb +8 -0
  78. data/lib/daru_lite/maths/arithmetic/dataframe.rb +91 -0
  79. data/lib/daru_lite/maths/arithmetic/vector.rb +117 -0
  80. data/lib/daru_lite/maths/statistics/dataframe.rb +202 -0
  81. data/lib/daru_lite/maths/statistics/vector.rb +1019 -0
  82. data/lib/daru_lite/monkeys.rb +56 -0
  83. data/lib/daru_lite/vector.rb +1678 -0
  84. data/lib/daru_lite/version.rb +3 -0
  85. data/lib/daru_lite.rb +99 -0
  86. data/profile/_base.rb +23 -0
  87. data/profile/df_to_a.rb +10 -0
  88. data/profile/filter.rb +13 -0
  89. data/profile/joining.rb +13 -0
  90. data/profile/sorting.rb +12 -0
  91. data/profile/vector_each_with_index.rb +9 -0
  92. data/profile/vector_new.rb +9 -0
  93. data/spec/accessors/array_wrapper_spec.rb +3 -0
  94. data/spec/category_spec.rb +1741 -0
  95. data/spec/core/group_by_spec.rb +655 -0
  96. data/spec/core/merge_spec.rb +179 -0
  97. data/spec/core/query_spec.rb +347 -0
  98. data/spec/daru_lite_spec.rb +22 -0
  99. data/spec/dataframe_spec.rb +4330 -0
  100. data/spec/date_time/data_spec.rb +197 -0
  101. data/spec/date_time/date_time_index_helper_spec.rb +72 -0
  102. data/spec/date_time/index_spec.rb +588 -0
  103. data/spec/date_time/offsets_spec.rb +465 -0
  104. data/spec/extensions/which_dsl_spec.rb +38 -0
  105. data/spec/fixtures/bank2.dat +200 -0
  106. data/spec/fixtures/boolean_converter_test.csv +5 -0
  107. data/spec/fixtures/countries.json +7794 -0
  108. data/spec/fixtures/duplicates.csv +32 -0
  109. data/spec/fixtures/eciresults.html +394 -0
  110. data/spec/fixtures/empties.dat +2 -0
  111. data/spec/fixtures/empty_rows_test.csv +17 -0
  112. data/spec/fixtures/macau.html +3691 -0
  113. data/spec/fixtures/macd_data.csv +150 -0
  114. data/spec/fixtures/matrix_test.csv +100 -0
  115. data/spec/fixtures/moneycontrol.html +6812 -0
  116. data/spec/fixtures/music_data.tsv +2501 -0
  117. data/spec/fixtures/repeated_fields.csv +7 -0
  118. data/spec/fixtures/sales-funnel.csv +18 -0
  119. data/spec/fixtures/scientific_notation.csv +4 -0
  120. data/spec/fixtures/string_converter_test.csv +5 -0
  121. data/spec/fixtures/strings.dat +2 -0
  122. data/spec/fixtures/test_xls.xls +0 -0
  123. data/spec/fixtures/test_xls_2.xls +0 -0
  124. data/spec/fixtures/url_test.txt~ +0 -0
  125. data/spec/fixtures/valid_markup.html +62 -0
  126. data/spec/fixtures/wiki_climate.html +1243 -0
  127. data/spec/fixtures/wiki_table_info.html +631 -0
  128. data/spec/formatters/table_formatter_spec.rb +137 -0
  129. data/spec/helpers_spec.rb +8 -0
  130. data/spec/index/categorical_index_spec.rb +170 -0
  131. data/spec/index/index_spec.rb +417 -0
  132. data/spec/index/multi_index_spec.rb +680 -0
  133. data/spec/io/io_spec.rb +373 -0
  134. data/spec/io/sql_data_source_spec.rb +56 -0
  135. data/spec/iruby/dataframe_spec.rb +170 -0
  136. data/spec/iruby/helpers_spec.rb +49 -0
  137. data/spec/iruby/multi_index_spec.rb +37 -0
  138. data/spec/iruby/vector_spec.rb +105 -0
  139. data/spec/maths/arithmetic/dataframe_spec.rb +148 -0
  140. data/spec/maths/arithmetic/vector_spec.rb +165 -0
  141. data/spec/maths/statistics/dataframe_spec.rb +178 -0
  142. data/spec/maths/statistics/vector_spec.rb +756 -0
  143. data/spec/monkeys_spec.rb +42 -0
  144. data/spec/shared/vector_display_spec.rb +213 -0
  145. data/spec/spec_helper.rb +87 -0
  146. data/spec/support/database_helper.rb +30 -0
  147. data/spec/support/matchers.rb +5 -0
  148. data/spec/vector_spec.rb +2293 -0
  149. metadata +571 -0
@@ -0,0 +1,417 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe DaruLite::Index do
4
+ context ".new" do
5
+ it "creates an Index object if Index-like data is supplied" do
6
+ i = DaruLite::Index.new [:one, 'one', 1, 2, :two]
7
+ expect(i.class).to eq(DaruLite::Index)
8
+ expect(i.to_a) .to eq([:one, 'one', 1, 2, :two])
9
+ end
10
+
11
+ it "creates a MultiIndex if tuples are supplied" do
12
+ i = DaruLite::Index.new([
13
+ [:b,:one,:bar],
14
+ [:b,:two,:bar],
15
+ [:b,:two,:baz],
16
+ [:b,:one,:foo]
17
+ ])
18
+
19
+ expect(i.class).to eq(DaruLite::MultiIndex)
20
+ expect(i.levels).to eq([[:b], [:one, :two], [:bar, :baz, :foo]])
21
+ expect(i.labels).to eq([[0,0,0,0],[0,1,1,0],[0,0,1,2]])
22
+ end
23
+
24
+ it "creates DateTimeIndex if date-like objects specified" do
25
+ i = DaruLite::Index.new([
26
+ DateTime.new(2012,2,4), DateTime.new(2012,2,5), DateTime.new(2012,2,6)])
27
+ expect(i.class).to eq(DaruLite::DateTimeIndex)
28
+ expect(i.to_a).to eq([DateTime.new(2012,2,4), DateTime.new(2012,2,5), DateTime.new(2012,2,6)])
29
+ expect(i.frequency).to eq('D')
30
+ end
31
+
32
+ context "create an Index with name" do
33
+ context 'if no name is set' do
34
+ subject { DaruLite::Index.new [:a, :b, :c] }
35
+ its(:name) { is_expected.to be_nil }
36
+ end
37
+
38
+ context 'correctly return the index name' do
39
+ subject { DaruLite::Index.new [:a, :b, :c], name: 'index_name' }
40
+ its(:name) { is_expected.to eq 'index_name' }
41
+ end
42
+
43
+ context "set new index name" do
44
+ subject {
45
+ DaruLite::Index.new([:a, :b, :c], name: 'index_name') }
46
+ before { subject.name = 'new_name'}
47
+ its(:name) { is_expected.to eq 'new_name' }
48
+ end
49
+ end
50
+ end
51
+
52
+ context "#initialize" do
53
+ it "creates an Index from Array" do
54
+ idx = DaruLite::Index.new ['speaker', 'mic', 'guitar', 'amp']
55
+
56
+ expect(idx.to_a).to eq(['speaker', 'mic', 'guitar', 'amp'])
57
+ end
58
+
59
+ it "creates an Index from Range" do
60
+ idx = DaruLite::Index.new 1..5
61
+
62
+ expect(idx).to eq(DaruLite::Index.new [1, 2, 3, 4, 5])
63
+ end
64
+
65
+ it "raises ArgumentError on invalid input type" do
66
+ expect { DaruLite::Index.new 'foo' }.to raise_error ArgumentError
67
+ end
68
+
69
+ it "accepts all sorts of objects for Indexing" do
70
+ idx = DaruLite::Index.new [:a, 'a', :hello, '23', 23]
71
+
72
+ expect(idx.to_a).to eq([:a, 'a', :hello, '23', 23])
73
+ end
74
+ end
75
+
76
+ context '#key' do
77
+ subject(:idx) { DaruLite::Index.new ['speaker', 'mic', 'guitar', 'amp'] }
78
+
79
+ it 'returns key by position' do
80
+ expect(idx.key(2)).to eq 'guitar'
81
+ end
82
+
83
+ it 'returns nil on too large pos' do
84
+ expect(idx.key(20)).to be_nil
85
+ end
86
+
87
+ it 'returns nil on wrong arg type' do
88
+ expect(idx.key(nil)).to be_nil
89
+ end
90
+ end
91
+
92
+ context '#sort' do
93
+ let(:asc) { index.sort }
94
+ let(:desc) { index.sort(ascending: false) }
95
+
96
+ context 'string index' do
97
+ let(:index) { DaruLite::Index.new ['mic', 'amp', 'guitar', 'speaker'] }
98
+ specify { expect(asc).to eq DaruLite::Index.new ['amp', 'guitar', 'mic',
99
+ 'speaker'] }
100
+ specify { expect(desc).to eq DaruLite::Index.new ['speaker', 'mic', 'guitar',
101
+ 'amp'] }
102
+ end
103
+
104
+ context 'number index' do
105
+ let(:index) { DaruLite::Index.new [100, 99, 101, 1, 2] }
106
+ specify { expect(asc).to eq DaruLite::Index.new [1, 2, 99, 100, 101] }
107
+ specify { expect(desc).to eq DaruLite::Index.new [101, 100, 99, 2, 1] }
108
+ end
109
+ end
110
+
111
+ context "#size" do
112
+ it "correctly returns the size of the index" do
113
+ idx = DaruLite::Index.new ['speaker', 'mic', 'guitar', 'amp']
114
+
115
+ expect(idx.size).to eq(4)
116
+ end
117
+ end
118
+
119
+ context "#valid?" do
120
+ let(:idx) { DaruLite::Index.new [:a, :b, :c] }
121
+
122
+ context "single index" do
123
+ it { expect(idx.valid? 2).to eq true }
124
+ it { expect(idx.valid? :d).to eq false }
125
+ end
126
+
127
+ context "multiple indexes" do
128
+ it { expect(idx.valid? :a, 1).to eq true }
129
+ it { expect(idx.valid? :a, 3).to eq false }
130
+ end
131
+ end
132
+
133
+ context '#inspect' do
134
+ context 'small index' do
135
+ subject { DaruLite::Index.new ['one', 'two', 'three'] }
136
+ its(:inspect) { is_expected.to eq "#<DaruLite::Index(3): {one, two, three}>" }
137
+ end
138
+
139
+ context 'large index' do
140
+ subject { DaruLite::Index.new ('a'..'z').to_a }
141
+ its(:inspect) { is_expected.to eq "#<DaruLite::Index(26): {a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t ... z}>" }
142
+ end
143
+
144
+ context 'index with name' do
145
+ subject { DaruLite::Index.new ['one', 'two', 'three'], name: 'number' }
146
+ its(:inspect) { is_expected.to eq "#<DaruLite::Index(3): number {one, two, three}>" }
147
+ end
148
+ end
149
+
150
+ context "#&" do
151
+ before :each do
152
+ @left = DaruLite::Index.new [:miles, :geddy, :eric]
153
+ @right = DaruLite::Index.new [:geddy, :richie, :miles]
154
+ end
155
+
156
+ it "intersects 2 indexes and returns an Index" do
157
+ expect(@left & @right).to eq([:miles, :geddy].to_index)
158
+ end
159
+
160
+ it "intersects an Index and an Array to return an Index" do
161
+ expect(@left & [:bob, :geddy, :richie]).to eq([:geddy].to_index)
162
+ end
163
+ end
164
+
165
+ context "#|" do
166
+ before :each do
167
+ @left = DaruLite::Index.new [:miles, :geddy, :eric]
168
+ @right = DaruLite::Index.new [:bob, :jimi, :richie]
169
+ end
170
+
171
+ it "unions 2 indexes and returns an Index" do
172
+ expect(@left | @right).to eq([:miles, :geddy, :eric, :bob, :jimi, :richie].to_index)
173
+ end
174
+
175
+ it "unions an Index and an Array to return an Index" do
176
+ expect(@left | [:bob, :jimi, :richie]).to eq([:miles, :geddy, :eric,
177
+ :bob, :jimi, :richie].to_index)
178
+ end
179
+ end
180
+
181
+ context "#[]" do
182
+ before do
183
+ @id = DaruLite::Index.new [:one, :two, :three, :four, :five, :six, :seven]
184
+ @mixed_id = DaruLite::Index.new ['a','b','c',:d,:a,8,3,5]
185
+ end
186
+
187
+ it "works with ranges" do
188
+ expect(@id[:two..:five]).to eq([1, 2, 3, 4])
189
+
190
+ expect(@mixed_id['a'..'c']).to eq([0, 1, 2])
191
+
192
+ # returns nil if first index is invalid
193
+ expect(@mixed_id.slice('d', 5)).to be_nil
194
+
195
+ # returns positions till the end if first index is present
196
+ expect(@mixed_id.slice('c', 6)).to eq([2, 3, 4, 5, 6, 7])
197
+ end
198
+
199
+ it "returns multiple keys if specified multiple indices" do
200
+ expect(@id[:one, :two, :four, :five]).to eq([0, 1, 3, 4])
201
+ expect(@mixed_id[0,5,3,2]).to eq([nil, 7, 6, nil])
202
+ end
203
+
204
+ it "returns nil for invalid indexes" do
205
+ expect(@id[:four]).to eq(3)
206
+ expect(@id[3]).to be_nil
207
+ end
208
+
209
+ it "returns correct index position for mixed index" do
210
+ expect(@mixed_id[8]).to eq(5)
211
+ expect(@mixed_id['c']).to eq(2)
212
+ end
213
+ end
214
+
215
+ context "#pos" do
216
+ let(:idx) { described_class.new [:a, :b, 1, 2] }
217
+
218
+ context "single index" do
219
+ it { expect(idx.pos :a).to eq 0 }
220
+ end
221
+
222
+ context "multiple indexes" do
223
+ subject { idx.pos :a, 1 }
224
+
225
+ it { is_expected.to be_a Array }
226
+ its(:size) { is_expected.to eq 2 }
227
+ it { is_expected.to eq [0, 2] }
228
+ end
229
+
230
+ context "single positional index" do
231
+ it { expect(idx.pos 0).to eq 0 }
232
+ end
233
+
234
+ context "multiple positional index" do
235
+ subject { idx.pos 0, 3 }
236
+
237
+ it { is_expected.to be_a Array }
238
+ its(:size) { is_expected.to eq 2 }
239
+ it { is_expected.to eq [0, 3] }
240
+ end
241
+
242
+ context "range" do
243
+ subject { idx.pos 1..3 }
244
+
245
+ it { is_expected.to be_a Array }
246
+ its(:size) { is_expected.to eq 3 }
247
+ it { is_expected.to eq [1, 2, 3] }
248
+ end
249
+ end
250
+
251
+ context "#subset" do
252
+ let(:idx) { described_class.new [:a, :b, 1, 2] }
253
+
254
+ context "multiple indexes" do
255
+ subject { idx.subset :a, 1 }
256
+
257
+ it { is_expected.to be_a described_class }
258
+ its(:size) { is_expected.to eq 2 }
259
+ its(:to_a) { is_expected.to eq [:a, 1] }
260
+ end
261
+
262
+ context "multiple positional indexes" do
263
+ subject { idx.subset 0, 3 }
264
+
265
+ it { is_expected.to be_a described_class }
266
+ its(:size) { is_expected.to eq 2 }
267
+ its(:to_a) { is_expected.to eq [:a, 2] }
268
+ end
269
+
270
+ context "range" do
271
+ subject { idx.subset 1..3 }
272
+
273
+ it { is_expected.to be_a described_class }
274
+ its(:size) { is_expected.to eq 3 }
275
+ its(:to_a) { is_expected.to eq [:b, 1, 2] }
276
+ end
277
+ end
278
+
279
+ context "#at" do
280
+ let(:idx) { described_class.new [:a, :b, 1 ] }
281
+
282
+ context "single position" do
283
+ it { expect(idx.at 1).to eq :b }
284
+ end
285
+
286
+ context "multiple positions" do
287
+ subject { idx.at 1, 2 }
288
+
289
+ it { is_expected.to be_a described_class }
290
+ its(:size) { is_expected.to eq 2 }
291
+ its(:to_a) { is_expected.to eq [:b, 1] }
292
+ end
293
+
294
+ context "range" do
295
+ subject { idx.at 1..2 }
296
+
297
+ it { is_expected.to be_a described_class }
298
+ its(:size) { is_expected.to eq 2 }
299
+ its(:to_a) { is_expected.to eq [:b, 1] }
300
+ end
301
+
302
+ context "range with negative integer" do
303
+ subject { idx.at 1..-1 }
304
+
305
+ it { is_expected.to be_a described_class }
306
+ its(:size) { is_expected.to eq 2 }
307
+ its(:to_a) { is_expected.to eq [:b, 1] }
308
+ end
309
+
310
+ context "rangle with single element" do
311
+ subject { idx.at 1..1 }
312
+
313
+ it { is_expected.to be_a described_class }
314
+ its(:size) { is_expected.to eq 1 }
315
+ its(:to_a) { is_expected.to eq [:b] }
316
+ end
317
+
318
+ context "invalid position" do
319
+ it { expect { idx.at 3 }.to raise_error IndexError }
320
+ end
321
+
322
+ context "invalid positions" do
323
+ it { expect { idx.at 2, 3 }.to raise_error IndexError }
324
+ end
325
+ end
326
+
327
+ # This context validate DaruLite::Index is like an enumerable.
328
+ # #map and #select are samples and we do not need tests all
329
+ # enumerable methods.
330
+ context "Enumerable" do
331
+ let(:idx) { DaruLite::Index.new ['speaker', 'mic', 'guitar', 'amp'] }
332
+
333
+ context "#map" do
334
+ it { expect(idx.map(&:upcase)).to eq(['SPEAKER', 'MIC', 'GUITAR', 'AMP']) }
335
+ end
336
+
337
+ context "select" do
338
+ it { expect(idx.select {|w| w[0] == 'g' }).to eq(['guitar']) }
339
+ end
340
+ end
341
+
342
+ context "#is_values" do
343
+ let(:klass) { DaruLite::Vector }
344
+ let(:idx) { described_class.new [:one, 'one', 1, 2, 'two', nil, [1, 2]] }
345
+
346
+ context "no arguments" do
347
+ let(:answer) { [false, false, false, false, false, false, false] }
348
+ it { expect(idx.is_values).to eq klass.new(answer) }
349
+ end
350
+
351
+ context "single arguments" do
352
+ let(:answer) { [false, true, false, false, false, false, false] }
353
+ it { expect(idx.is_values 'one').to eq klass.new(answer) }
354
+ end
355
+
356
+ context "multiple arguments" do
357
+ context "symbol and number as argument" do
358
+ subject { idx.is_values 2, :one }
359
+ let(:answer) { [true, false, false, true, false, false, false] }
360
+ it { is_expected.to be_a DaruLite::Vector }
361
+ its(:size) { is_expected.to eq 7 }
362
+ it { is_expected.to eq klass.new(answer) }
363
+ end
364
+
365
+ context "string and number as argument" do
366
+ subject { idx.is_values('one', 1)}
367
+ let(:answer) { [false, true, true, false, false, false, false] }
368
+ it { is_expected.to be_a DaruLite::Vector }
369
+ its(:size) { is_expected.to eq 7 }
370
+ it { is_expected.to eq klass.new(answer) }
371
+ end
372
+
373
+ context "nil is present in arguments" do
374
+ subject { idx.is_values('two', nil)}
375
+ let(:answer) { [false, false, false, false, true, true, false] }
376
+ it { is_expected.to be_a DaruLite::Vector }
377
+ its(:size) { is_expected.to eq 7 }
378
+ it { is_expected.to eq klass.new(answer) }
379
+ end
380
+
381
+ context "subarray is present in arguments" do
382
+ subject { idx.is_values([1, 2])}
383
+ let(:answer) { [false, false, false, false, false, false, true] }
384
+ it { is_expected.to be_a DaruLite::Vector }
385
+ its(:size) { is_expected.to eq 7 }
386
+ it { is_expected.to eq klass.new(answer) }
387
+ end
388
+ end
389
+
390
+ end
391
+
392
+ context '#to_df' do
393
+ let(:idx) do
394
+ DaruLite::Index.new(['speaker', 'mic', 'guitar', 'amp'],
395
+ name: 'instruments')
396
+ end
397
+ subject { idx.to_df }
398
+
399
+ it { is_expected.to eq DaruLite::DataFrame.new(
400
+ 'instruments' => ['speaker', 'mic', 'guitar', 'amp']
401
+ )
402
+ }
403
+ end
404
+
405
+ context "#dup" do
406
+ let(:idx) do
407
+ DaruLite::Index.new(['speaker', 'mic', 'guitar', 'amp'],
408
+ name: 'instruments')
409
+ end
410
+ subject { idx.dup }
411
+
412
+ it { is_expected.to eq idx }
413
+ it 'have same names' do
414
+ expect(subject.name).to eq idx.name
415
+ end
416
+ end
417
+ end