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,482 +0,0 @@
1
- shared_examples_for 'a setable DataFrame' do
2
- describe "#row.set_at" do
3
- let(:df) do
4
- DaruLite::DataFrame.new({
5
- a: 1..3,
6
- b: 'a'..'c'
7
- })
8
- end
9
-
10
- context "single position" do
11
- subject { df }
12
- before { df.row.set_at [1], ['x', 'y'] }
13
-
14
- its(:size) { is_expected.to eq 3 }
15
- its(:'a.to_a') { is_expected.to eq [1, 'x', 3] }
16
- its(:'b.to_a') { is_expected.to eq ['a', 'y', 'c'] }
17
- end
18
-
19
- context "multiple position" do
20
- subject { df }
21
- before { df.row.set_at [0, 2], ['x', 'y'] }
22
-
23
- its(:size) { is_expected.to eq 3 }
24
- its(:'a.to_a') { is_expected.to eq ['x', 2, 'x'] }
25
- its(:'b.to_a') { is_expected.to eq ['y', 'b', 'y'] }
26
- end
27
-
28
- context "invalid position" do
29
- it { expect { df.row.set_at [3], ['x', 'y'] }.to raise_error IndexError }
30
- end
31
-
32
- context "invalid positions" do
33
- it { expect { df.row.set_at [2, 3], ['x', 'y'] }.to raise_error IndexError }
34
- end
35
-
36
- context "incorrect size" do
37
- it { expect { df.row.set_at [1], ['x', 'y', 'z'] }.to raise_error SizeError }
38
- end
39
- end
40
-
41
- describe "#set_at" do
42
- let(:df) do
43
- DaruLite::DataFrame.new({
44
- 1 => 1..3,
45
- a: 'a'..'c',
46
- b: 11..13
47
- })
48
- end
49
-
50
- context "single position" do
51
- subject { df }
52
- before { df.set_at [1], ['x', 'y', 'z'] }
53
-
54
- its(:shape) { is_expected.to eq [3, 3] }
55
- it { expect(df[1].to_a).to eq [1, 2, 3] }
56
- its(:'a.to_a') { is_expected.to eq ['x', 'y', 'z'] }
57
- its(:'b.to_a') { is_expected.to eq [11, 12, 13] }
58
- end
59
-
60
- context "multiple position" do
61
- subject { df }
62
- before { df.set_at [1, 2], ['x', 'y', 'z'] }
63
-
64
- its(:shape) { is_expected.to eq [3, 3] }
65
- it { expect(df[1].to_a).to eq [1, 2, 3] }
66
- its(:'a.to_a') { is_expected.to eq ['x', 'y', 'z'] }
67
- its(:'b.to_a') { is_expected.to eq ['x', 'y', 'z'] }
68
- end
69
-
70
- context "invalid position" do
71
- it { expect { df.set_at [3], ['x', 'y', 'z'] }.to raise_error IndexError }
72
- end
73
-
74
- context "invalid positions" do
75
- it { expect { df.set_at [2, 3], ['x', 'y', 'z'] }.to raise_error IndexError }
76
- end
77
-
78
- context "incorrect size" do
79
- it { expect { df.set_at [1], ['x', 'y'] }.to raise_error SizeError }
80
- end
81
- end
82
-
83
- describe "#[]=" do
84
- context DaruLite::Index do
85
- let(:df) do
86
- DaruLite::DataFrame.new(
87
- {
88
- b: [11,12,13,14,15],
89
- a: [1,2,3,4,5],
90
- c: [11,22,33,44,55]
91
- },
92
- order: [:a, :b, :c],
93
- index: [:one, :two, :three, :four, :five]
94
- )
95
- end
96
-
97
- it "assigns directly with the []= operator" do
98
- df[:a] = [100,200,300,400,500]
99
- expect(df).to eq(DaruLite::DataFrame.new({
100
- b: [11,12,13,14,15],
101
- a: [100,200,300,400,500],
102
- c: [11,22,33,44,55]}, order: [:a, :b, :c],
103
- index: [:one, :two, :three, :four, :five]))
104
- end
105
-
106
- it "assigns new vector with default length if given just a value" do
107
- df[:d] = 1.0
108
- expect(df[:d]).to eq(DaruLite::Vector.new([1.0, 1.0, 1.0, 1.0, 1.0],
109
- index: [:one, :two, :three, :four, :five], name: :d))
110
- end
111
-
112
- it "updates vector with default length if given just a value" do
113
- df[:c] = 1.0
114
- expect(df[:c]).to eq(DaruLite::Vector.new([1.0, 1.0, 1.0, 1.0, 1.0],
115
- index: [:one, :two, :three, :four, :five], name: :c))
116
- end
117
-
118
- it "appends an Array as a DaruLite::Vector" do
119
- df[:d] = [69,99,108,85,49]
120
-
121
- expect(df.d.class).to eq(DaruLite::Vector)
122
- end
123
-
124
- it "appends an arbitrary enumerable as a DaruLite::Vector" do
125
- df[:d] = Set.new([69,99,108,85,49])
126
-
127
- expect(df[:d]).to eq(DaruLite::Vector.new([69, 99, 108, 85, 49],
128
- index: [:one, :two, :three, :four, :five], name: :c))
129
- end
130
-
131
- it "replaces an already present vector" do
132
- df[:a] = [69,99,108,85,49].dv(nil, [:one, :two, :three, :four, :five])
133
-
134
- expect(df.a).to eq([69,99,108,85,49].dv(nil, [:one, :two, :three, :four, :five]))
135
- end
136
-
137
- it "appends a new vector to the DataFrame" do
138
- df[:woo] = [69,99,108,85,49].dv(nil, [:one, :two, :three, :four, :five])
139
-
140
- expect(df.vectors).to eq([:a, :b, :c, :woo].to_index)
141
- end
142
-
143
- it "creates an index for the new vector if not specified" do
144
- df[:woo] = [69,99,108,85,49]
145
-
146
- expect(df.woo.index).to eq([:one, :two, :three, :four, :five].to_index)
147
- end
148
-
149
- it "matches index of vector to be inserted with the DataFrame index" do
150
- df[:shankar] = [69,99,108,85,49].dv(:shankar, [:two, :one, :three, :five, :four])
151
-
152
- expect(df.shankar).to eq([99,69,108,49,85].dv(:shankar,
153
- [:one, :two, :three, :four, :five]))
154
- end
155
-
156
- it "matches index of vector to be inserted, inserting nils where no match found" do
157
- df[:shankar] = [1,2,3].dv(:shankar, [:one, :james, :hetfield])
158
-
159
- expect(df.shankar).to eq([1,nil,nil,nil,nil].dv(:shankar, [:one, :two, :three, :four, :five]))
160
- end
161
-
162
- it "raises error for Array assignment of wrong length" do
163
- expect{
164
- df[:shiva] = [1,2,3]
165
- }.to raise_error
166
- end
167
-
168
- it "assigns correct name given empty dataframe" do
169
- df_empty = DaruLite::DataFrame.new({})
170
- df_empty[:a] = 1..5
171
- df_empty[:b] = 1..5
172
-
173
- expect(df_empty[:a].name).to equal(:a)
174
- expect(df_empty[:b].name).to equal(:b)
175
- end
176
-
177
- it "appends multiple vectors at a time" do
178
- # TODO
179
- end
180
- end
181
-
182
- context DaruLite::MultiIndex do
183
- it "raises error when incomplete index specified but index is absent" do
184
- expect {
185
- df_mi[:d] = [100,200,300,400,100,200,300,400,100,200,300,400]
186
- }.to raise_error
187
- end
188
-
189
- it "assigns all sub-indexes when a top level index is specified" do
190
- df_mi[:a] = [100,200,300,400,100,200,300,400,100,200,300,400]
191
-
192
- expect(df_mi).to eq(DaruLite::DataFrame.new([
193
- [100,200,300,400,100,200,300,400,100,200,300,400],
194
- [100,200,300,400,100,200,300,400,100,200,300,400],
195
- vector_arry1,
196
- vector_arry2], index: multi_index, order: order_mi))
197
- end
198
-
199
- it "creates a new vector when full index specfied" do
200
- order = DaruLite::MultiIndex.from_tuples([
201
- [:a,:one,:bar],
202
- [:a,:two,:baz],
203
- [:b,:two,:foo],
204
- [:b,:one,:foo],
205
- [:c,:one,:bar]])
206
- answer = DaruLite::DataFrame.new([
207
- vector_arry1,
208
- vector_arry2,
209
- vector_arry1,
210
- vector_arry2,
211
- [100,200,300,400,100,200,300,400,100,200,300,400]
212
- ], index: multi_index, order: order)
213
- df_mi[:c,:one,:bar] = [100,200,300,400,100,200,300,400,100,200,300,400]
214
-
215
- expect(df_mi).to eq(answer)
216
- end
217
-
218
- it "assigns correct name given empty dataframe" do
219
- df_empty = DaruLite::DataFrame.new([], index: multi_index, order: order_mi)
220
- df_empty[:c, :one, :bar] = 1..12
221
-
222
- expect(df_empty[:c, :one, :bar].name).to eq "conebar"
223
- end
224
- end
225
- end
226
-
227
- describe "#add_row" do
228
- subject(:data_frame) {
229
- DaruLite::DataFrame.new({b: [11,12,13,14,15], a: [1,2,3,4,5],
230
- c: [11,22,33,44,55]}, order: [:a, :b, :c],
231
- index: [:one, :two, :three, :four, :five])
232
- }
233
- context 'named' do
234
- before {
235
- data_frame.add_row [100,200,300], :six
236
- }
237
-
238
- it { is_expected.to eq(DaruLite::DataFrame.new({
239
- a: [1,2,3,4,5,100],
240
- b: [11,12,13,14,15,200],
241
- c: [11,22,33,44,55,300]}, order: [:a, :b, :c],
242
- index: [:one, :two, :three, :four, :five, :six]))
243
- }
244
- end
245
-
246
- context 'unnamed' do
247
- before {
248
- data_frame.add_row [100,200,300]
249
- }
250
-
251
- it { is_expected.to eq(DaruLite::DataFrame.new({
252
- a: [1,2,3,4,5,100],
253
- b: [11,12,13,14,15,200],
254
- c: [11,22,33,44,55,300]}, order: [:a, :b, :c],
255
- index: [:one, :two, :three, :four, :five, 5]))
256
- }
257
- end
258
-
259
- context 'with mulitiindex DF' do
260
- subject(:data_frame) do
261
- DaruLite::DataFrame.new({b: [11,12,13], a: [1,2,3],
262
- c: [11,22,33]}, order: [:a, :b, :c],
263
- index: DaruLite::MultiIndex.from_tuples([[:one, :two], [:one, :three], [:two, :four]]))
264
- end
265
-
266
- before { data_frame.add_row [100,200,300], [:two, :five] }
267
-
268
- it { is_expected.to eq(DaruLite::DataFrame.new({
269
- b: [11,12,13,200], a: [1,2,3,100],
270
- c: [11,22,33,300]}, order: [:a, :b, :c],
271
- index: DaruLite::MultiIndex.from_tuples([[:one, :two], [:one, :three], [:two, :four], [:two, :five]])))
272
- }
273
- end
274
-
275
- it "allows adding rows after making empty DF by specfying only order" do
276
- df = DaruLite::DataFrame.new({}, order: [:a, :b, :c])
277
- df.add_row [1,2,3]
278
- df.add_row [5,6,7]
279
-
280
- expect(df[:a]).to eq(DaruLite::Vector.new([1,5]))
281
- expect(df[:b]).to eq(DaruLite::Vector.new([2,6]))
282
- expect(df[:c]).to eq(DaruLite::Vector.new([3,7]))
283
- expect(df.index).to eq(DaruLite::Index.new([0,1]))
284
- end
285
- end
286
-
287
- describe '#add_vector' do
288
- subject(:data_frame) do
289
- DaruLite::DataFrame.new({b: [11,12,13,14,15], a: [1,2,3,4,5],
290
- c: [11,22,33,44,55]}, order: [:a, :b, :c],
291
- index: [:one, :two, :three, :four, :five])
292
- end
293
-
294
- before { data_frame.add_vector :a, [100,200,300,400,500] }
295
-
296
- it { is_expected.to eq(DaruLite::DataFrame.new({
297
- b: [11,12,13,14,15],
298
- a: [100,200,300,400,500],
299
- c: [11,22,33,44,55]}, order: [:a, :b, :c],
300
- index: [:one, :two, :three, :four, :five]))
301
- }
302
- end
303
-
304
- describe "#insert_vector" do
305
- subject(:data_frame) do
306
- DaruLite::DataFrame.new({b: [11,12,13,14,15], a: [1,2,3,4,5],
307
- c: [11,22,33,44,55]}, order: [:a, :b, :c],
308
- index: [:one, :two, :three, :four, :five])
309
- end
310
-
311
- it "insert a new vector at the desired slot" do
312
- df = DaruLite::DataFrame.new({
313
- a: [1,2,3,4,5],
314
- d: [710, 720, 730, 740, 750],
315
- b: [11, 12, 13, 14, 15],
316
- c: [11,22,33,44,55]}, order: [:a, :d, :b, :c],
317
- index: [:one, :two, :three, :four, :five]
318
- )
319
- data_frame.insert_vector 1, :d, [710, 720, 730, 740, 750]
320
- expect(subject).to eq df
321
- end
322
-
323
- it "raises error for data array being too big" do
324
- expect {
325
- source = (1..8).to_a
326
- data_frame.insert_vector 1, :d, source
327
- }.to raise_error(IndexError)
328
- end
329
-
330
- it "raises error for invalid index value" do
331
- expect {
332
- source = (1..5).to_a
333
- data_frame.insert_vector 4, :d, source
334
- }.to raise_error(ArgumentError)
335
- end
336
-
337
- it "raises error for invalid source type" do
338
- expect {
339
- source = 14
340
- data_frame.insert_vector 3, :d, source
341
- }.to raise_error(ArgumentError)
342
- end
343
- end
344
-
345
- describe "#row[]=" do
346
- context DaruLite::Index do
347
- let(:df) do
348
- DaruLite::DataFrame.new(
349
- {
350
- b: [11,12,13,14,15],
351
- a: [1,2,3,4,5],
352
- c: [11,22,33,44,55]
353
- },
354
- order: [:a, :b, :c],
355
- index: [:one, :two, :three, :four, :five]
356
- )
357
- end
358
-
359
- it "assigns specified row when Array" do
360
- df.row[:one] = [49, 99, 59]
361
-
362
- expect(df.row[:one]) .to eq([49, 99, 59].dv(:one, [:a, :b, :c]))
363
- expect(df.row[:one].index).to eq([:a, :b, :c].to_index)
364
- expect(df.row[:one].name) .to eq(:one)
365
- end
366
-
367
- it "assigns specified row when DV" do
368
- df.row[:one] = [49, 99, 59].dv(nil, [:a, :b, :c])
369
-
370
- expect(df.row[:one]).to eq([49, 99, 59].dv(:one, [:a, :b, :c]))
371
- end
372
-
373
- it "assigns correct elements when Vector of different index" do
374
- df.row[:one] = DaruLite::Vector.new([44,62,11], index: [:b,:f,:a])
375
-
376
- expect(df.row[:one]).to eq(DaruLite::Vector.new([11,44,nil], index: [:a,:b,:c]))
377
- end
378
-
379
- it "creates a new row from an Array" do
380
- df.row[:patekar] = [9,2,11]
381
-
382
- expect(df.row[:patekar]).to eq([9,2,11].dv(:patekar, [:a, :b, :c]))
383
- end
384
-
385
- it "creates a new row from a DV" do
386
- df.row[:patekar] = [9,2,11].dv(nil, [:a, :b, :c])
387
-
388
- expect(df.row[:patekar]).to eq([9,2,11].dv(:patekar, [:a, :b, :c]))
389
- end
390
-
391
- it "creates a new row from numeric row index and named DV" do
392
- df.row[2] = [9,2,11].dv(nil, [:a, :b, :c])
393
-
394
- expect(df.row[2]).to eq([9,2,11].dv(nil, [:a, :b, :c]))
395
- end
396
-
397
- it "correctly aligns assigned DV by index" do
398
- df.row[:two] = [9,2,11].dv(nil, [:b, :a, :c])
399
-
400
- expect(df.row[:two]).to eq([2,9,11].dv(:two, [:a, :b, :c]))
401
- end
402
-
403
- it "correctlu aligns assinged DV by index for new rows" do
404
- df.row[:latest] = DaruLite::Vector.new([2,3,1], index: [:b,:c,:a])
405
-
406
- expect(df.row[:latest]).to eq(DaruLite::Vector.new([1,2,3], index: [:a,:b,:c]))
407
- end
408
-
409
- it "inserts nils for indexes that dont exist in the DataFrame" do
410
- df.row[:two] = [49, 99, 59].dv(nil, [:oo, :aah, :gaah])
411
-
412
- expect(df.row[:two]).to eq([nil,nil,nil].dv(nil, [:a, :b, :c]))
413
- end
414
-
415
- it "correctly inserts row of a different length by matching indexes" do
416
- df.row[:four] = [5,4,3,2,1,3].dv(nil, [:you, :have, :a, :big, :appetite, :spock])
417
-
418
- expect(df.row[:four]).to eq([3,nil,nil].dv(:four, [:a, :b, :c]))
419
- end
420
-
421
- it "raises error for row insertion by Array of wrong length" do
422
- expect{
423
- df.row[:one] = [1,2,3,4,5,6,7]
424
- }.to raise_error
425
- end
426
- end
427
-
428
- context DaruLite::MultiIndex do
429
- pending
430
- # TO DO
431
- end
432
-
433
- context DaruLite::CategoricalIndex do
434
- let(:idx) { DaruLite::CategoricalIndex.new [:a, 1, :a, 1, :c] }
435
- let(:df) do
436
- DaruLite::DataFrame.new({
437
- a: 'a'..'e',
438
- b: 1..5
439
- }, index: idx)
440
- end
441
-
442
- context "modify exiting row" do
443
- context "single category" do
444
- subject { df }
445
- before { df.row[:a] = ['x', 'y'] }
446
-
447
- it { is_expected.to be_a DaruLite::DataFrame }
448
- its(:index) { is_expected.to eq idx }
449
- its(:vectors) { is_expected.to eq DaruLite::Index.new [:a, :b] }
450
- its(:'a.to_a') { is_expected.to eq ['x', 'b', 'x', 'd', 'e'] }
451
- its(:'b.to_a') { is_expected.to eq ['y', 2, 'y', 4, 5] }
452
- end
453
-
454
- context "multiple categories" do
455
- subject { df }
456
- before { df.row[:a, 1] = ['x', 'y'] }
457
-
458
- it { is_expected.to be_a DaruLite::DataFrame }
459
- its(:index) { is_expected.to eq idx }
460
- its(:vectors) { is_expected.to eq DaruLite::Index.new [:a, :b] }
461
- its(:'a.to_a') { is_expected.to eq ['x', 'x', 'x', 'x', 'e'] }
462
- its(:'b.to_a') { is_expected.to eq ['y', 'y', 'y', 'y', 5] }
463
- end
464
-
465
- context "positional index" do
466
- subject { df }
467
- before { df.row[0, 2] = ['x', 'y'] }
468
-
469
- it { is_expected.to be_a DaruLite::DataFrame }
470
- its(:index) { is_expected.to eq idx }
471
- its(:vectors) { is_expected.to eq DaruLite::Index.new [:a, :b] }
472
- its(:'a.to_a') { is_expected.to eq ['x', 'b', 'x', 'd', 'e'] }
473
- its(:'b.to_a') { is_expected.to eq ['y', 2, 'y', 4, 5] }
474
- end
475
- end
476
-
477
- context "add new row" do
478
- # TODO
479
- end
480
- end
481
- end
482
- end