daru_lite 0.3.4 → 0.3.5

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 (142) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +60 -0
  3. data/README.md +1 -1
  4. data/lib/daru_lite/category.rb +1 -1
  5. data/lib/daru_lite/date_time/index.rb +2 -2
  6. data/lib/daru_lite/maths/statistics/vector.rb +1 -1
  7. data/lib/daru_lite/version.rb +1 -1
  8. data/lib/daru_lite.rb +1 -0
  9. metadata +54 -284
  10. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  11. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  12. data/.github/dependabot.yml +0 -11
  13. data/.github/workflows/ci.yml +0 -33
  14. data/.gitignore +0 -10
  15. data/.rspec +0 -2
  16. data/.rubocop.yml +0 -27
  17. data/.rubocop_todo.yml +0 -139
  18. data/CONTRIBUTING.md +0 -47
  19. data/Gemfile +0 -2
  20. data/Rakefile +0 -69
  21. data/ReleasePolicy.md +0 -20
  22. data/benchmarks/TradeoffData.csv +0 -65
  23. data/benchmarks/csv_reading.rb +0 -22
  24. data/benchmarks/dataframe_creation.rb +0 -39
  25. data/benchmarks/db_loading.rb +0 -33
  26. data/benchmarks/duplicating.rb +0 -45
  27. data/benchmarks/group_by.rb +0 -32
  28. data/benchmarks/joining.rb +0 -52
  29. data/benchmarks/row_access.rb +0 -41
  30. data/benchmarks/row_assign.rb +0 -36
  31. data/benchmarks/sorting.rb +0 -51
  32. data/benchmarks/statistics.rb +0 -28
  33. data/benchmarks/vector_access.rb +0 -31
  34. data/benchmarks/vector_assign.rb +0 -42
  35. data/benchmarks/where_clause.rb +0 -48
  36. data/benchmarks/where_vs_filter.rb +0 -28
  37. data/daru_lite.gemspec +0 -54
  38. data/daru_lite_test-shm +0 -0
  39. data/daru_lite_test-wal +0 -0
  40. data/images/README.md +0 -5
  41. data/images/con0.png +0 -0
  42. data/images/con1.png +0 -0
  43. data/images/init0.png +0 -0
  44. data/images/init1.png +0 -0
  45. data/images/man0.png +0 -0
  46. data/images/man1.png +0 -0
  47. data/images/man2.png +0 -0
  48. data/images/man3.png +0 -0
  49. data/images/man4.png +0 -0
  50. data/images/man5.png +0 -0
  51. data/images/man6.png +0 -0
  52. data/profile/_base.rb +0 -23
  53. data/profile/df_to_a.rb +0 -10
  54. data/profile/filter.rb +0 -13
  55. data/profile/joining.rb +0 -13
  56. data/profile/sorting.rb +0 -12
  57. data/profile/vector_each_with_index.rb +0 -9
  58. data/profile/vector_new.rb +0 -9
  59. data/spec/accessors/array_wrapper_spec.rb +0 -3
  60. data/spec/category_spec.rb +0 -1767
  61. data/spec/core/group_by_spec.rb +0 -655
  62. data/spec/core/merge_spec.rb +0 -179
  63. data/spec/core/query_spec.rb +0 -347
  64. data/spec/daru_lite_spec.rb +0 -22
  65. data/spec/data_frame/aggregatable_example.rb +0 -65
  66. data/spec/data_frame/buildable_example.rb +0 -109
  67. data/spec/data_frame/calculatable_example.rb +0 -135
  68. data/spec/data_frame/convertible_example.rb +0 -180
  69. data/spec/data_frame/duplicatable_example.rb +0 -134
  70. data/spec/data_frame/fetchable_example.rb +0 -510
  71. data/spec/data_frame/filterable_example.rb +0 -456
  72. data/spec/data_frame/indexable_example.rb +0 -221
  73. data/spec/data_frame/iterable_example.rb +0 -481
  74. data/spec/data_frame/joinable_example.rb +0 -131
  75. data/spec/data_frame/missable_example.rb +0 -47
  76. data/spec/data_frame/pivotable_example.rb +0 -297
  77. data/spec/data_frame/queryable_example.rb +0 -92
  78. data/spec/data_frame/setable_example.rb +0 -513
  79. data/spec/data_frame/sortable_example.rb +0 -368
  80. data/spec/dataframe_spec.rb +0 -1342
  81. data/spec/date_time/data_spec.rb +0 -197
  82. data/spec/date_time/date_time_index_helper_spec.rb +0 -72
  83. data/spec/date_time/index_spec.rb +0 -588
  84. data/spec/date_time/offsets_spec.rb +0 -465
  85. data/spec/extensions/which_dsl_spec.rb +0 -38
  86. data/spec/fixtures/bank2.dat +0 -200
  87. data/spec/fixtures/boolean_converter_test.csv +0 -5
  88. data/spec/fixtures/countries.json +0 -7794
  89. data/spec/fixtures/duplicates.csv +0 -32
  90. data/spec/fixtures/eciresults.html +0 -394
  91. data/spec/fixtures/empties.dat +0 -2
  92. data/spec/fixtures/empty_rows_test.csv +0 -17
  93. data/spec/fixtures/macau.html +0 -3691
  94. data/spec/fixtures/macd_data.csv +0 -150
  95. data/spec/fixtures/matrix_test.csv +0 -100
  96. data/spec/fixtures/moneycontrol.html +0 -6812
  97. data/spec/fixtures/music_data.tsv +0 -2501
  98. data/spec/fixtures/repeated_fields.csv +0 -7
  99. data/spec/fixtures/sales-funnel.csv +0 -18
  100. data/spec/fixtures/scientific_notation.csv +0 -4
  101. data/spec/fixtures/string_converter_test.csv +0 -5
  102. data/spec/fixtures/strings.dat +0 -2
  103. data/spec/fixtures/test_xls.xls +0 -0
  104. data/spec/fixtures/test_xls_2.xls +0 -0
  105. data/spec/fixtures/url_test.txt~ +0 -0
  106. data/spec/fixtures/valid_markup.html +0 -62
  107. data/spec/fixtures/wiki_climate.html +0 -1243
  108. data/spec/fixtures/wiki_table_info.html +0 -631
  109. data/spec/formatters/table_formatter_spec.rb +0 -137
  110. data/spec/helpers_spec.rb +0 -8
  111. data/spec/index/categorical_index_spec.rb +0 -289
  112. data/spec/index/index_spec.rb +0 -438
  113. data/spec/index/multi_index_spec.rb +0 -752
  114. data/spec/io/io_spec.rb +0 -357
  115. data/spec/io/sql_data_source_spec.rb +0 -48
  116. data/spec/iruby/dataframe_spec.rb +0 -170
  117. data/spec/iruby/helpers_spec.rb +0 -49
  118. data/spec/iruby/multi_index_spec.rb +0 -37
  119. data/spec/iruby/vector_spec.rb +0 -105
  120. data/spec/maths/arithmetic/dataframe_spec.rb +0 -148
  121. data/spec/maths/arithmetic/vector_spec.rb +0 -165
  122. data/spec/maths/statistics/dataframe_spec.rb +0 -191
  123. data/spec/maths/statistics/vector_spec.rb +0 -756
  124. data/spec/monkeys_spec.rb +0 -42
  125. data/spec/shared/vector_display_spec.rb +0 -213
  126. data/spec/spec_helper.rb +0 -87
  127. data/spec/support/database_helper.rb +0 -29
  128. data/spec/support/matchers.rb +0 -5
  129. data/spec/vector/aggregatable_example.rb +0 -27
  130. data/spec/vector/calculatable_example.rb +0 -82
  131. data/spec/vector/convertible_example.rb +0 -126
  132. data/spec/vector/duplicatable_example.rb +0 -48
  133. data/spec/vector/fetchable_example.rb +0 -463
  134. data/spec/vector/filterable_example.rb +0 -165
  135. data/spec/vector/indexable_example.rb +0 -201
  136. data/spec/vector/iterable_example.rb +0 -111
  137. data/spec/vector/joinable_example.rb +0 -25
  138. data/spec/vector/missable_example.rb +0 -88
  139. data/spec/vector/queryable_example.rb +0 -91
  140. data/spec/vector/setable_example.rb +0 -300
  141. data/spec/vector/sortable_example.rb +0 -242
  142. data/spec/vector_spec.rb +0 -599
@@ -1,510 +0,0 @@
1
- shared_examples_for 'a fetchable DataFrame' do
2
- describe "#[]" do
3
- context DaruLite::Index do
4
- let(:df) do
5
- DaruLite::DataFrame.new(
6
- {
7
- b: [11,12,13,14,15],
8
- a: [1,2,3,4,5],
9
- c: [11,22,33,44,55]
10
- },
11
- order: [:a, :b, :c],
12
- index: [:one, :two, :three, :four, :five]
13
- )
14
- end
15
-
16
- it "returns a Vector" do
17
- expect(df[:a]).to eq([1,2,3,4,5].dv(:a, [:one, :two, :three, :four, :five]))
18
- end
19
-
20
- it "returns a Vector by default" do
21
- expect(df[:a]).to eq(DaruLite::Vector.new([1,2,3,4,5], name: :a,
22
- index: [:one, :two, :three, :four, :five]))
23
- end
24
-
25
- it "returns a DataFrame" do
26
- temp = DaruLite::DataFrame.new({b: [11,12,13,14,15], a: [1,2,3,4,5]},
27
- order: [:a, :b], index: [:one, :two, :three, :four, :five])
28
-
29
- expect(df[:a, :b]).to eq(temp)
30
- end
31
-
32
- it "accesses vector with Integer index" do
33
- expect(df[0]).to eq([1,2,3,4,5].dv(:a, [:one, :two, :three, :four, :five]))
34
- end
35
-
36
- it "returns a subset of DataFrame when specified range" do
37
- subset = df[:b..:c]
38
- expect(subset).to eq(DaruLite::DataFrame.new({
39
- b: [11,12,13,14,15],
40
- c: [11,22,33,44,55]
41
- }, index: [:one, :two, :three, :four, :five]))
42
- end
43
-
44
- it 'accepts axis parameter as a last argument' do
45
- expect(df[:a, :vector]).to eq df[:a]
46
- expect(df[:one, :row]).to eq [1, 11, 11].dv(:one, [:a, :b, :c])
47
- end
48
- end
49
-
50
- context DaruLite::MultiIndex do
51
- it "accesses vector with an integer index" do
52
- expect(df_mi[0]).to eq(
53
- DaruLite::Vector.new(vector_arry1, index: multi_index))
54
- end
55
-
56
- it "returns a vector when specifying full tuple" do
57
- expect(df_mi[:a, :one, :bar]).to eq(
58
- DaruLite::Vector.new(vector_arry1, index: multi_index))
59
- end
60
-
61
- it "returns a vector when specifying last tuple part as an array" do
62
- expect(df_mi[:a, :one, [:bar]]).to eq(
63
- DaruLite::Vector.new(vector_arry1, index: multi_index))
64
- end
65
-
66
- it "returns DataFrame when specified first layer of MultiIndex" do
67
- sub_order = DaruLite::MultiIndex.from_tuples([
68
- [:one, :bar],
69
- [:two, :baz]
70
- ])
71
- expect(df_mi[:a]).to eq(
72
- DaruLite::DataFrame.new([vector_arry1, vector_arry2], index: multi_index, order: sub_order)
73
- )
74
- end
75
-
76
- it "returns a Vector if the last level of MultiIndex is tracked" do
77
- expect(df_mi[:a, :one, :bar]).to eq(
78
- DaruLite::Vector.new(vector_arry1, index: multi_index)
79
- )
80
- end
81
- end
82
-
83
- context "with duplicate tuples in a MultiIndex" do
84
- let(:dup_df) do
85
- DaruLite::DataFrame.new(
86
- [[1, 2], [3, 4], [5, 6], [7, 8]],
87
- order: DaruLite::MultiIndex.from_tuples([
88
- [:weighted_count, 'Wave'], [:weighted_count, 'Wave'],
89
- [:percentage, 'Wave'], [:percentage, 'Wave']
90
- ]),
91
- index: %w[Yes No]
92
- )
93
- end
94
-
95
- it "returns a DataFrame with all matching columns for a partial key" do
96
- result = dup_df[:weighted_count]
97
-
98
- expect(result).to be_a(DaruLite::DataFrame)
99
- expect(result.ncols).to eq(2)
100
- expect(result.map_vectors(&:to_a)).to eq([[1, 2], [3, 4]])
101
- expect(result.index).to eq(dup_df.index)
102
- end
103
-
104
- it "returns a DataFrame with all matching columns for a duplicate full tuple" do
105
- result = dup_df[:weighted_count, 'Wave']
106
-
107
- expect(result).to be_a(DaruLite::DataFrame)
108
- expect(result.map_vectors(&:to_a)).to eq([[1, 2], [3, 4]])
109
- end
110
- end
111
- end
112
-
113
- describe "#at" do
114
- context DaruLite::Index do
115
- let(:idx) { DaruLite::Index.new [:a, :b, :c] }
116
- let(:df) do
117
- DaruLite::DataFrame.new({
118
- 1 => 1..3,
119
- a: 'a'..'c',
120
- b: 11..13
121
- }, index: idx)
122
- end
123
-
124
- context "single position" do
125
- subject { df.at 1 }
126
-
127
- it { is_expected.to be_a DaruLite::Vector }
128
- its(:size) { is_expected.to eq 3 }
129
- its(:to_a) { is_expected.to eq ['a', 'b', 'c'] }
130
- its(:index) { is_expected.to eq idx }
131
- end
132
-
133
- context "multiple positions" do
134
- subject { df.at 0, 2 }
135
-
136
- it { is_expected.to be_a DaruLite::DataFrame }
137
- its(:shape) { is_expected.to eq [3, 2] }
138
- its(:index) { is_expected.to eq idx }
139
- it { expect(df[1].to_a).to eq [1, 2, 3] }
140
- its(:'b.to_a') { is_expected.to eq [11, 12, 13] }
141
- end
142
-
143
- context "single invalid position" do
144
- it { expect { df. at 3 }.to raise_error IndexError }
145
- end
146
-
147
- context "multiple invalid positions" do
148
- it { expect { df.at 2, 3 }.to raise_error IndexError }
149
- end
150
-
151
- context "range" do
152
- subject { df.at 0..1 }
153
-
154
- it { is_expected.to be_a DaruLite::DataFrame }
155
- its(:shape) { is_expected.to eq [3, 2] }
156
- its(:index) { is_expected.to eq idx }
157
- it { expect(df[1].to_a).to eq [1, 2, 3] }
158
- its(:'a.to_a') { is_expected.to eq ['a', 'b', 'c'] }
159
- end
160
-
161
- context "range with negative end" do
162
- subject { df.at 0..-2 }
163
-
164
- it { is_expected.to be_a DaruLite::DataFrame }
165
- its(:shape) { is_expected.to eq [3, 2] }
166
- its(:index) { is_expected.to eq idx }
167
- it { expect(df[1].to_a).to eq [1, 2, 3] }
168
- its(:'a.to_a') { is_expected.to eq ['a', 'b', 'c'] }
169
- end
170
-
171
- context "range with single element" do
172
- subject { df.at 1..1 }
173
-
174
- it { is_expected.to be_a DaruLite::DataFrame }
175
- its(:shape) { is_expected.to eq [3, 1] }
176
- its(:index) { is_expected.to eq idx }
177
- its(:'a.to_a') { is_expected.to eq ['a', 'b', 'c'] }
178
- end
179
- end
180
-
181
- context DaruLite::MultiIndex do
182
- let (:idx) do
183
- DaruLite::MultiIndex.from_tuples [
184
- [:a,:one,:bar],
185
- [:a,:one,:baz],
186
- [:b,:two,:bar],
187
- ]
188
- end
189
- let(:df) do
190
- DaruLite::DataFrame.new({
191
- 1 => 1..3,
192
- a: 'a'..'c',
193
- b: 11..13
194
- }, index: idx)
195
- end
196
-
197
- context "single position" do
198
- subject { df.at 1 }
199
-
200
- it { is_expected.to be_a DaruLite::Vector }
201
- its(:size) { is_expected.to eq 3 }
202
- its(:to_a) { is_expected.to eq ['a', 'b', 'c'] }
203
- its(:index) { is_expected.to eq idx }
204
- end
205
-
206
- context "multiple positions" do
207
- subject { df.at 0, 2 }
208
-
209
- it { is_expected.to be_a DaruLite::DataFrame }
210
- its(:shape) { is_expected.to eq [3, 2] }
211
- its(:index) { is_expected.to eq idx }
212
- it { expect(df[1].to_a).to eq [1, 2, 3] }
213
- its(:'b.to_a') { is_expected.to eq [11, 12, 13] }
214
- end
215
-
216
- context "single invalid position" do
217
- it { expect { df. at 3 }.to raise_error IndexError }
218
- end
219
-
220
- context "multiple invalid positions" do
221
- it { expect { df.at 2, 3 }.to raise_error IndexError }
222
- end
223
-
224
- context "range" do
225
- subject { df.at 0..1 }
226
-
227
- it { is_expected.to be_a DaruLite::DataFrame }
228
- its(:shape) { is_expected.to eq [3, 2] }
229
- its(:index) { is_expected.to eq idx }
230
- it { expect(df[1].to_a).to eq [1, 2, 3] }
231
- its(:'a.to_a') { is_expected.to eq ['a', 'b', 'c'] }
232
- end
233
-
234
- context "range with negative end" do
235
- subject { df.at 0..-2 }
236
-
237
- it { is_expected.to be_a DaruLite::DataFrame }
238
- its(:shape) { is_expected.to eq [3, 2] }
239
- its(:index) { is_expected.to eq idx }
240
- it { expect(df[1].to_a).to eq [1, 2, 3] }
241
- its(:'a.to_a') { is_expected.to eq ['a', 'b', 'c'] }
242
- end
243
-
244
- context "range with single element" do
245
- subject { df.at 1..1 }
246
-
247
- it { is_expected.to be_a DaruLite::DataFrame }
248
- its(:shape) { is_expected.to eq [3, 1] }
249
- its(:index) { is_expected.to eq idx }
250
- its(:'a.to_a') { is_expected.to eq ['a', 'b', 'c'] }
251
- end
252
- end
253
-
254
- context DaruLite::CategoricalIndex do
255
- let (:idx) { DaruLite::CategoricalIndex.new [:a, 1, 1] }
256
- let(:df) do
257
- DaruLite::DataFrame.new({
258
- 1 => 1..3,
259
- a: 'a'..'c',
260
- b: 11..13
261
- }, index: idx)
262
- end
263
-
264
- context "single position" do
265
- subject { df.at 1 }
266
-
267
- it { is_expected.to be_a DaruLite::Vector }
268
- its(:size) { is_expected.to eq 3 }
269
- its(:to_a) { is_expected.to eq ['a', 'b', 'c'] }
270
- its(:index) { is_expected.to eq idx }
271
- end
272
-
273
- context "multiple positions" do
274
- subject { df.at 0, 2 }
275
-
276
- it { is_expected.to be_a DaruLite::DataFrame }
277
- its(:shape) { is_expected.to eq [3, 2] }
278
- its(:index) { is_expected.to eq idx }
279
- it { expect(df[1].to_a).to eq [1, 2, 3] }
280
- its(:'b.to_a') { is_expected.to eq [11, 12, 13] }
281
- end
282
-
283
- context "single invalid position" do
284
- it { expect { df. at 3 }.to raise_error IndexError }
285
- end
286
-
287
- context "multiple invalid positions" do
288
- it { expect { df.at 2, 3 }.to raise_error IndexError }
289
- end
290
-
291
- context "range" do
292
- subject { df.at 0..1 }
293
-
294
- it { is_expected.to be_a DaruLite::DataFrame }
295
- its(:shape) { is_expected.to eq [3, 2] }
296
- its(:index) { is_expected.to eq idx }
297
- it { expect(df[1].to_a).to eq [1, 2, 3] }
298
- its(:'a.to_a') { is_expected.to eq ['a', 'b', 'c'] }
299
- end
300
-
301
- context "range with negative index" do
302
- subject { df.at 0..-2 }
303
-
304
- it { is_expected.to be_a DaruLite::DataFrame }
305
- its(:shape) { is_expected.to eq [3, 2] }
306
- its(:index) { is_expected.to eq idx }
307
- it { expect(df[1].to_a).to eq [1, 2, 3] }
308
- its(:'a.to_a') { is_expected.to eq ['a', 'b', 'c'] }
309
- end
310
-
311
- context "range with single element" do
312
- subject { df.at 1..1 }
313
-
314
- it { is_expected.to be_a DaruLite::DataFrame }
315
- its(:shape) { is_expected.to eq [3, 1] }
316
- its(:index) { is_expected.to eq idx }
317
- its(:'a.to_a') { is_expected.to eq ['a', 'b', 'c'] }
318
- end
319
- end
320
- end
321
-
322
- context "#first" do
323
- it 'works' do
324
- expect(df.first(2)).to eq(
325
- DaruLite::DataFrame.new({b: [11,12], a: [1,2], c: [11,22]},
326
- order: [:a, :b, :c],
327
- index: [:one, :two]))
328
- end
329
-
330
- it 'works with too large values' do
331
- expect(df.first(200)).to eq(df)
332
- end
333
-
334
- it 'has synonym' do
335
- expect(df.first(2)).to eq(df.head(2))
336
- end
337
-
338
- it 'works on DateTime indexes' do
339
- idx = DaruLite::DateTimeIndex.new(['2017-01-01', '2017-02-01', '2017-03-01'])
340
- df = DaruLite::DataFrame.new({col1: ['a', 'b', 'c']}, index: idx)
341
- first = DaruLite::DataFrame.new({col1: ['a']}, index: DaruLite::DateTimeIndex.new(['2017-01-01']))
342
- expect(df.head(1)).to eq(first)
343
- end
344
- end
345
-
346
- context "#last" do
347
- it 'works' do
348
- expect(df.last(2)).to eq(
349
- DaruLite::DataFrame.new({b: [14,15], a: [4,5], c: [44,55]},
350
- order: [:a, :b, :c],
351
- index: [:four, :five]))
352
- end
353
-
354
- it 'works with too large values' do
355
- expect(df.last(200)).to eq(df)
356
- end
357
-
358
- it 'has synonym' do
359
- expect(df.last(2)).to eq(df.tail(2))
360
- end
361
- end
362
-
363
- context '#access_row_tuples_by_indexs' do
364
- let(:df) {
365
- DaruLite::DataFrame.new({col: [:a, :b, :c, :d, :e], num: [52,12,07,17,01]}) }
366
- let(:df_idx) {
367
- DaruLite::DataFrame.new({a: [52, 12, 07], b: [1, 2, 3]}, index: [:one, :two, :three])
368
- }
369
- let (:mi_idx) do
370
- DaruLite::MultiIndex.from_tuples [
371
- [:a,:one,:bar],
372
- [:a,:one,:baz],
373
- [:b,:two,:bar],
374
- [:a,:two,:baz],
375
- ]
376
- end
377
- let (:df_mi) do
378
- DaruLite::DataFrame.new({
379
- a: 1..4,
380
- b: 'a'..'d'
381
- }, index: mi_idx )
382
- end
383
- context 'when no index is given' do
384
- it 'returns empty Array' do
385
- expect(df.access_row_tuples_by_indexs()).to eq([])
386
- end
387
- end
388
- context 'when index(s) are given' do
389
- it 'returns Array of row tuples' do
390
- expect(df.access_row_tuples_by_indexs(1)).to eq([[:b, 12]])
391
- expect(df.access_row_tuples_by_indexs(0,3)).to eq([[:a, 52], [:d, 17]])
392
- end
393
- end
394
- context 'when custom index(s) are given' do
395
- it 'returns Array of row tuples' do
396
- expect(df_idx.access_row_tuples_by_indexs(:one,:three)).to eq(
397
- [[52, 1], [7, 3]]
398
- )
399
- end
400
- end
401
- context 'when multi index is given' do
402
- it 'returns Array of row tuples' do
403
- expect(df_mi.access_row_tuples_by_indexs(:a)).to eq(
404
- [[1, "a"], [2, "b"], [4, "d"]]
405
- )
406
- expect(df_mi.access_row_tuples_by_indexs(:a, :one, :baz)).to eq(
407
- [[2, "b"]]
408
- )
409
- end
410
- end
411
- end
412
-
413
- context "#only_numerics" do
414
- subject { df.only_numerics }
415
-
416
- let(:df) do
417
- DaruLite::DataFrame.new({a: vector1, b: vector2, c: vector3 }, clone: false)
418
- end
419
- let(:vector1) { DaruLite::Vector.new([1,2,3,4,5]) }
420
- let(:vector2) { DaruLite::Vector.new(%w(one two three four five)) }
421
- let(:vector3) { DaruLite::Vector.new([11,22,33,44,55]) }
422
-
423
- it "returns a clone of numeric vectors" do
424
- expect(subject).to eq(
425
- DaruLite::DataFrame.new({ a: vector1, c: vector3}, clone: false)
426
- )
427
- expect(subject[:a].object_id).to_not eq(vector1.object_id)
428
- end
429
-
430
- context 'clone is false' do
431
- subject { df.only_numerics(clone: false) }
432
-
433
- it "returns a view of only the numeric vectors" do
434
- expect(subject).to eq(
435
- DaruLite::DataFrame.new({ a: vector1, c: vector3 }, clone: false)
436
- )
437
- expect(subject[:a].object_id).to eq(vector1.object_id)
438
- end
439
- end
440
-
441
- context DaruLite::MultiIndex do
442
- let(:df) do
443
- order = DaruLite::MultiIndex.from_tuples(
444
- [
445
- [:d, :one, :large],
446
- [:d, :one, :small],
447
- [:d, :two, :large],
448
- [:d, :two, :small],
449
- [:e, :one, :large],
450
- [:e, :one, :small],
451
- [:e, :two, :large],
452
- [:e, :two, :small]
453
- ]
454
- )
455
-
456
- index = DaruLite::MultiIndex.from_tuples(
457
- [
458
- [:bar],
459
- [:foo]
460
- ]
461
- )
462
- DaruLite::DataFrame.new(
463
- [
464
- [4.112,2.234],
465
- %w(a b),
466
- [6.342,nil],
467
- [7.2344,3.23214],
468
- [8.234,4.533],
469
- [10.342,2.3432],
470
- [12.0,nil],
471
- %w(a b)
472
- ],
473
- order:,
474
- index:
475
- )
476
- end
477
-
478
- it "returns numeric vectors" do
479
- vectors = DaruLite::MultiIndex.from_tuples(
480
- [
481
- [:d, :one, :large],
482
- [:d, :two, :large],
483
- [:d, :two, :small],
484
- [:e, :one, :large],
485
- [:e, :one, :small],
486
- [:e, :two, :large]
487
- ]
488
- )
489
- index = DaruLite::MultiIndex.from_tuples(
490
- [
491
- [:bar],
492
- [:foo]
493
- ]
494
- )
495
- answer = DaruLite::DataFrame.new(
496
- [
497
- [4.112,2.234],
498
- [6.342,nil],
499
- [7.2344,3.23214],
500
- [8.234,4.533],
501
- [10.342,2.3432],
502
- [12.0,nil],
503
- ], order: vectors, index: index
504
- )
505
-
506
- expect(subject).to eq(answer)
507
- end
508
- end
509
- end
510
- end