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,201 +0,0 @@
|
|
|
1
|
-
shared_examples_for 'an indexable Vector' do |dtype|
|
|
2
|
-
describe "#index_of" do
|
|
3
|
-
context DaruLite::Index do
|
|
4
|
-
let(:vector) do
|
|
5
|
-
DaruLite::Vector.new(
|
|
6
|
-
[1,2,3,4,5],
|
|
7
|
-
name: :a,
|
|
8
|
-
index: [:one, :two, :three, :four, :five],
|
|
9
|
-
dtype:
|
|
10
|
-
)
|
|
11
|
-
end
|
|
12
|
-
it "returns index of specified value" do
|
|
13
|
-
expect(vector.index_of(1)).to eq(:one)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
context DaruLite::MultiIndex do
|
|
18
|
-
let(:vector) { DaruLite::Vector.new([1,2,3,4], index: multi_index, dtype:) }
|
|
19
|
-
let(:multi_index) do
|
|
20
|
-
DaruLite::MultiIndex.from_tuples([
|
|
21
|
-
[:a,:two,:bar],
|
|
22
|
-
[:a,:two,:baz],
|
|
23
|
-
[:b,:one,:bar],
|
|
24
|
-
[:b,:two,:bar]
|
|
25
|
-
])
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "returns tuple of specified value" do
|
|
29
|
-
expect(vector.index_of(3)).to eq([:b,:one,:bar])
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
describe "#index=" do
|
|
35
|
-
subject { vector.index = new_index }
|
|
36
|
-
|
|
37
|
-
let(:vector) { DaruLite::Vector.new([1,2,3,4,5]) }
|
|
38
|
-
|
|
39
|
-
context "new index is an Index" do
|
|
40
|
-
before { subject }
|
|
41
|
-
|
|
42
|
-
let(:new_index) { DaruLite::DateTimeIndex.date_range(start: '2012', periods: 5) }
|
|
43
|
-
|
|
44
|
-
it 'returns the new index' do
|
|
45
|
-
expect(subject).to eq(new_index)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it "simply reassigns index" do
|
|
49
|
-
expect(vector.index.class).to eq(DaruLite::DateTimeIndex)
|
|
50
|
-
expect(vector['2012-1-1']).to eq(1)
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
context "new index is an array" do
|
|
55
|
-
before { subject }
|
|
56
|
-
|
|
57
|
-
let(:new_index) { [5, 4, 3, 2, 1] }
|
|
58
|
-
|
|
59
|
-
it "accepts an array as index" do
|
|
60
|
-
expect(vector.index.class).to eq(DaruLite::Index)
|
|
61
|
-
expect(vector[5]).to eq(1)
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
context "new index is a range" do
|
|
66
|
-
before { subject }
|
|
67
|
-
|
|
68
|
-
let(:new_index) { 'a'..'e' }
|
|
69
|
-
|
|
70
|
-
it "accepts an range as index" do
|
|
71
|
-
expect(vector.index.class).to eq(DaruLite::Index)
|
|
72
|
-
expect(vector['a']).to eq(1)
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
context "new index has a different size" do
|
|
77
|
-
let(:new_index) { DaruLite::Index.new([4,2,6]) }
|
|
78
|
-
|
|
79
|
-
it "raises error for index size != vector size" do
|
|
80
|
-
expect { subject }.to raise_error(
|
|
81
|
-
ArgumentError, 'Size of supplied index 3 does not match size of Vector'
|
|
82
|
-
)
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
describe "#reindex!" do
|
|
88
|
-
subject { vector.reindex!(index) }
|
|
89
|
-
|
|
90
|
-
let(:vector) { DaruLite::Vector.new([1, 2, 3, 4, 5]) }
|
|
91
|
-
let(:index) { DaruLite::Index.new([3, 4, 1, 0, 6]) }
|
|
92
|
-
|
|
93
|
-
before { subject }
|
|
94
|
-
|
|
95
|
-
it "intelligently reindexes" do
|
|
96
|
-
expect(vector).to eq(DaruLite::Vector.new([4, 5, 2, 1, nil], index:))
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
describe "#reindex" do
|
|
101
|
-
subject { vector.reindex(index) }
|
|
102
|
-
|
|
103
|
-
let(:vector) { DaruLite::Vector.new([1, 2, 3, 4, 5]) }
|
|
104
|
-
let(:index) { DaruLite::Index.new([3, 4, 1, 0, 6]) }
|
|
105
|
-
|
|
106
|
-
it "intelligently reindexes" do
|
|
107
|
-
expect(subject).to eq(DaruLite::Vector.new([4, 5, 2, 1, nil], index:))
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
describe '#indexes' do
|
|
112
|
-
context DaruLite::Index do
|
|
113
|
-
subject { vector.indexes 1, 2, nil, Float::NAN }
|
|
114
|
-
|
|
115
|
-
let(:vector) do
|
|
116
|
-
DaruLite::Vector.new(
|
|
117
|
-
[1, 2, 1, 2, 3, nil, nil, Float::NAN],
|
|
118
|
-
index: 11..18
|
|
119
|
-
)
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
it { is_expected.to be_a Array }
|
|
123
|
-
it { is_expected.to eq [11, 12, 13, 14, 16, 17, 18] }
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
context DaruLite::MultiIndex do
|
|
127
|
-
subject { vector.indexes 1, 2, Float::NAN }
|
|
128
|
-
|
|
129
|
-
let(:mi) do
|
|
130
|
-
DaruLite::MultiIndex.from_tuples([
|
|
131
|
-
['M', 2000],
|
|
132
|
-
['M', 2001],
|
|
133
|
-
['M', 2002],
|
|
134
|
-
['M', 2003],
|
|
135
|
-
['F', 2000],
|
|
136
|
-
['F', 2001],
|
|
137
|
-
['F', 2002],
|
|
138
|
-
['F', 2003]
|
|
139
|
-
])
|
|
140
|
-
end
|
|
141
|
-
let(:vector) { DaruLite::Vector.new([1, 2, 1, 2, 3, nil, nil, Float::NAN], index: mi) }
|
|
142
|
-
|
|
143
|
-
it { is_expected.to be_a Array }
|
|
144
|
-
it { is_expected.to eq(
|
|
145
|
-
[
|
|
146
|
-
['M', 2000],
|
|
147
|
-
['M', 2001],
|
|
148
|
-
['M', 2002],
|
|
149
|
-
['M', 2003],
|
|
150
|
-
['F', 2003]
|
|
151
|
-
]) }
|
|
152
|
-
end
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
describe "#reset_index!" do
|
|
156
|
-
subject { vector.reset_index! }
|
|
157
|
-
|
|
158
|
-
context 'after rejecting initial values' do
|
|
159
|
-
let(:vector) do
|
|
160
|
-
v = DaruLite::Vector.new([1, 2, 3, 4, 5, nil, nil, 4, nil])
|
|
161
|
-
v.reject_values(*DaruLite::MISSING_VALUES)
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
it "resets any index to a numerical serialized index" do
|
|
165
|
-
expect(subject).to eq(DaruLite::Vector.new([1, 2, 3, 4, 5, 4]))
|
|
166
|
-
expect(subject.index).to eq(DaruLite::Index.new([0, 1, 2, 3, 4, 5]))
|
|
167
|
-
end
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
context 'when vector is indexed' do
|
|
171
|
-
let(:vector) do
|
|
172
|
-
DaruLite::Vector.new([1, 2, 3, 4, 5], index: [:a, :b, :c, :d, :e])
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
it "resets any index to a numerical serialized index" do
|
|
176
|
-
expect(subject.index).to eq(DaruLite::Index.new([0, 1, 2, 3, 4]))
|
|
177
|
-
end
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
describe "#detach_index" do
|
|
182
|
-
subject { vector.detach_index }
|
|
183
|
-
|
|
184
|
-
let(:vector) do
|
|
185
|
-
DaruLite::Vector.new(
|
|
186
|
-
[1, 2, 3, 4, 5, 6],
|
|
187
|
-
index: ['a', 'b', 'c', 'd', 'e', 'f'],
|
|
188
|
-
name: :values
|
|
189
|
-
)
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
it "creates a DataFrame with first Vector as index and second as values of the Vector" do
|
|
193
|
-
expect(vector.detach_index).to eq(
|
|
194
|
-
DaruLite::DataFrame.new(
|
|
195
|
-
index: ['a', 'b', 'c', 'd', 'e', 'f'],
|
|
196
|
-
values: [1, 2, 3, 4, 5, 6]
|
|
197
|
-
)
|
|
198
|
-
)
|
|
199
|
-
end
|
|
200
|
-
end
|
|
201
|
-
end
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
shared_examples_for 'an iterable Vector' do |dtype|
|
|
2
|
-
let(:vector) do
|
|
3
|
-
DaruLite::Vector.new(
|
|
4
|
-
[5, 5, 5, 5, 5, 6, 6, 7, 8, 9, 10, 1, 2, 3, 4, 11, -99, -99],
|
|
5
|
-
dtype:,
|
|
6
|
-
name: :common_all_dtypes
|
|
7
|
-
)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
describe "#collect" do
|
|
11
|
-
subject { vector.collect { |v| v } }
|
|
12
|
-
|
|
13
|
-
it "returns an Array" do
|
|
14
|
-
expect(subject).to eq([5, 5, 5, 5, 5, 6, 6, 7, 8, 9, 10, 1, 2, 3, 4, 11, -99, -99])
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
describe "#map" do
|
|
19
|
-
subject { vector.map { |v| v } }
|
|
20
|
-
|
|
21
|
-
it "maps" do
|
|
22
|
-
expect(subject).to eq([5, 5, 5, 5, 5, 6, 6, 7, 8, 9, 10, 1, 2, 3, 4, 11, -99, -99])
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
describe "#map!" do
|
|
27
|
-
subject { vector.map! { |v| v + 1 } }
|
|
28
|
-
|
|
29
|
-
it "destructively maps" do
|
|
30
|
-
subject
|
|
31
|
-
expect(vector).to eq(
|
|
32
|
-
DaruLite::Vector.new(
|
|
33
|
-
[6, 6, 6, 6, 6, 7, 7, 8, 9, 10, 11, 2, 3, 4, 5, 12, -98, -98],
|
|
34
|
-
dtype:
|
|
35
|
-
)
|
|
36
|
-
)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
describe "#recode" do
|
|
41
|
-
subject { vector.recode { |v| v == -99 ? 1 : 0 } }
|
|
42
|
-
|
|
43
|
-
it "maps and returns a vector of dtype of self by default" do
|
|
44
|
-
expect(subject).to eq(
|
|
45
|
-
DaruLite::Vector.new [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1]
|
|
46
|
-
)
|
|
47
|
-
expect(subject.dtype).to eq(:array)
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
describe "#recode!" do
|
|
52
|
-
subject { vector.recode! { |v| v == -99 ? 1 : 0 } }
|
|
53
|
-
|
|
54
|
-
let(:vector) do
|
|
55
|
-
DaruLite::Vector.new(
|
|
56
|
-
[5, 5, 5, 5, 5, 6, 6, 7, 8, 9, 10, 1, 2, 3, 4, 11, -99, -99],
|
|
57
|
-
name: :common_all_dtypes,
|
|
58
|
-
dtype:
|
|
59
|
-
)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it "destructively maps and returns a vector of dtype of self by default" do
|
|
63
|
-
subject
|
|
64
|
-
expect(vector).to eq(
|
|
65
|
-
DaruLite::Vector.new [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1]
|
|
66
|
-
)
|
|
67
|
-
expect(vector.dtype).to eq(dtype)
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
describe "#verify" do
|
|
72
|
-
subject { vector.verify { |d| d > 0 } }
|
|
73
|
-
|
|
74
|
-
let(:vector) do
|
|
75
|
-
DaruLite::Vector.new([1,2,3,4,5,6,-99,35,-100], dtype:)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it "returns a hash of invalid data and index of data" do
|
|
79
|
-
expect(subject).to eq({ 6 => -99, 8 => -100 })
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
describe '#replace_values' do
|
|
84
|
-
subject do
|
|
85
|
-
DaruLite::Vector.new(
|
|
86
|
-
[1, 2, 1, 4, nil, Float::NAN, nil, Float::NAN],
|
|
87
|
-
index: 11..18
|
|
88
|
-
)
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
context 'replace nils and NaNs' do
|
|
92
|
-
before { subject.replace_values [nil, Float::NAN], 10 }
|
|
93
|
-
|
|
94
|
-
its(:to_a) { is_expected.to eq [1, 2, 1, 4, 10, 10, 10, 10] }
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
context 'replace arbitrary values' do
|
|
98
|
-
before { subject.replace_values [1, 2], 10 }
|
|
99
|
-
|
|
100
|
-
its(:to_a) { is_expected.to eq(
|
|
101
|
-
[10, 10, 10, 4, nil, Float::NAN, nil, Float::NAN]) }
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
context 'works for single value' do
|
|
105
|
-
before { subject.replace_values nil, 10 }
|
|
106
|
-
|
|
107
|
-
its(:to_a) { is_expected.to eq(
|
|
108
|
-
[1, 2, 1, 4, 10, Float::NAN, 10, Float::NAN]) }
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
shared_examples_for 'a joinable Vector' do |dtype|
|
|
2
|
-
describe "#concat" do
|
|
3
|
-
let(:vector) do
|
|
4
|
-
DaruLite::Vector.new(
|
|
5
|
-
[1, 2, 3, 4, 5],
|
|
6
|
-
name: :yoga,
|
|
7
|
-
index: [:warwick, :thompson, :jackson, :fender, :esp],
|
|
8
|
-
dtype:
|
|
9
|
-
)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "concatenates a new element at the end of vector with index" do
|
|
13
|
-
vector.concat(6, :ibanez)
|
|
14
|
-
|
|
15
|
-
expect(vector.index) .to eq(
|
|
16
|
-
DaruLite::Index.new([:warwick, :thompson, :jackson, :fender, :esp, :ibanez]))
|
|
17
|
-
expect(vector[:ibanez]).to eq(6)
|
|
18
|
-
expect(vector[5]) .to eq(6)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "raises error if index not specified" do
|
|
22
|
-
expect { vector.concat(6) }.to raise_error
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
shared_examples_for 'a missable Vector' do
|
|
2
|
-
describe "#replace_nils" do
|
|
3
|
-
subject { vector.replace_nils(2) }
|
|
4
|
-
|
|
5
|
-
let(:vector) { DaruLite::Vector.new([1, 2, 3, nil, nil, 4]) }
|
|
6
|
-
|
|
7
|
-
it "replaces all nils with the specified value" do
|
|
8
|
-
expect(subject).to eq(DaruLite::Vector.new([1, 2, 3, 2, 2, 4]))
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "replaces all nils with the specified value (bang)" do
|
|
12
|
-
vec = DaruLite::Vector.new([1,2,3,nil,nil,4]).replace_nils!(2)
|
|
13
|
-
expect(vec).to eq(DaruLite::Vector.new([1,2,3,2,2,4]))
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
describe "#replace_nils" do
|
|
18
|
-
subject { vector.replace_nils!(2) }
|
|
19
|
-
|
|
20
|
-
let(:vector) { DaruLite::Vector.new([1, 2, 3, nil, nil, 4]) }
|
|
21
|
-
|
|
22
|
-
it "replaces all nils with the specified value (bang)" do
|
|
23
|
-
subject
|
|
24
|
-
expect(vector).to eq(DaruLite::Vector.new([1, 2, 3, 2, 2, 4]))
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
describe '#rolling_fillna!' do
|
|
29
|
-
subject do
|
|
30
|
-
DaruLite::Vector.new(
|
|
31
|
-
[Float::NAN, 2, 1, 4, nil, Float::NAN, 3, nil, Float::NAN]
|
|
32
|
-
)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
context 'rolling_fillna! forwards' do
|
|
36
|
-
before { subject.rolling_fillna!(:forward) }
|
|
37
|
-
|
|
38
|
-
its(:to_a) { is_expected.to eq [0, 2, 1, 4, 4, 4, 3, 3, 3] }
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
context 'rolling_fillna! backwards' do
|
|
42
|
-
before { subject.rolling_fillna!(direction: :backward) }
|
|
43
|
-
|
|
44
|
-
its(:to_a) { is_expected.to eq [2, 2, 1, 4, 3, 3, 3, 0, 0] }
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
context 'all invalid vector' do
|
|
48
|
-
subject do
|
|
49
|
-
DaruLite::Vector.new(
|
|
50
|
-
[Float::NAN, Float::NAN, Float::NAN, Float::NAN, Float::NAN]
|
|
51
|
-
)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
before { subject.rolling_fillna!(:forward) }
|
|
55
|
-
|
|
56
|
-
its(:to_a) { is_expected.to eq [0, 0, 0, 0, 0] }
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
context 'with non-default index' do
|
|
60
|
-
subject do
|
|
61
|
-
DaruLite::Vector.new(
|
|
62
|
-
[Float::NAN, 2, 1, 4, nil, Float::NAN, 3, nil, Float::NAN],
|
|
63
|
-
index: %w[a b c d e f g h i]
|
|
64
|
-
)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
before { subject.rolling_fillna!(direction: :backward) }
|
|
68
|
-
|
|
69
|
-
it { is_expected.to eq DaruLite::Vector.new([2, 2, 1, 4, 3, 3, 3, 0, 0], index: %w[a b c d e f g h i]) }
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
describe '#rolling_fillna' do
|
|
74
|
-
subject do
|
|
75
|
-
DaruLite::Vector.new(
|
|
76
|
-
[Float::NAN, 2, 1, 4, nil, Float::NAN, 3, nil, Float::NAN]
|
|
77
|
-
)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
context 'rolling_fillna forwards' do
|
|
81
|
-
it { expect(subject.rolling_fillna(:forward).to_a).to eq [0, 2, 1, 4, 4, 4, 3, 3, 3] }
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
context 'rolling_fillna backwards' do
|
|
85
|
-
it { expect(subject.rolling_fillna(direction: :backward).to_a).to eq [2, 2, 1, 4, 3, 3, 3, 0, 0] }
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
shared_examples_for 'a queryable Vector' do
|
|
2
|
-
describe '#include_values?' do
|
|
3
|
-
context 'only nils' do
|
|
4
|
-
context 'true' do
|
|
5
|
-
let(:vector) { DaruLite::Vector.new [1, 2, 3, :a, 'Unknown', nil] }
|
|
6
|
-
it { expect(vector.include_values? nil).to eq true }
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
context 'false' do
|
|
10
|
-
let(:vector) { DaruLite::Vector.new [1, 2, 3, :a, 'Unknown'] }
|
|
11
|
-
it { expect(vector.include_values? nil).to eq false }
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
context 'only Float::NAN' do
|
|
16
|
-
context 'true' do
|
|
17
|
-
let(:vector) { DaruLite::Vector.new [1, nil, 2, 3, Float::NAN] }
|
|
18
|
-
it { expect(vector.include_values? Float::NAN).to eq true }
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
context 'false' do
|
|
22
|
-
let(:vector) { DaruLite::Vector.new [1, nil, 2, 3] }
|
|
23
|
-
it { expect(vector.include_values? Float::NAN).to eq false }
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
context 'both nil and Float::NAN' do
|
|
28
|
-
context 'true with only nil' do
|
|
29
|
-
let(:vector) { DaruLite::Vector.new [1, Float::NAN, 2, 3] }
|
|
30
|
-
it { expect(vector.include_values? nil, Float::NAN).to eq true }
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context 'true with only Float::NAN' do
|
|
34
|
-
let(:vector) { DaruLite::Vector.new [1, nil, 2, 3] }
|
|
35
|
-
it { expect(vector.include_values? nil, Float::NAN).to eq true }
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
context 'false' do
|
|
39
|
-
let(:vector) { DaruLite::Vector.new [1, 2, 3] }
|
|
40
|
-
it { expect(vector.include_values? nil, Float::NAN).to eq false }
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
context 'any other value' do
|
|
45
|
-
context 'true' do
|
|
46
|
-
let(:vector) { DaruLite::Vector.new [1, 2, 3, 4, nil] }
|
|
47
|
-
it { expect(vector.include_values? 1, 2, 3, 5).to eq true }
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
context 'false' do
|
|
51
|
-
let(:vector) { DaruLite::Vector.new [1, 2, 3, 4, nil] }
|
|
52
|
-
it { expect(vector.include_values? 5, 6).to eq false }
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
describe "#any?" do
|
|
58
|
-
let(:vector) { DaruLite::Vector.new([1, 2, 3, 4, 5]) }
|
|
59
|
-
|
|
60
|
-
it "returns true if block returns true for any one of the elements" do
|
|
61
|
-
expect(vector.any?{ |e| e == 1 }).to eq(true)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it "returns false if block is false for all elements" do
|
|
65
|
-
expect(vector.any?{ |e| e > 10 }).to eq(false)
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
describe "#all?" do
|
|
70
|
-
let(:vector) { DaruLite::Vector.new([1, 2, 3, 4, 5]) }
|
|
71
|
-
|
|
72
|
-
it "returns true if block is true for all elements" do
|
|
73
|
-
expect(vector.all? { |e| e < 6 }).to eq(true)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it "returns false if block is false for any one element" do
|
|
77
|
-
expect(vector.all? { |e| e == 2 }).to eq(false)
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
describe '#match' do
|
|
82
|
-
subject { dv.match(regexp) }
|
|
83
|
-
|
|
84
|
-
context 'returns matching array for a given regexp' do
|
|
85
|
-
let(:dv) { DaruLite::Vector.new ['3 days', '5 weeks', '2 weeks'] }
|
|
86
|
-
let(:regexp) { /weeks/ }
|
|
87
|
-
|
|
88
|
-
it { is_expected.to eq([false, true, true]) }
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|