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