daru_lite 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +60 -0
  3. data/README.md +1 -1
  4. data/lib/daru_lite/category.rb +1 -1
  5. data/lib/daru_lite/date_time/index.rb +2 -2
  6. data/lib/daru_lite/maths/statistics/vector.rb +1 -1
  7. data/lib/daru_lite/version.rb +1 -1
  8. data/lib/daru_lite.rb +1 -0
  9. metadata +54 -284
  10. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  11. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  12. data/.github/dependabot.yml +0 -11
  13. data/.github/workflows/ci.yml +0 -33
  14. data/.gitignore +0 -10
  15. data/.rspec +0 -2
  16. data/.rubocop.yml +0 -27
  17. data/.rubocop_todo.yml +0 -139
  18. data/CONTRIBUTING.md +0 -47
  19. data/Gemfile +0 -2
  20. data/Rakefile +0 -69
  21. data/ReleasePolicy.md +0 -20
  22. data/benchmarks/TradeoffData.csv +0 -65
  23. data/benchmarks/csv_reading.rb +0 -22
  24. data/benchmarks/dataframe_creation.rb +0 -39
  25. data/benchmarks/db_loading.rb +0 -33
  26. data/benchmarks/duplicating.rb +0 -45
  27. data/benchmarks/group_by.rb +0 -32
  28. data/benchmarks/joining.rb +0 -52
  29. data/benchmarks/row_access.rb +0 -41
  30. data/benchmarks/row_assign.rb +0 -36
  31. data/benchmarks/sorting.rb +0 -51
  32. data/benchmarks/statistics.rb +0 -28
  33. data/benchmarks/vector_access.rb +0 -31
  34. data/benchmarks/vector_assign.rb +0 -42
  35. data/benchmarks/where_clause.rb +0 -48
  36. data/benchmarks/where_vs_filter.rb +0 -28
  37. data/daru_lite.gemspec +0 -54
  38. data/daru_lite_test-shm +0 -0
  39. data/daru_lite_test-wal +0 -0
  40. data/images/README.md +0 -5
  41. data/images/con0.png +0 -0
  42. data/images/con1.png +0 -0
  43. data/images/init0.png +0 -0
  44. data/images/init1.png +0 -0
  45. data/images/man0.png +0 -0
  46. data/images/man1.png +0 -0
  47. data/images/man2.png +0 -0
  48. data/images/man3.png +0 -0
  49. data/images/man4.png +0 -0
  50. data/images/man5.png +0 -0
  51. data/images/man6.png +0 -0
  52. data/profile/_base.rb +0 -23
  53. data/profile/df_to_a.rb +0 -10
  54. data/profile/filter.rb +0 -13
  55. data/profile/joining.rb +0 -13
  56. data/profile/sorting.rb +0 -12
  57. data/profile/vector_each_with_index.rb +0 -9
  58. data/profile/vector_new.rb +0 -9
  59. data/spec/accessors/array_wrapper_spec.rb +0 -3
  60. data/spec/category_spec.rb +0 -1767
  61. data/spec/core/group_by_spec.rb +0 -655
  62. data/spec/core/merge_spec.rb +0 -179
  63. data/spec/core/query_spec.rb +0 -347
  64. data/spec/daru_lite_spec.rb +0 -22
  65. data/spec/data_frame/aggregatable_example.rb +0 -65
  66. data/spec/data_frame/buildable_example.rb +0 -109
  67. data/spec/data_frame/calculatable_example.rb +0 -135
  68. data/spec/data_frame/convertible_example.rb +0 -180
  69. data/spec/data_frame/duplicatable_example.rb +0 -134
  70. data/spec/data_frame/fetchable_example.rb +0 -510
  71. data/spec/data_frame/filterable_example.rb +0 -456
  72. data/spec/data_frame/indexable_example.rb +0 -221
  73. data/spec/data_frame/iterable_example.rb +0 -481
  74. data/spec/data_frame/joinable_example.rb +0 -131
  75. data/spec/data_frame/missable_example.rb +0 -47
  76. data/spec/data_frame/pivotable_example.rb +0 -297
  77. data/spec/data_frame/queryable_example.rb +0 -92
  78. data/spec/data_frame/setable_example.rb +0 -513
  79. data/spec/data_frame/sortable_example.rb +0 -368
  80. data/spec/dataframe_spec.rb +0 -1342
  81. data/spec/date_time/data_spec.rb +0 -197
  82. data/spec/date_time/date_time_index_helper_spec.rb +0 -72
  83. data/spec/date_time/index_spec.rb +0 -588
  84. data/spec/date_time/offsets_spec.rb +0 -465
  85. data/spec/extensions/which_dsl_spec.rb +0 -38
  86. data/spec/fixtures/bank2.dat +0 -200
  87. data/spec/fixtures/boolean_converter_test.csv +0 -5
  88. data/spec/fixtures/countries.json +0 -7794
  89. data/spec/fixtures/duplicates.csv +0 -32
  90. data/spec/fixtures/eciresults.html +0 -394
  91. data/spec/fixtures/empties.dat +0 -2
  92. data/spec/fixtures/empty_rows_test.csv +0 -17
  93. data/spec/fixtures/macau.html +0 -3691
  94. data/spec/fixtures/macd_data.csv +0 -150
  95. data/spec/fixtures/matrix_test.csv +0 -100
  96. data/spec/fixtures/moneycontrol.html +0 -6812
  97. data/spec/fixtures/music_data.tsv +0 -2501
  98. data/spec/fixtures/repeated_fields.csv +0 -7
  99. data/spec/fixtures/sales-funnel.csv +0 -18
  100. data/spec/fixtures/scientific_notation.csv +0 -4
  101. data/spec/fixtures/string_converter_test.csv +0 -5
  102. data/spec/fixtures/strings.dat +0 -2
  103. data/spec/fixtures/test_xls.xls +0 -0
  104. data/spec/fixtures/test_xls_2.xls +0 -0
  105. data/spec/fixtures/url_test.txt~ +0 -0
  106. data/spec/fixtures/valid_markup.html +0 -62
  107. data/spec/fixtures/wiki_climate.html +0 -1243
  108. data/spec/fixtures/wiki_table_info.html +0 -631
  109. data/spec/formatters/table_formatter_spec.rb +0 -137
  110. data/spec/helpers_spec.rb +0 -8
  111. data/spec/index/categorical_index_spec.rb +0 -289
  112. data/spec/index/index_spec.rb +0 -438
  113. data/spec/index/multi_index_spec.rb +0 -752
  114. data/spec/io/io_spec.rb +0 -357
  115. data/spec/io/sql_data_source_spec.rb +0 -48
  116. data/spec/iruby/dataframe_spec.rb +0 -170
  117. data/spec/iruby/helpers_spec.rb +0 -49
  118. data/spec/iruby/multi_index_spec.rb +0 -37
  119. data/spec/iruby/vector_spec.rb +0 -105
  120. data/spec/maths/arithmetic/dataframe_spec.rb +0 -148
  121. data/spec/maths/arithmetic/vector_spec.rb +0 -165
  122. data/spec/maths/statistics/dataframe_spec.rb +0 -191
  123. data/spec/maths/statistics/vector_spec.rb +0 -756
  124. data/spec/monkeys_spec.rb +0 -42
  125. data/spec/shared/vector_display_spec.rb +0 -213
  126. data/spec/spec_helper.rb +0 -87
  127. data/spec/support/database_helper.rb +0 -29
  128. data/spec/support/matchers.rb +0 -5
  129. data/spec/vector/aggregatable_example.rb +0 -27
  130. data/spec/vector/calculatable_example.rb +0 -82
  131. data/spec/vector/convertible_example.rb +0 -126
  132. data/spec/vector/duplicatable_example.rb +0 -48
  133. data/spec/vector/fetchable_example.rb +0 -463
  134. data/spec/vector/filterable_example.rb +0 -165
  135. data/spec/vector/indexable_example.rb +0 -201
  136. data/spec/vector/iterable_example.rb +0 -111
  137. data/spec/vector/joinable_example.rb +0 -25
  138. data/spec/vector/missable_example.rb +0 -88
  139. data/spec/vector/queryable_example.rb +0 -91
  140. data/spec/vector/setable_example.rb +0 -300
  141. data/spec/vector/sortable_example.rb +0 -242
  142. data/spec/vector_spec.rb +0 -599
data/spec/monkeys_spec.rb DELETED
@@ -1,42 +0,0 @@
1
- describe "Monkeys" do
2
- context Matrix do
3
- it "performs elementwise division" do
4
- left = Matrix[[3,6,9],[4,8,12],[2,4,6]]
5
- right = Matrix[[3,6,9],[4,8,12],[2,4,6]]
6
-
7
- expect(left.elementwise_division(right)).to eq(Matrix[[1,1,1],[1,1,1],[1,1,1]])
8
- end
9
- end
10
-
11
- describe '#daru_lite_vector' do
12
- it 'converts Array' do
13
- expect([1,2,3].daru_lite_vector).to eq DaruLite::Vector.new [1,2,3]
14
- expect([1,2,3].daru_lite_vector('test', [:a, :b, :c])).to eq \
15
- DaruLite::Vector.new [1,2,3], name: 'test', index: [:a, :b, :c]
16
- end
17
-
18
- it 'converts Range' do
19
- expect((1..3).daru_lite_vector).to eq DaruLite::Vector.new [1,2,3]
20
- expect((1..3).daru_lite_vector('test', [:a, :b, :c])).to eq \
21
- DaruLite::Vector.new [1,2,3], name: 'test', index: [:a, :b, :c]
22
- end
23
-
24
- it 'converts Hash' do
25
- # FIXME: is it most useful way of converting hashes?..
26
- # I'd prefer something like
27
- # expect({a: 1, b: 2, c: 3}.daru_lite_vector('test')).to eq DaruLite::Vector.new [1,2,3], name: 'test', index: [:a, :b, :c]
28
- #
29
- expect({test: [1, 2, 3]}.daru_lite_vector).to eq DaruLite::Vector.new [1,2,3], name: :test
30
- end
31
- end
32
-
33
- describe '#to_index' do
34
- it 'converts Array' do
35
- expect([1,2,3].to_index).to eq DaruLite::Index.new [1,2,3]
36
- end
37
-
38
- it 'converts Range' do
39
- expect((1..3).to_index).to eq DaruLite::Index.new [1,2,3]
40
- end
41
- end
42
- end
@@ -1,213 +0,0 @@
1
- describe DaruLite::Vector do
2
- # TODO: Add inspect specs for category
3
- context '#inspect' do
4
- context 'simple' do
5
- subject(:vector) { DaruLite::Vector.new [1,2,3],
6
- index: [:a, :b, :c], name: 'test'}
7
- its(:inspect) { is_expected.to eq %Q{
8
- |#<DaruLite::Vector(3)>
9
- | test
10
- | a 1
11
- | b 2
12
- | c 3
13
- }.unindent }
14
- end
15
-
16
- context 'no name' do
17
- subject(:vector) { DaruLite::Vector.new [1,2,3], index: [:a, :b, :c]}
18
- its(:inspect) { is_expected.to eq %Q{
19
- |#<DaruLite::Vector(3)>
20
- | a 1
21
- | b 2
22
- | c 3
23
- }.unindent }
24
- end
25
-
26
- context 'with nils' do
27
- subject(:vector) { DaruLite::Vector.new [1,nil,3],
28
- index: [:a, :b, :c], name: 'test'}
29
- its(:inspect) { is_expected.to eq %Q{
30
- |#<DaruLite::Vector(3)>
31
- | test
32
- | a 1
33
- | b nil
34
- | c 3
35
- }.unindent }
36
- end
37
-
38
- context 'very large amount of data' do
39
- subject(:vector) { DaruLite::Vector.new [1,2,3] * 100, name: 'test'}
40
- its(:inspect) { is_expected.to eq %Q{
41
- |#<DaruLite::Vector(300)>
42
- | test
43
- | 0 1
44
- | 1 2
45
- | 2 3
46
- | 3 1
47
- | 4 2
48
- | 5 3
49
- | 6 1
50
- | 7 2
51
- | 8 3
52
- | 9 1
53
- | 10 2
54
- | 11 3
55
- | 12 1
56
- | 13 2
57
- | 14 3
58
- | ... ...
59
- }.unindent }
60
- end
61
-
62
- context 'really long name or data' do
63
- subject(:vector) { DaruLite::Vector.new [1,2,'this is ridiculously long'],
64
- index: [:a, :b, :c], name: 'and this is not much better faithfully'}
65
- its(:inspect) { is_expected.to eq %Q{
66
- |#<DaruLite::Vector(3)>
67
- | and this is not much
68
- | a 1
69
- | b 2
70
- | c this is ridiculously
71
- }.unindent }
72
- end
73
-
74
- context 'with multiindex' do
75
- subject(:vector) {
76
- DaruLite::Vector.new(
77
- [1,2,3,4,5,6,7],
78
- name: 'test',
79
- index: DaruLite::MultiIndex.from_tuples([
80
- %w[foo one],
81
- %w[foo two],
82
- %w[foo three],
83
- %w[bar one],
84
- %w[bar two],
85
- %w[bar three],
86
- %w[baz one],
87
- ]),
88
- )
89
- }
90
-
91
- its(:inspect) { is_expected.to eq %Q{
92
- |#<DaruLite::Vector(7)>
93
- | test
94
- | foo one 1
95
- | two 2
96
- | three 3
97
- | bar one 4
98
- | two 5
99
- | three 6
100
- | baz one 7
101
- }.unindent}
102
- end
103
-
104
- context 'threshold and spacing settings' do
105
- end
106
- end
107
-
108
- [nil, :category].each do |type|
109
- context '#to_html' do
110
- let(:doc) { Nokogiri::HTML(vector.to_html) }
111
- subject(:table) { doc.at('table') }
112
- let(:header) { doc.at('b') }
113
-
114
- context 'simple' do
115
- let(:vector) { DaruLite::Vector.new [1,nil,3],
116
- index: [:a, :b, :c], name: 'test', type: type }
117
- it { is_expected.not_to be_nil }
118
-
119
- describe 'header' do
120
- subject { header }
121
- it { is_expected.not_to be_nil }
122
- its(:text) { is_expected.to eq " DaruLite::Vector(3)"\
123
- "#{":category" if type == :category} " }
124
- end
125
-
126
- describe 'name' do
127
- subject(:name) { table.at('thead > tr:first-child > th:nth-child(2)') }
128
- it { is_expected.not_to be_nil }
129
- its(:text) { is_expected.to eq 'test' }
130
-
131
- context 'withought name' do
132
- let(:vector) { DaruLite::Vector.new [1,nil,3], index: [:a, :b, :c], type: type }
133
-
134
- it { is_expected.to be_nil }
135
- end
136
- end
137
-
138
- describe 'index' do
139
- subject(:indexes) { table.search('tr > td:first-child').map(&:text) }
140
- its(:count) { is_expected.to eq vector.size }
141
- it { is_expected.to eq vector.index.to_a.map(&:to_s) }
142
- end
143
-
144
- describe 'values' do
145
- subject(:indexes) { table.search('tr > td:last-child').map(&:text) }
146
- its(:count) { is_expected.to eq vector.size }
147
- it { is_expected.to eq vector.to_a.map(&:to_s) }
148
- end
149
- end
150
-
151
- context 'large vector' do
152
- subject(:vector) { DaruLite::Vector.new [1,2,3] * 100, name: 'test', type: type }
153
- it 'has only 30 rows (+ 1 header rows, + 2 finishing rows)' do
154
- expect(table.search('tr').size).to eq 33
155
- end
156
-
157
- describe '"skipped" row' do
158
- subject(:row) { table.search('tr:nth-child(31) td').map(&:text) }
159
- its(:count) { is_expected.to eq 2 }
160
- it { is_expected.to eq ['...', '...'] }
161
- end
162
-
163
- describe 'last row' do
164
- subject(:row) { table.search('tr:nth-child(32) td').map(&:text) }
165
- its(:count) { is_expected.to eq 2 }
166
- it { is_expected.to eq ['299', '3'] }
167
- end
168
- end
169
-
170
- context 'multi-index' do
171
- subject(:vector) {
172
- DaruLite::Vector.new(
173
- [1,2,3,4,5,6,7],
174
- name: 'test',
175
- type: type,
176
- index: DaruLite::MultiIndex.from_tuples([
177
- %w[foo one],
178
- %w[foo two],
179
- %w[foo three],
180
- %w[bar one],
181
- %w[bar two],
182
- %w[bar three],
183
- %w[baz one],
184
- ]),
185
- )
186
- }
187
-
188
- describe 'header' do
189
- subject { header }
190
- it { is_expected.not_to be_nil }
191
- its(:text) { is_expected.to eq " DaruLite::Vector(7)"\
192
- "#{":category" if type == :category} " }
193
- end
194
-
195
- describe 'name row' do
196
- subject(:row) { table.at('thead > tr:nth-child(1)').search('th') }
197
- its(:count) { should == 2 }
198
- it { expect(row.first['colspan']).to eq '2' }
199
- end
200
-
201
- describe 'first data row' do
202
- let(:row) { table.at('tbody > tr:first-child') }
203
- subject { row.inner_html.scan(/<t[dh].+?<\/t[dh]>/) }
204
- it { is_expected.to eq [
205
- '<th rowspan="3">foo</th>',
206
- '<th rowspan="1">one</th>',
207
- '<td>1</td>'
208
- ]}
209
- end
210
- end
211
- end
212
- end
213
- end
data/spec/spec_helper.rb DELETED
@@ -1,87 +0,0 @@
1
- require 'rspec'
2
- require 'rspec/its'
3
- require 'rspec/expectations'
4
- require 'matrix'
5
- require 'awesome_print'
6
- require 'debug'
7
- require 'distribution'
8
- require 'tempfile'
9
- require 'nokogiri'
10
- require 'webmock/rspec'
11
-
12
- def mri?
13
- RUBY_ENGINE == 'ruby'
14
- end
15
-
16
- def jruby?
17
- RUBY_ENGINE == 'jruby'
18
- end
19
-
20
- RSpec::Expectations.configuration.warn_about_potential_false_positives = false
21
-
22
- require 'simplecov'
23
- SimpleCov.start do
24
- add_filter 'vendor'
25
- add_filter 'spec'
26
- # minimum_coverage_by_file 95 -- too strict for now. Reconsider after specs redesign.
27
- end
28
-
29
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
30
- $LOAD_PATH.unshift(File.dirname(__FILE__))
31
- require 'daru_lite'
32
-
33
- if jruby?
34
- require 'mdarray'
35
- end
36
-
37
- ALL_DTYPES = [:array]
38
-
39
- # FIXME: This must go! Need to be able to use be_within
40
- def expect_correct_vector_in_delta v1, v2, delta
41
- expect(v1.size).to eq(v2.size)
42
- (0...v1.size).each do |v|
43
- expect(v1[v]).to be_within(delta).of(v2[v])
44
- end
45
- end
46
-
47
- def expect_correct_df_in_delta df1, df2, delta
48
- df1.each_vector_with_index do |vector, i|
49
- expect_correct_vector_in_delta vector, df2[i], delta
50
- end
51
- end
52
-
53
- RSpec::Matchers.define :be_all_within do |delta|
54
- match do |actual|
55
- expect(@expected).to_not be_nil
56
- expect(actual.size).to equal(actual.size)
57
- (@act, @exp), @idx = actual.zip(@expected).each_with_index.detect { |(a, e), _| (a - e).abs > delta }
58
- @idx.nil?
59
- end
60
-
61
- chain :of do |expected|
62
- @expected = expected
63
- end
64
-
65
- failure_message do |actual|
66
- return "expected value must be provided using '.of'." if @expected.nil?
67
- return "expected.size must equal actual.size." if @expected.size != actual.size
68
- "at index=[#{@idx}], expected '#{actual[@idx]}' to be within '#{delta}' of '#{@expected[@idx]}'."
69
- end
70
- end
71
-
72
- class String
73
- # allows to pretty test agains multiline strings:
74
- # %Q{
75
- # |test
76
- # |me
77
- # }.unindent # =>
78
- # "test
79
- # me"
80
- def unindent
81
- gsub(/\n\s+?\|/, "\n") # for all lines looking like "<spaces>|" -- remove this.
82
- .gsub(/\|\n/, "\n") # allow to write trailing space not removed by editor
83
- .gsub(/^\n|\n\s+$/, '') # remove empty strings before and after
84
- end
85
- end
86
-
87
- Dir[File.expand_path('../support/**/*.rb', __FILE__)].each {|f| require f }
@@ -1,29 +0,0 @@
1
- require 'sqlite3'
2
- require 'active_record'
3
-
4
- module DaruLite::RSpec
5
- class Account < ActiveRecord::Base
6
- self.table_name = 'accounts'
7
- end
8
- end
9
-
10
- shared_context 'with accounts table in sqlite3 database' do
11
- let(:db_name) do
12
- 'daru_lite_test'
13
- end
14
-
15
- before do
16
- # just in case
17
- FileUtils.rm(db_name) if File.file?(db_name)
18
-
19
- SQLite3::Database.new(db_name).tap do |db|
20
- db.execute "create table accounts(id integer, name varchar, age integer, primary key(id))"
21
- db.execute "insert into accounts values(1, 'Homer', 20)"
22
- db.execute "insert into accounts values(2, 'Marge', 30)"
23
- end
24
- end
25
-
26
- after do
27
- FileUtils.rm(db_name)
28
- end
29
- end
@@ -1,5 +0,0 @@
1
- RSpec::Matchers.define :be_boolean do
2
- match do |actual|
3
- expect(actual.is_a?(TrueClass) || actual.is_a?(FalseClass)).to be true
4
- end
5
- end
@@ -1,27 +0,0 @@
1
- shared_examples_for 'an aggregatable Vector' do
2
- context "#group_by" do
3
- let(:dv) { DaruLite::Vector.new [:a, :b, :a, :b, :c] }
4
-
5
- context 'vector not specified' do
6
- subject { dv.group_by }
7
-
8
- it { is_expected.to be_a DaruLite::Core::GroupBy }
9
- its(:'groups.size') { is_expected.to eq 3 }
10
- its(:groups) { is_expected.to eq({[:a]=>[0, 2], [:b]=>[1, 3], [:c]=>[4]}) }
11
- end
12
-
13
- context 'vector name specified' do
14
- before { dv.name = :hello }
15
- subject { dv.group_by :hello }
16
-
17
- it { is_expected.to be_a DaruLite::Core::GroupBy }
18
- its(:'groups.size') { is_expected.to eq 3 }
19
- its(:groups) { is_expected.to eq({[:a]=>[0, 2], [:b]=>[1, 3], [:c]=>[4]}) }
20
- end
21
-
22
- context 'vector name invalid' do
23
- before { dv.name = :hello }
24
- it { expect { dv.group_by :abc }.to raise_error }
25
- end
26
- end
27
- end
@@ -1,82 +0,0 @@
1
- shared_examples_for 'a calculatable Vector' do |dtype|
2
- describe '#count_values' do
3
- let(:vector) { DaruLite::Vector.new([1, 2, 3, 1, 2, nil, nil]) }
4
-
5
- it { expect(vector.count_values 1, 2).to eq 4 }
6
- it { expect(vector.count_values nil).to eq 2 }
7
- it { expect(vector.count_values 3, Float::NAN).to eq 1 }
8
- it { expect(vector.count_values 4).to eq 0 }
9
- end
10
-
11
- context "#summary" do
12
- subject { vector.summary }
13
-
14
- context 'all types' do
15
- let(:vector) { DaruLite::Vector.new([1 ,2, 3, 4, 5], name: 'vector') }
16
-
17
- it { is_expected.to include vector.name }
18
-
19
- it { is_expected.to include "n :#{vector.size}" }
20
-
21
- it { is_expected.to include "non-missing:#{vector.size - vector.count_values(*DaruLite::MISSING_VALUES)}" }
22
- end
23
-
24
-
25
- context "numeric type" do
26
- let(:vector) { DaruLite::Vector.new([1,2,5], name: 'numeric') }
27
-
28
- it { is_expected. to eq %Q{
29
- |= numeric
30
- | n :3
31
- | non-missing:3
32
- | median: 2
33
- | mean: 2.6667
34
- | std.dev.: 2.0817
35
- | std.err.: 1.2019
36
- | skew: 0.2874
37
- | kurtosis: -2.3333
38
- }.unindent }
39
- end
40
-
41
- context "numeric type with missing values" do
42
- let(:vector) { DaruLite::Vector.new([1,2,5,nil,Float::NAN], name: 'numeric') }
43
-
44
- it { is_expected.not_to include 'skew' }
45
- it { is_expected.not_to include 'kurtosis' }
46
- end
47
-
48
- if dtype == :array
49
- context "object type" do
50
- let(:vector) { DaruLite::Vector.new([1, 1, 2, 2, "string", nil, Float::NAN], name: 'object') }
51
-
52
- if RUBY_VERSION >= '2.2'
53
- it { is_expected.to eq %Q{
54
- |= object
55
- | n :7
56
- | non-missing:5
57
- | factors: 1,2,string
58
- | mode: 1,2
59
- | Distribution
60
- | string 1 50.00%
61
- | NaN 1 50.00%
62
- | 1 2 100.00%
63
- | 2 2 100.00%
64
- }.unindent }
65
- else
66
- it { is_expected.to eq %Q{
67
- |= object
68
- | n :7
69
- | non-missing:5
70
- | factors: 1,2,string
71
- | mode: 1,2
72
- | Distribution
73
- | NaN 1 50.00%
74
- | string 1 50.00%
75
- | 2 2 100.00%
76
- | 1 2 100.00%
77
- }.unindent }
78
- end
79
- end
80
- end
81
- end
82
- end
@@ -1,126 +0,0 @@
1
- shared_examples_for 'a convertible Vector' do |dtype|
2
- describe "#to_df" do
3
- subject { vector.to_df }
4
-
5
- let(:vector) do
6
- DaruLite::Vector.new(['a','b','c'], name: :my_dv, index: ['alpha', 'beta', 'gamma'])
7
- end
8
-
9
- it 'is a dataframe' do
10
- expect(subject).to be_a DaruLite::DataFrame
11
- end
12
-
13
- it 'converts the vector to a single-vector dataframe' do
14
- expect(subject[:my_dv]).to eq vector
15
- end
16
-
17
- it 'has the same index as the original vector' do
18
- expect(subject.index).to eq vector.index
19
- end
20
-
21
- it 'has the same name as the vector' do
22
- expect(subject.name).to eq :my_dv
23
- end
24
- end
25
-
26
- describe "#to_h" do
27
- context DaruLite::Index do
28
- subject { vector.to_h }
29
-
30
- let(:vector) do
31
- DaruLite::Vector.new(
32
- [1,2,3,4,5],
33
- name: :a,
34
- index: [:one, :two, :three, :four, :five],
35
- dtype:
36
- )
37
- end
38
-
39
- it "returns the vector as a hash" do
40
- expect(subject).to eq({one: 1, two: 2, three: 3, four: 4, five: 5})
41
- end
42
- end
43
-
44
- context DaruLite::MultiIndex do
45
- pending
46
- # it "returns vector as a Hash" do
47
- # pending
48
- # mi = DaruLite::MultiIndex.from_tuples([
49
- # [:a,:two,:bar],
50
- # [:a,:two,:baz],
51
- # [:b,:one,:bar],
52
- # [:b,:two,:bar]
53
- # ])
54
- # vector = DaruLite::Vector.new([1,2,3,4], index: mi, dtype: dtype)
55
- # expect(vector.to_h).to eq({
56
- # [:a,:two,:bar] => 1,
57
- # [:a,:two,:baz] => 2,
58
- # [:b,:one,:bar] => 3,
59
- # [:b,:two,:bar] => 4
60
- # })
61
- # end
62
- end
63
- end
64
-
65
- describe "#to_json" do
66
- subject { vector.to_json }
67
-
68
- let(:vector) do
69
- DaruLite::Vector.new(
70
- [1,2,3,4,5],
71
- name: :a,
72
- index: [:one, :two, :three, :four, :five],
73
- dtype: dtype
74
- )
75
- end
76
-
77
- it "returns the vector as json" do
78
- expect(subject).to eq(vector.to_h.to_json)
79
- end
80
-
81
- end
82
-
83
- describe "#to_s" do
84
- let(:vector) { DaruLite::Vector.new(["a", "b"], index: [1, 2], name:) }
85
-
86
- context 'name is nil' do
87
- let(:name) { nil }
88
-
89
- it 'produces a class, size description' do
90
- expect(vector.to_s).to eq("#<DaruLite::Vector(2)>")
91
- end
92
- end
93
-
94
- context 'name is present' do
95
- let(:name) { "Test" }
96
-
97
- it 'produces a class, name, size description' do
98
- expect(vector.to_s).to eq("#<DaruLite::Vector: Test(2)>")
99
- end
100
- end
101
-
102
- context 'name is a symbol' do
103
- let(:name) { :Test }
104
-
105
- it 'produces a class, name, size description' do
106
- expect(vector.to_s).to eq("#<DaruLite::Vector: Test(2)>")
107
- end
108
- end
109
- end
110
-
111
- describe "#to_matrix" do
112
- let(:vector) { DaruLite::Vector.new [1, 2, 3, 4, 5, 6] }
113
-
114
- it "converts DaruLite::Vector to a horizontal Ruby Matrix" do
115
- expect(vector.to_matrix).to eq(Matrix[[1, 2, 3, 4, 5, 6]])
116
- end
117
-
118
- it "converts DaruLite::Vector to a vertical Ruby Matrix" do
119
- expect(vector.to_matrix(:vertical)).to eq(Matrix.columns([[1, 2, 3, 4, 5, 6]]))
120
- end
121
-
122
- it 'raises on wrong axis' do
123
- expect { vector.to_matrix(:strange) }.to raise_error(ArgumentError)
124
- end
125
- end
126
- end
@@ -1,48 +0,0 @@
1
- shared_examples_for 'a duplicatable Vector' do
2
- describe "#dup" do
3
- subject { vector.dup }
4
-
5
- let(:vector) do
6
- DaruLite::Vector.new([1, 2], name: :yoda, index: [:happy, :lightsaber])
7
- end
8
-
9
- it "copies the original data" do
10
- expect(subject.send(:data)).to eq([1,2])
11
- end
12
-
13
- it "creates a new data object" do
14
- expect(subject.send(:data).object_id).not_to eq(vector.send(:data).object_id)
15
- end
16
-
17
- it "copies the name" do
18
- expect(subject.name).to eq(:yoda)
19
- end
20
-
21
- it "copies the original index" do
22
- expect(subject.index).to eq(DaruLite::Index.new([:happy, :lightsaber]))
23
- end
24
-
25
- it "creates a new index object" do
26
- expect(subject.index.object_id).not_to eq(vector.index.object_id)
27
- end
28
- end
29
-
30
- describe "#clone_structure" do
31
- subject { vector.clone_structure }
32
- context DaruLite::Index do
33
- let(:vector) do
34
- DaruLite::Vector.new([1, 2, 3, 4, 5], index: [:a,:b,:c,:d,:e])
35
- end
36
-
37
- it "clones a vector with its index and fills it with nils" do
38
- expect(subject).to eq(
39
- DaruLite::Vector.new([nil, nil, nil, nil, nil], index: [:a,:b,:c,:d,:e])
40
- )
41
- end
42
- end
43
-
44
- context DaruLite::MultiIndex do
45
- pending
46
- end
47
- end
48
- end