daru_lite 0.3.4 → 0.4.0
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.
- checksums.yaml +4 -4
- data/History.md +84 -0
- data/README.md +16 -1
- data/lib/daru_lite/category.rb +1 -1
- data/lib/daru_lite/core/group_by.rb +0 -4
- data/lib/daru_lite/core/merge.rb +2 -2
- data/lib/daru_lite/data_frame/calculatable.rb +12 -6
- data/lib/daru_lite/data_frame/duplicatable.rb +0 -14
- data/lib/daru_lite/data_frame/iterable.rb +2 -2
- data/lib/daru_lite/data_frame/missable.rb +0 -9
- data/lib/daru_lite/dataframe.rb +34 -9
- data/lib/daru_lite/date_time/index.rb +4 -4
- data/lib/daru_lite/index/multi_index.rb +1 -2
- data/lib/daru_lite/maths/statistics/dataframe.rb +2 -4
- data/lib/daru_lite/maths/statistics/vector.rb +3 -8
- data/lib/daru_lite/monkeys/array.rb +4 -0
- data/lib/daru_lite/monkeys/hash.rb +3 -0
- data/lib/daru_lite/monkeys/matrix.rb +3 -0
- data/lib/daru_lite/monkeys/range.rb +4 -0
- data/lib/daru_lite/vector/missable.rb +0 -55
- data/lib/daru_lite/vector/sortable.rb +2 -2
- data/lib/daru_lite/vector.rb +3 -9
- data/lib/daru_lite/version.rb +1 -1
- data/lib/daru_lite.rb +8 -10
- metadata +54 -287
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- data/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- data/.github/dependabot.yml +0 -11
- data/.github/workflows/ci.yml +0 -33
- data/.gitignore +0 -10
- data/.rspec +0 -2
- data/.rubocop.yml +0 -27
- data/.rubocop_todo.yml +0 -139
- data/CONTRIBUTING.md +0 -47
- data/Gemfile +0 -2
- data/Rakefile +0 -69
- data/ReleasePolicy.md +0 -20
- data/benchmarks/TradeoffData.csv +0 -65
- data/benchmarks/csv_reading.rb +0 -22
- data/benchmarks/dataframe_creation.rb +0 -39
- data/benchmarks/db_loading.rb +0 -33
- data/benchmarks/duplicating.rb +0 -45
- data/benchmarks/group_by.rb +0 -32
- data/benchmarks/joining.rb +0 -52
- data/benchmarks/row_access.rb +0 -41
- data/benchmarks/row_assign.rb +0 -36
- data/benchmarks/sorting.rb +0 -51
- data/benchmarks/statistics.rb +0 -28
- data/benchmarks/vector_access.rb +0 -31
- data/benchmarks/vector_assign.rb +0 -42
- data/benchmarks/where_clause.rb +0 -48
- data/benchmarks/where_vs_filter.rb +0 -28
- data/daru_lite.gemspec +0 -54
- data/daru_lite_test-shm +0 -0
- data/daru_lite_test-wal +0 -0
- data/images/README.md +0 -5
- data/images/con0.png +0 -0
- data/images/con1.png +0 -0
- data/images/init0.png +0 -0
- data/images/init1.png +0 -0
- data/images/man0.png +0 -0
- data/images/man1.png +0 -0
- data/images/man2.png +0 -0
- data/images/man3.png +0 -0
- data/images/man4.png +0 -0
- data/images/man5.png +0 -0
- data/images/man6.png +0 -0
- data/lib/daru_lite/accessors/mdarray_wrapper.rb +0 -7
- data/lib/daru_lite/monkeys/m_d_array.rb +0 -7
- data/lib/daru_lite/monkeys/object.rb +0 -7
- data/profile/_base.rb +0 -23
- data/profile/df_to_a.rb +0 -10
- data/profile/filter.rb +0 -13
- data/profile/joining.rb +0 -13
- data/profile/sorting.rb +0 -12
- data/profile/vector_each_with_index.rb +0 -9
- data/profile/vector_new.rb +0 -9
- data/spec/accessors/array_wrapper_spec.rb +0 -3
- data/spec/category_spec.rb +0 -1767
- data/spec/core/group_by_spec.rb +0 -655
- data/spec/core/merge_spec.rb +0 -179
- data/spec/core/query_spec.rb +0 -347
- data/spec/daru_lite_spec.rb +0 -22
- data/spec/data_frame/aggregatable_example.rb +0 -65
- data/spec/data_frame/buildable_example.rb +0 -109
- data/spec/data_frame/calculatable_example.rb +0 -135
- data/spec/data_frame/convertible_example.rb +0 -180
- data/spec/data_frame/duplicatable_example.rb +0 -134
- data/spec/data_frame/fetchable_example.rb +0 -510
- data/spec/data_frame/filterable_example.rb +0 -456
- data/spec/data_frame/indexable_example.rb +0 -221
- data/spec/data_frame/iterable_example.rb +0 -481
- data/spec/data_frame/joinable_example.rb +0 -131
- data/spec/data_frame/missable_example.rb +0 -47
- data/spec/data_frame/pivotable_example.rb +0 -297
- data/spec/data_frame/queryable_example.rb +0 -92
- data/spec/data_frame/setable_example.rb +0 -513
- data/spec/data_frame/sortable_example.rb +0 -368
- data/spec/dataframe_spec.rb +0 -1342
- data/spec/date_time/data_spec.rb +0 -197
- data/spec/date_time/date_time_index_helper_spec.rb +0 -72
- data/spec/date_time/index_spec.rb +0 -588
- data/spec/date_time/offsets_spec.rb +0 -465
- data/spec/extensions/which_dsl_spec.rb +0 -38
- data/spec/fixtures/bank2.dat +0 -200
- data/spec/fixtures/boolean_converter_test.csv +0 -5
- data/spec/fixtures/countries.json +0 -7794
- data/spec/fixtures/duplicates.csv +0 -32
- data/spec/fixtures/eciresults.html +0 -394
- data/spec/fixtures/empties.dat +0 -2
- data/spec/fixtures/empty_rows_test.csv +0 -17
- data/spec/fixtures/macau.html +0 -3691
- data/spec/fixtures/macd_data.csv +0 -150
- data/spec/fixtures/matrix_test.csv +0 -100
- data/spec/fixtures/moneycontrol.html +0 -6812
- data/spec/fixtures/music_data.tsv +0 -2501
- data/spec/fixtures/repeated_fields.csv +0 -7
- data/spec/fixtures/sales-funnel.csv +0 -18
- data/spec/fixtures/scientific_notation.csv +0 -4
- data/spec/fixtures/string_converter_test.csv +0 -5
- data/spec/fixtures/strings.dat +0 -2
- data/spec/fixtures/test_xls.xls +0 -0
- data/spec/fixtures/test_xls_2.xls +0 -0
- data/spec/fixtures/url_test.txt~ +0 -0
- data/spec/fixtures/valid_markup.html +0 -62
- data/spec/fixtures/wiki_climate.html +0 -1243
- data/spec/fixtures/wiki_table_info.html +0 -631
- data/spec/formatters/table_formatter_spec.rb +0 -137
- data/spec/helpers_spec.rb +0 -8
- data/spec/index/categorical_index_spec.rb +0 -289
- data/spec/index/index_spec.rb +0 -438
- data/spec/index/multi_index_spec.rb +0 -752
- data/spec/io/io_spec.rb +0 -357
- data/spec/io/sql_data_source_spec.rb +0 -48
- data/spec/iruby/dataframe_spec.rb +0 -170
- data/spec/iruby/helpers_spec.rb +0 -49
- data/spec/iruby/multi_index_spec.rb +0 -37
- data/spec/iruby/vector_spec.rb +0 -105
- data/spec/maths/arithmetic/dataframe_spec.rb +0 -148
- data/spec/maths/arithmetic/vector_spec.rb +0 -165
- data/spec/maths/statistics/dataframe_spec.rb +0 -191
- data/spec/maths/statistics/vector_spec.rb +0 -756
- data/spec/monkeys_spec.rb +0 -42
- data/spec/shared/vector_display_spec.rb +0 -213
- data/spec/spec_helper.rb +0 -87
- data/spec/support/database_helper.rb +0 -29
- data/spec/support/matchers.rb +0 -5
- data/spec/vector/aggregatable_example.rb +0 -27
- data/spec/vector/calculatable_example.rb +0 -82
- data/spec/vector/convertible_example.rb +0 -126
- data/spec/vector/duplicatable_example.rb +0 -48
- data/spec/vector/fetchable_example.rb +0 -463
- data/spec/vector/filterable_example.rb +0 -165
- data/spec/vector/indexable_example.rb +0 -201
- data/spec/vector/iterable_example.rb +0 -111
- data/spec/vector/joinable_example.rb +0 -25
- data/spec/vector/missable_example.rb +0 -88
- data/spec/vector/queryable_example.rb +0 -91
- data/spec/vector/setable_example.rb +0 -300
- data/spec/vector/sortable_example.rb +0 -242
- data/spec/vector_spec.rb +0 -599
|
@@ -1,513 +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
|
-
|
|
225
|
-
context "with duplicate tuples" do
|
|
226
|
-
let(:dup_df) do
|
|
227
|
-
DaruLite::DataFrame.new(
|
|
228
|
-
[[1, 2], [3, 4], [5, 6], [7, 8]],
|
|
229
|
-
order: DaruLite::MultiIndex.from_tuples([
|
|
230
|
-
[:weighted_count, 'Wave'], [:weighted_count, 'Wave'],
|
|
231
|
-
[:percentage, 'Wave'], [:percentage, 'Wave']
|
|
232
|
-
]),
|
|
233
|
-
index: %w[Yes No]
|
|
234
|
-
)
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
it "assigns every column matching a duplicate full tuple" do
|
|
238
|
-
dup_df[:weighted_count, 'Wave'] = [10, 20]
|
|
239
|
-
|
|
240
|
-
expect(dup_df.data.map(&:to_a)).to eq([[10, 20], [10, 20], [5, 6], [7, 8]])
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
it "assigns independent Vector instances to duplicate columns" do
|
|
244
|
-
dup_df[:weighted_count, 'Wave'] = [10, 20]
|
|
245
|
-
|
|
246
|
-
expect(dup_df.data[0].object_id).not_to eq(dup_df.data[1].object_id)
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
it "assigns every column matching a partial key" do
|
|
250
|
-
dup_df[:percentage] = [99, 98]
|
|
251
|
-
|
|
252
|
-
expect(dup_df.data.map(&:to_a)).to eq([[1, 2], [3, 4], [99, 98], [99, 98]])
|
|
253
|
-
end
|
|
254
|
-
end
|
|
255
|
-
end
|
|
256
|
-
end
|
|
257
|
-
|
|
258
|
-
describe "#add_row" do
|
|
259
|
-
subject(:data_frame) {
|
|
260
|
-
DaruLite::DataFrame.new({b: [11,12,13,14,15], a: [1,2,3,4,5],
|
|
261
|
-
c: [11,22,33,44,55]}, order: [:a, :b, :c],
|
|
262
|
-
index: [:one, :two, :three, :four, :five])
|
|
263
|
-
}
|
|
264
|
-
context 'named' do
|
|
265
|
-
before {
|
|
266
|
-
data_frame.add_row [100,200,300], :six
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
it { is_expected.to eq(DaruLite::DataFrame.new({
|
|
270
|
-
a: [1,2,3,4,5,100],
|
|
271
|
-
b: [11,12,13,14,15,200],
|
|
272
|
-
c: [11,22,33,44,55,300]}, order: [:a, :b, :c],
|
|
273
|
-
index: [:one, :two, :three, :four, :five, :six]))
|
|
274
|
-
}
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
context 'unnamed' do
|
|
278
|
-
before {
|
|
279
|
-
data_frame.add_row [100,200,300]
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
it { is_expected.to eq(DaruLite::DataFrame.new({
|
|
283
|
-
a: [1,2,3,4,5,100],
|
|
284
|
-
b: [11,12,13,14,15,200],
|
|
285
|
-
c: [11,22,33,44,55,300]}, order: [:a, :b, :c],
|
|
286
|
-
index: [:one, :two, :three, :four, :five, 5]))
|
|
287
|
-
}
|
|
288
|
-
end
|
|
289
|
-
|
|
290
|
-
context 'with mulitiindex DF' do
|
|
291
|
-
subject(:data_frame) do
|
|
292
|
-
DaruLite::DataFrame.new({b: [11,12,13], a: [1,2,3],
|
|
293
|
-
c: [11,22,33]}, order: [:a, :b, :c],
|
|
294
|
-
index: DaruLite::MultiIndex.from_tuples([[:one, :two], [:one, :three], [:two, :four]]))
|
|
295
|
-
end
|
|
296
|
-
|
|
297
|
-
before { data_frame.add_row [100,200,300], [:two, :five] }
|
|
298
|
-
|
|
299
|
-
it { is_expected.to eq(DaruLite::DataFrame.new({
|
|
300
|
-
b: [11,12,13,200], a: [1,2,3,100],
|
|
301
|
-
c: [11,22,33,300]}, order: [:a, :b, :c],
|
|
302
|
-
index: DaruLite::MultiIndex.from_tuples([[:one, :two], [:one, :three], [:two, :four], [:two, :five]])))
|
|
303
|
-
}
|
|
304
|
-
end
|
|
305
|
-
|
|
306
|
-
it "allows adding rows after making empty DF by specfying only order" do
|
|
307
|
-
df = DaruLite::DataFrame.new({}, order: [:a, :b, :c])
|
|
308
|
-
df.add_row [1,2,3]
|
|
309
|
-
df.add_row [5,6,7]
|
|
310
|
-
|
|
311
|
-
expect(df[:a]).to eq(DaruLite::Vector.new([1,5]))
|
|
312
|
-
expect(df[:b]).to eq(DaruLite::Vector.new([2,6]))
|
|
313
|
-
expect(df[:c]).to eq(DaruLite::Vector.new([3,7]))
|
|
314
|
-
expect(df.index).to eq(DaruLite::Index.new([0,1]))
|
|
315
|
-
end
|
|
316
|
-
end
|
|
317
|
-
|
|
318
|
-
describe '#add_vector' do
|
|
319
|
-
subject(:data_frame) do
|
|
320
|
-
DaruLite::DataFrame.new({b: [11,12,13,14,15], a: [1,2,3,4,5],
|
|
321
|
-
c: [11,22,33,44,55]}, order: [:a, :b, :c],
|
|
322
|
-
index: [:one, :two, :three, :four, :five])
|
|
323
|
-
end
|
|
324
|
-
|
|
325
|
-
before { data_frame.add_vector :a, [100,200,300,400,500] }
|
|
326
|
-
|
|
327
|
-
it { is_expected.to eq(DaruLite::DataFrame.new({
|
|
328
|
-
b: [11,12,13,14,15],
|
|
329
|
-
a: [100,200,300,400,500],
|
|
330
|
-
c: [11,22,33,44,55]}, order: [:a, :b, :c],
|
|
331
|
-
index: [:one, :two, :three, :four, :five]))
|
|
332
|
-
}
|
|
333
|
-
end
|
|
334
|
-
|
|
335
|
-
describe "#insert_vector" do
|
|
336
|
-
subject(:data_frame) do
|
|
337
|
-
DaruLite::DataFrame.new({b: [11,12,13,14,15], a: [1,2,3,4,5],
|
|
338
|
-
c: [11,22,33,44,55]}, order: [:a, :b, :c],
|
|
339
|
-
index: [:one, :two, :three, :four, :five])
|
|
340
|
-
end
|
|
341
|
-
|
|
342
|
-
it "insert a new vector at the desired slot" do
|
|
343
|
-
df = DaruLite::DataFrame.new({
|
|
344
|
-
a: [1,2,3,4,5],
|
|
345
|
-
d: [710, 720, 730, 740, 750],
|
|
346
|
-
b: [11, 12, 13, 14, 15],
|
|
347
|
-
c: [11,22,33,44,55]}, order: [:a, :d, :b, :c],
|
|
348
|
-
index: [:one, :two, :three, :four, :five]
|
|
349
|
-
)
|
|
350
|
-
data_frame.insert_vector 1, :d, [710, 720, 730, 740, 750]
|
|
351
|
-
expect(subject).to eq df
|
|
352
|
-
end
|
|
353
|
-
|
|
354
|
-
it "raises error for data array being too big" do
|
|
355
|
-
expect {
|
|
356
|
-
source = (1..8).to_a
|
|
357
|
-
data_frame.insert_vector 1, :d, source
|
|
358
|
-
}.to raise_error(IndexError)
|
|
359
|
-
end
|
|
360
|
-
|
|
361
|
-
it "raises error for invalid index value" do
|
|
362
|
-
expect {
|
|
363
|
-
source = (1..5).to_a
|
|
364
|
-
data_frame.insert_vector 4, :d, source
|
|
365
|
-
}.to raise_error(ArgumentError)
|
|
366
|
-
end
|
|
367
|
-
|
|
368
|
-
it "raises error for invalid source type" do
|
|
369
|
-
expect {
|
|
370
|
-
source = 14
|
|
371
|
-
data_frame.insert_vector 3, :d, source
|
|
372
|
-
}.to raise_error(ArgumentError)
|
|
373
|
-
end
|
|
374
|
-
end
|
|
375
|
-
|
|
376
|
-
describe "#row[]=" do
|
|
377
|
-
context DaruLite::Index do
|
|
378
|
-
let(:df) do
|
|
379
|
-
DaruLite::DataFrame.new(
|
|
380
|
-
{
|
|
381
|
-
b: [11,12,13,14,15],
|
|
382
|
-
a: [1,2,3,4,5],
|
|
383
|
-
c: [11,22,33,44,55]
|
|
384
|
-
},
|
|
385
|
-
order: [:a, :b, :c],
|
|
386
|
-
index: [:one, :two, :three, :four, :five]
|
|
387
|
-
)
|
|
388
|
-
end
|
|
389
|
-
|
|
390
|
-
it "assigns specified row when Array" do
|
|
391
|
-
df.row[:one] = [49, 99, 59]
|
|
392
|
-
|
|
393
|
-
expect(df.row[:one]) .to eq([49, 99, 59].dv(:one, [:a, :b, :c]))
|
|
394
|
-
expect(df.row[:one].index).to eq([:a, :b, :c].to_index)
|
|
395
|
-
expect(df.row[:one].name) .to eq(:one)
|
|
396
|
-
end
|
|
397
|
-
|
|
398
|
-
it "assigns specified row when DV" do
|
|
399
|
-
df.row[:one] = [49, 99, 59].dv(nil, [:a, :b, :c])
|
|
400
|
-
|
|
401
|
-
expect(df.row[:one]).to eq([49, 99, 59].dv(:one, [:a, :b, :c]))
|
|
402
|
-
end
|
|
403
|
-
|
|
404
|
-
it "assigns correct elements when Vector of different index" do
|
|
405
|
-
df.row[:one] = DaruLite::Vector.new([44,62,11], index: [:b,:f,:a])
|
|
406
|
-
|
|
407
|
-
expect(df.row[:one]).to eq(DaruLite::Vector.new([11,44,nil], index: [:a,:b,:c]))
|
|
408
|
-
end
|
|
409
|
-
|
|
410
|
-
it "creates a new row from an Array" do
|
|
411
|
-
df.row[:patekar] = [9,2,11]
|
|
412
|
-
|
|
413
|
-
expect(df.row[:patekar]).to eq([9,2,11].dv(:patekar, [:a, :b, :c]))
|
|
414
|
-
end
|
|
415
|
-
|
|
416
|
-
it "creates a new row from a DV" do
|
|
417
|
-
df.row[:patekar] = [9,2,11].dv(nil, [:a, :b, :c])
|
|
418
|
-
|
|
419
|
-
expect(df.row[:patekar]).to eq([9,2,11].dv(:patekar, [:a, :b, :c]))
|
|
420
|
-
end
|
|
421
|
-
|
|
422
|
-
it "creates a new row from numeric row index and named DV" do
|
|
423
|
-
df.row[2] = [9,2,11].dv(nil, [:a, :b, :c])
|
|
424
|
-
|
|
425
|
-
expect(df.row[2]).to eq([9,2,11].dv(nil, [:a, :b, :c]))
|
|
426
|
-
end
|
|
427
|
-
|
|
428
|
-
it "correctly aligns assigned DV by index" do
|
|
429
|
-
df.row[:two] = [9,2,11].dv(nil, [:b, :a, :c])
|
|
430
|
-
|
|
431
|
-
expect(df.row[:two]).to eq([2,9,11].dv(:two, [:a, :b, :c]))
|
|
432
|
-
end
|
|
433
|
-
|
|
434
|
-
it "correctlu aligns assinged DV by index for new rows" do
|
|
435
|
-
df.row[:latest] = DaruLite::Vector.new([2,3,1], index: [:b,:c,:a])
|
|
436
|
-
|
|
437
|
-
expect(df.row[:latest]).to eq(DaruLite::Vector.new([1,2,3], index: [:a,:b,:c]))
|
|
438
|
-
end
|
|
439
|
-
|
|
440
|
-
it "inserts nils for indexes that dont exist in the DataFrame" do
|
|
441
|
-
df.row[:two] = [49, 99, 59].dv(nil, [:oo, :aah, :gaah])
|
|
442
|
-
|
|
443
|
-
expect(df.row[:two]).to eq([nil,nil,nil].dv(nil, [:a, :b, :c]))
|
|
444
|
-
end
|
|
445
|
-
|
|
446
|
-
it "correctly inserts row of a different length by matching indexes" do
|
|
447
|
-
df.row[:four] = [5,4,3,2,1,3].dv(nil, [:you, :have, :a, :big, :appetite, :spock])
|
|
448
|
-
|
|
449
|
-
expect(df.row[:four]).to eq([3,nil,nil].dv(:four, [:a, :b, :c]))
|
|
450
|
-
end
|
|
451
|
-
|
|
452
|
-
it "raises error for row insertion by Array of wrong length" do
|
|
453
|
-
expect{
|
|
454
|
-
df.row[:one] = [1,2,3,4,5,6,7]
|
|
455
|
-
}.to raise_error
|
|
456
|
-
end
|
|
457
|
-
end
|
|
458
|
-
|
|
459
|
-
context DaruLite::MultiIndex do
|
|
460
|
-
pending
|
|
461
|
-
# TO DO
|
|
462
|
-
end
|
|
463
|
-
|
|
464
|
-
context DaruLite::CategoricalIndex do
|
|
465
|
-
let(:idx) { DaruLite::CategoricalIndex.new [:a, 1, :a, 1, :c] }
|
|
466
|
-
let(:df) do
|
|
467
|
-
DaruLite::DataFrame.new({
|
|
468
|
-
a: 'a'..'e',
|
|
469
|
-
b: 1..5
|
|
470
|
-
}, index: idx)
|
|
471
|
-
end
|
|
472
|
-
|
|
473
|
-
context "modify exiting row" do
|
|
474
|
-
context "single category" do
|
|
475
|
-
subject { df }
|
|
476
|
-
before { df.row[:a] = ['x', 'y'] }
|
|
477
|
-
|
|
478
|
-
it { is_expected.to be_a DaruLite::DataFrame }
|
|
479
|
-
its(:index) { is_expected.to eq idx }
|
|
480
|
-
its(:vectors) { is_expected.to eq DaruLite::Index.new [:a, :b] }
|
|
481
|
-
its(:'a.to_a') { is_expected.to eq ['x', 'b', 'x', 'd', 'e'] }
|
|
482
|
-
its(:'b.to_a') { is_expected.to eq ['y', 2, 'y', 4, 5] }
|
|
483
|
-
end
|
|
484
|
-
|
|
485
|
-
context "multiple categories" do
|
|
486
|
-
subject { df }
|
|
487
|
-
before { df.row[:a, 1] = ['x', 'y'] }
|
|
488
|
-
|
|
489
|
-
it { is_expected.to be_a DaruLite::DataFrame }
|
|
490
|
-
its(:index) { is_expected.to eq idx }
|
|
491
|
-
its(:vectors) { is_expected.to eq DaruLite::Index.new [:a, :b] }
|
|
492
|
-
its(:'a.to_a') { is_expected.to eq ['x', 'x', 'x', 'x', 'e'] }
|
|
493
|
-
its(:'b.to_a') { is_expected.to eq ['y', 'y', 'y', 'y', 5] }
|
|
494
|
-
end
|
|
495
|
-
|
|
496
|
-
context "positional index" do
|
|
497
|
-
subject { df }
|
|
498
|
-
before { df.row[0, 2] = ['x', 'y'] }
|
|
499
|
-
|
|
500
|
-
it { is_expected.to be_a DaruLite::DataFrame }
|
|
501
|
-
its(:index) { is_expected.to eq idx }
|
|
502
|
-
its(:vectors) { is_expected.to eq DaruLite::Index.new [:a, :b] }
|
|
503
|
-
its(:'a.to_a') { is_expected.to eq ['x', 'b', 'x', 'd', 'e'] }
|
|
504
|
-
its(:'b.to_a') { is_expected.to eq ['y', 2, 'y', 4, 5] }
|
|
505
|
-
end
|
|
506
|
-
end
|
|
507
|
-
|
|
508
|
-
context "add new row" do
|
|
509
|
-
# TODO
|
|
510
|
-
end
|
|
511
|
-
end
|
|
512
|
-
end
|
|
513
|
-
end
|