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,109 +0,0 @@
|
|
|
1
|
-
shared_examples_for 'a buildable DataFrame' do
|
|
2
|
-
describe "::rows" do
|
|
3
|
-
let(:rows) do
|
|
4
|
-
[
|
|
5
|
-
[1,2,3,4,5],
|
|
6
|
-
[1,2,3,4,5],
|
|
7
|
-
[1,2,3,4,5],
|
|
8
|
-
[1,2,3,4,5]
|
|
9
|
-
]
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
context DaruLite::Index do
|
|
13
|
-
it "creates a DataFrame from Array rows" do
|
|
14
|
-
df = DaruLite::DataFrame.rows(rows, order: [:a,:b,:c,:d,:e])
|
|
15
|
-
|
|
16
|
-
expect(df.index).to eq(DaruLite::Index.new [0,1,2,3])
|
|
17
|
-
expect(df.vectors).to eq(DaruLite::Index.new [:a,:b,:c,:d,:e])
|
|
18
|
-
expect(df[:a]).to eq(DaruLite::Vector.new [1,1,1,1])
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "creates empty dataframe" do
|
|
22
|
-
df = DaruLite::DataFrame.rows([], order: [:a, :b, :c])
|
|
23
|
-
|
|
24
|
-
expect(df.vectors).to eq(DaruLite::Index.new [:a,:b,:c])
|
|
25
|
-
expect(df.index).to be_empty
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "creates a DataFrame from Vector rows" do
|
|
29
|
-
vector_rows = rows.map { |r| DaruLite::Vector.new r, index: [:a,:b,:c,:d,:e] }
|
|
30
|
-
|
|
31
|
-
df = DaruLite::DataFrame.rows(vector_rows, order: [:a,:b,:c,:d,:e])
|
|
32
|
-
|
|
33
|
-
expect(df.index) .to eq(DaruLite::Index.new [0,1,2,3])
|
|
34
|
-
expect(df.vectors) .to eq(DaruLite::Index.new [:a,:b,:c,:d,:e])
|
|
35
|
-
expect(df[:a]) .to eq(DaruLite::Vector.new [1,1,1,1])
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it 'derives index & order from arrays' do
|
|
39
|
-
df = DaruLite::DataFrame.rows(rows)
|
|
40
|
-
expect(df.index) .to eq(DaruLite::Index.new [0,1,2,3])
|
|
41
|
-
expect(df.vectors) .to eq(DaruLite::Index.new %w[0 1 2 3 4])
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it 'derives index & order from vectors' do
|
|
45
|
-
vector_rows = rows.zip(%w[w x y z]).map { |r, n| DaruLite::Vector.new r, index: [:a,:b,:c,:d,:e], name: n }
|
|
46
|
-
df = DaruLite::DataFrame.rows(vector_rows)
|
|
47
|
-
expect(df.index) .to eq(DaruLite::Index.new %w[w x y z])
|
|
48
|
-
expect(df.vectors) .to eq(DaruLite::Index.new [:a,:b,:c,:d,:e])
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it 'behaves, when rows are repeated' do
|
|
52
|
-
vector_rows = rows.zip(%w[w w y z]).map { |r, n| DaruLite::Vector.new r, index: [:a,:b,:c,:d,:e], name: n }
|
|
53
|
-
df = DaruLite::DataFrame.rows(vector_rows)
|
|
54
|
-
expect(df.index) .to eq(DaruLite::Index.new %w[w_1 w_2 y z])
|
|
55
|
-
expect(df.vectors) .to eq(DaruLite::Index.new [:a,:b,:c,:d,:e])
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it 'behaves, when vectors are unnamed' do
|
|
59
|
-
vector_rows = rows.map { |r| DaruLite::Vector.new r, index: [:a,:b,:c,:d,:e] }
|
|
60
|
-
df = DaruLite::DataFrame.rows(vector_rows)
|
|
61
|
-
expect(df.index) .to eq(DaruLite::Index.new [0,1,2,3])
|
|
62
|
-
expect(df.vectors) .to eq(DaruLite::Index.new [:a,:b,:c,:d,:e])
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
context DaruLite::MultiIndex do
|
|
67
|
-
it "creates a DataFrame from rows" do
|
|
68
|
-
df = DaruLite::DataFrame.rows(
|
|
69
|
-
rows*3, index: multi_index, order: [:a,:b,:c,:d,:e])
|
|
70
|
-
|
|
71
|
-
expect(df.index).to eq(multi_index)
|
|
72
|
-
expect(df.vectors).to eq(DaruLite::Index.new([:a,:b,:c,:d,:e]))
|
|
73
|
-
expect(df[:a]).to eq(DaruLite::Vector.new([1]*12, index: multi_index))
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it "crates a DataFrame from rows (MultiIndex order)" do
|
|
77
|
-
rows = [
|
|
78
|
-
[11, 1, 11, 1],
|
|
79
|
-
[12, 2, 12, 2],
|
|
80
|
-
[13, 3, 13, 3],
|
|
81
|
-
[14, 4, 14, 4]
|
|
82
|
-
]
|
|
83
|
-
index = DaruLite::MultiIndex.from_tuples([
|
|
84
|
-
[:one,:bar],
|
|
85
|
-
[:one,:baz],
|
|
86
|
-
[:two,:foo],
|
|
87
|
-
[:two,:bar]
|
|
88
|
-
])
|
|
89
|
-
|
|
90
|
-
df = DaruLite::DataFrame.rows(rows, index: index, order: order_mi)
|
|
91
|
-
expect(df.index).to eq(index)
|
|
92
|
-
expect(df.vectors).to eq(order_mi)
|
|
93
|
-
expect(df[:a, :one, :bar]).to eq(DaruLite::Vector.new([11,12,13,14],
|
|
94
|
-
index: index))
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
it "creates a DataFrame from Vector rows" do
|
|
98
|
-
rows3 = rows*3
|
|
99
|
-
rows3.map! { |r| DaruLite::Vector.new(r, index: multi_index) }
|
|
100
|
-
|
|
101
|
-
df = DaruLite::DataFrame.rows(rows3, order: multi_index)
|
|
102
|
-
|
|
103
|
-
expect(df.index).to eq(DaruLite::Index.new(Array.new(rows3.size) { |i| i }))
|
|
104
|
-
expect(df.vectors).to eq(multi_index)
|
|
105
|
-
expect(df[:a,:one,:bar]).to eq(DaruLite::Vector.new([1]*12))
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
end
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
shared_examples_for 'a calculatable DataFrame' do
|
|
2
|
-
context "#vector_sum" do
|
|
3
|
-
let(:df) do
|
|
4
|
-
a1 = DaruLite::Vector.new [1, 2, 3, 4, 5, nil, nil]
|
|
5
|
-
a2 = DaruLite::Vector.new [10, 10, 20, 20, 20, 30, nil]
|
|
6
|
-
b1 = DaruLite::Vector.new [nil, 1, 1, 1, 1, 2, nil]
|
|
7
|
-
b2 = DaruLite::Vector.new [2, 2, 2, nil, 2, 3, nil]
|
|
8
|
-
DaruLite::DataFrame.new({ a1:, a2:, b1:, b2: })
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "calculates complete vector sum" do
|
|
12
|
-
expect(df.vector_sum).to eq(DaruLite::Vector.new [nil, 15, 26, nil, 28, nil, nil])
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it "ignores nils if skipnil is true" do
|
|
16
|
-
expect(df.vector_sum skipnil: true).to eq(DaruLite::Vector.new [13, 15, 26, 25, 28, 35, 0])
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "calculates partial vector sum" do
|
|
20
|
-
a = df.vector_sum([:a1, :a2])
|
|
21
|
-
b = df.vector_sum([:b1, :b2])
|
|
22
|
-
|
|
23
|
-
expect(a).to eq(DaruLite::Vector.new [11, 12, 23, 24, 25, nil, nil])
|
|
24
|
-
expect(b).to eq(DaruLite::Vector.new [nil, 3, 3, nil, 3, 5, nil])
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
describe "#vector_mean" do
|
|
29
|
-
let(:df) do
|
|
30
|
-
a1 = DaruLite::Vector.new [1, 2, 3, 4, 5, nil]
|
|
31
|
-
a2 = DaruLite::Vector.new [10, 10, 20, 20, 20, 30]
|
|
32
|
-
b1 = DaruLite::Vector.new [nil, 1, 1, 1, 1, 2]
|
|
33
|
-
b2 = DaruLite::Vector.new [2, 2, 2, nil, 2, 3]
|
|
34
|
-
c = DaruLite::Vector.new [nil, 2, 4, 2, 2, 2]
|
|
35
|
-
DaruLite::DataFrame.new({ a1:, a2:, b1:, b2:, c: })
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "calculates complete vector mean" do
|
|
39
|
-
expect(df.vector_mean).to eq(
|
|
40
|
-
DaruLite::Vector.new [nil, 3.4, 6, nil, 6.0, nil]
|
|
41
|
-
)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
describe "#compute" do
|
|
46
|
-
let(:vnumeric) { DaruLite::Vector.new [0, 0, 1, 4] }
|
|
47
|
-
let(:vsum) { DaruLite::Vector.new [1 + 4 + 10.0, 2 + 3 + 20.0, 3 + 2 + 30.0, 4 + 1 + 40.0] }
|
|
48
|
-
let(:vmult) { DaruLite::Vector.new [1 * 4, 2 * 3, 3 * 2, 4 * 1] }
|
|
49
|
-
let(:df) do
|
|
50
|
-
v1 = DaruLite::Vector.new [1, 2, 3, 4]
|
|
51
|
-
v2 = DaruLite::Vector.new [4, 3, 2, 1]
|
|
52
|
-
v3 = DaruLite::Vector.new [10, 20, 30, 40]
|
|
53
|
-
|
|
54
|
-
DaruLite::DataFrame.new({ v1:, v2:, v3: })
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
it "performs a computation when supplied in a string" do
|
|
58
|
-
expect(df.compute("v1/v2")).to eq(vnumeric)
|
|
59
|
-
expect(df.compute("v1+v2+v3")).to eq(vsum)
|
|
60
|
-
expect(df.compute("v1*v2")).to eq(vmult)
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
describe "#vector_by_calculation" do
|
|
65
|
-
subject { df.vector_by_calculation { a + b + c } }
|
|
66
|
-
|
|
67
|
-
let(:df) do
|
|
68
|
-
a1 = DaruLite::Vector.new([1, 2, 3, 4, 5, 6, 7])
|
|
69
|
-
a2 = DaruLite::Vector.new([10, 20, 30, 40, 50, 60, 70])
|
|
70
|
-
a3 = DaruLite::Vector.new([100, 200, 300, 400, 500, 600, 700])
|
|
71
|
-
DaruLite::DataFrame.new({ :a => a1, :b => a2, :c => a3 })
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it "DSL for returning vector of each calculation" do
|
|
75
|
-
expect(subject).to eq(DaruLite::Vector.new([111, 222, 333, 444, 555, 666, 777]))
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
describe "#vector_count_characters" do
|
|
80
|
-
subject { df.vector_count_characters }
|
|
81
|
-
let(:df) do
|
|
82
|
-
a1 = DaruLite::Vector.new( [1, 'abcde', 3, 4, 5, nil])
|
|
83
|
-
a2 = DaruLite::Vector.new( [10, 20.3, 20, 20, 20, 30])
|
|
84
|
-
b1 = DaruLite::Vector.new( [nil, '343434', 1, 1, 1, 2])
|
|
85
|
-
b2 = DaruLite::Vector.new( [2, 2, 2, nil, 2, 3])
|
|
86
|
-
c = DaruLite::Vector.new([nil, 2, 'This is a nice example', 2, 2, 2])
|
|
87
|
-
|
|
88
|
-
DaruLite::DataFrame.new({ a1:, a2:, b1:, b2:, c: })
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
it "returns correct values" do
|
|
92
|
-
expect(subject).to eq(DaruLite::Vector.new([4, 17, 27, 5, 6, 5]))
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
describe "#summary" do
|
|
97
|
-
subject { df.summary }
|
|
98
|
-
|
|
99
|
-
context "DataFrame" do
|
|
100
|
-
let(:df) do
|
|
101
|
-
DaruLite::DataFrame.new(
|
|
102
|
-
{ a: [1,2,5], b: [1,2,"string"] },
|
|
103
|
-
order: [:a, :b],
|
|
104
|
-
index: [:one, :two, :three],
|
|
105
|
-
name: 'frame'
|
|
106
|
-
)
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
it { is_expected.to eq %Q{
|
|
110
|
-
|= frame
|
|
111
|
-
| Number of rows: 3
|
|
112
|
-
| Element:[a]
|
|
113
|
-
| == a
|
|
114
|
-
| n :3
|
|
115
|
-
| non-missing:3
|
|
116
|
-
| median: 2
|
|
117
|
-
| mean: 2.6667
|
|
118
|
-
| std.dev.: 2.0817
|
|
119
|
-
| std.err.: 1.2019
|
|
120
|
-
| skew: 0.2874
|
|
121
|
-
| kurtosis: -2.3333
|
|
122
|
-
| Element:[b]
|
|
123
|
-
| == b
|
|
124
|
-
| n :3
|
|
125
|
-
| non-missing:3
|
|
126
|
-
| factors: 1,2,string
|
|
127
|
-
| mode: 1,2,string
|
|
128
|
-
| Distribution
|
|
129
|
-
| 1 1 100.00%
|
|
130
|
-
| 2 1 100.00%
|
|
131
|
-
| string 1 100.00%
|
|
132
|
-
}.unindent }
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
end
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
shared_examples_for 'a convertible DataFrame' do
|
|
2
|
-
describe '#create_sql' do
|
|
3
|
-
subject { df.create_sql('foo') }
|
|
4
|
-
|
|
5
|
-
let(:df) do
|
|
6
|
-
DaruLite::DataFrame.new(
|
|
7
|
-
{
|
|
8
|
-
a: [1,2,3],
|
|
9
|
-
b: ['test', 'me', 'please'],
|
|
10
|
-
c: ['2015-06-01', '2015-06-02', '2015-06-03']
|
|
11
|
-
},
|
|
12
|
-
name: 'test'
|
|
13
|
-
)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it { is_expected.to eq %Q{
|
|
17
|
-
|CREATE TABLE foo (a INTEGER,
|
|
18
|
-
| b VARCHAR (255),
|
|
19
|
-
| c DATE) CHARACTER SET=UTF8;
|
|
20
|
-
}.unindent }
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
describe '#to_df' do
|
|
24
|
-
subject { df.to_df }
|
|
25
|
-
|
|
26
|
-
it { is_expected.to eq(df) }
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
describe "#to_matrix" do
|
|
30
|
-
subject { df.to_matrix }
|
|
31
|
-
|
|
32
|
-
let(:df) do
|
|
33
|
-
DaruLite::DataFrame.new(
|
|
34
|
-
{
|
|
35
|
-
b: [11,12,13,14,15],
|
|
36
|
-
a: [1,2,3,4,5],
|
|
37
|
-
c: [11,22,33,44,55],
|
|
38
|
-
d: [5,4,nil,2,1],
|
|
39
|
-
e: ['this', 'has', 'string','data','too']
|
|
40
|
-
},
|
|
41
|
-
order: [:a, :b, :c,:d,:e],
|
|
42
|
-
index: [:one, :two, :three, :four, :five]
|
|
43
|
-
)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "concats numeric non-nil vectors to Matrix" do
|
|
47
|
-
expect(subject).to eq(Matrix[
|
|
48
|
-
[1,11,11,5],
|
|
49
|
-
[2,12,22,4],
|
|
50
|
-
[3,13,33,nil],
|
|
51
|
-
[4,14,44,2],
|
|
52
|
-
[5,15,55,1]
|
|
53
|
-
])
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
describe "#to_a" do
|
|
58
|
-
subject { df.to_a }
|
|
59
|
-
|
|
60
|
-
context DaruLite::Index do
|
|
61
|
-
it "converts DataFrame into array of hashes" do
|
|
62
|
-
expect(subject).to eq(
|
|
63
|
-
[
|
|
64
|
-
[
|
|
65
|
-
{a: 1, b: 11, c: 11},
|
|
66
|
-
{a: 2, b: 12, c: 22},
|
|
67
|
-
{a: 3, b: 13, c: 33},
|
|
68
|
-
{a: 4, b: 14, c: 44},
|
|
69
|
-
{a: 5, b: 15, c: 55}
|
|
70
|
-
],
|
|
71
|
-
[
|
|
72
|
-
:one, :two, :three, :four, :five
|
|
73
|
-
]
|
|
74
|
-
])
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
context DaruLite::MultiIndex do
|
|
79
|
-
pending
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
describe '#to_json' do
|
|
84
|
-
subject { JSON.parse(json) }
|
|
85
|
-
|
|
86
|
-
let(:df) do
|
|
87
|
-
DaruLite::DataFrame.new(
|
|
88
|
-
{ a: [1,2,3], b: [3,4,5], c: [6,7,8]},
|
|
89
|
-
index: [:one, :two, :three],
|
|
90
|
-
name: 'test'
|
|
91
|
-
)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
context 'with index' do
|
|
95
|
-
let(:json) { df.to_json(false) }
|
|
96
|
-
# FIXME: is it most reasonable we can do?.. -- zverok
|
|
97
|
-
# For me, more resonable thing would be something like
|
|
98
|
-
#
|
|
99
|
-
# [
|
|
100
|
-
# {"index" => "one" , "a"=>1, "b"=>3, "c"=>6},
|
|
101
|
-
# {"index" => "two" , "a"=>2, "b"=>4, "c"=>7},
|
|
102
|
-
# {"index" => "three", "a"=>3, "b"=>5, "c"=>8}
|
|
103
|
-
# ]
|
|
104
|
-
#
|
|
105
|
-
# Or maybe
|
|
106
|
-
#
|
|
107
|
-
# [
|
|
108
|
-
# ["one" , {"a"=>1, "b"=>3, "c"=>6}],
|
|
109
|
-
# ["two" , {"a"=>2, "b"=>4, "c"=>7}],
|
|
110
|
-
# ["three", {"a"=>3, "b"=>5, "c"=>8}]
|
|
111
|
-
# ]
|
|
112
|
-
#
|
|
113
|
-
# Or even
|
|
114
|
-
#
|
|
115
|
-
# {
|
|
116
|
-
# "one" => {"a"=>1, "b"=>3, "c"=>6},
|
|
117
|
-
# "two" => {"a"=>2, "b"=>4, "c"=>7},
|
|
118
|
-
# "three" => {"a"=>3, "b"=>5, "c"=>8}
|
|
119
|
-
# }
|
|
120
|
-
#
|
|
121
|
-
it { is_expected.to eq(
|
|
122
|
-
[
|
|
123
|
-
[
|
|
124
|
-
{"a"=>1, "b"=>3, "c"=>6},
|
|
125
|
-
{"a"=>2, "b"=>4, "c"=>7},
|
|
126
|
-
{"a"=>3, "b"=>5, "c"=>8}
|
|
127
|
-
],
|
|
128
|
-
["one", "two", "three"]
|
|
129
|
-
]
|
|
130
|
-
)}
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
context 'without index' do
|
|
134
|
-
let(:json) { df.to_json(true) }
|
|
135
|
-
|
|
136
|
-
it { is_expected.to eq(
|
|
137
|
-
[
|
|
138
|
-
{"a"=>1, "b"=>3, "c"=>6},
|
|
139
|
-
{"a"=>2, "b"=>4, "c"=>7},
|
|
140
|
-
{"a"=>3, "b"=>5, "c"=>8}
|
|
141
|
-
]
|
|
142
|
-
)}
|
|
143
|
-
end
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
describe "#to_h" do
|
|
147
|
-
subject { df.to_h }
|
|
148
|
-
|
|
149
|
-
it "converts to a hash" do
|
|
150
|
-
expect(subject).to eq(
|
|
151
|
-
{
|
|
152
|
-
a: DaruLite::Vector.new([1,2,3,4,5],
|
|
153
|
-
index: [:one, :two, :three, :four, :five]),
|
|
154
|
-
b: DaruLite::Vector.new([11,12,13,14,15],
|
|
155
|
-
index: [:one, :two, :three, :four, :five]),
|
|
156
|
-
c: DaruLite::Vector.new([11,22,33,44,55],
|
|
157
|
-
index: [:one, :two, :three, :four, :five])
|
|
158
|
-
}
|
|
159
|
-
)
|
|
160
|
-
end
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
describe '#to_s' do
|
|
164
|
-
subject { df.to_s }
|
|
165
|
-
|
|
166
|
-
it 'produces a class, size description' do
|
|
167
|
-
expect(subject).to eq "#<DaruLite::DataFrame(5x3)>"
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
it 'produces a class, name, size description' do
|
|
171
|
-
df.name = "Test"
|
|
172
|
-
expect(subject).to eq "#<DaruLite::DataFrame: Test(5x3)>"
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
it 'produces a class, name, size description when the name is a symbol' do
|
|
176
|
-
df.name = :Test
|
|
177
|
-
expect(subject).to eq "#<DaruLite::DataFrame: Test(5x3)>"
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
end
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
shared_examples_for 'a duplicatable DataFrame' do
|
|
2
|
-
describe "#dup" do
|
|
3
|
-
context DaruLite::Index do
|
|
4
|
-
subject { df.dup }
|
|
5
|
-
|
|
6
|
-
it "dups every data structure inside DataFrame" do
|
|
7
|
-
expect(subject.object_id).not_to eq(df.object_id)
|
|
8
|
-
expect(subject.vectors.object_id).not_to eq(df.vectors.object_id)
|
|
9
|
-
expect(subject.index.object_id).not_to eq(df.index.object_id)
|
|
10
|
-
|
|
11
|
-
df.each_vector_with_index do |vector, index|
|
|
12
|
-
expect(vector.object_id).not_to eq(subject[index].object_id)
|
|
13
|
-
expect(vector.to_a.object_id).not_to eq(subject[index].to_a.object_id)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context DaruLite::MultiIndex do
|
|
19
|
-
subject { df_mi.dup }
|
|
20
|
-
|
|
21
|
-
it "duplicates with multi index" do
|
|
22
|
-
expect(subject).to eq(df_mi)
|
|
23
|
-
expect(subject.vectors.object_id).not_to eq(df_mi.vectors.object_id)
|
|
24
|
-
expect(subject.index.object_id).not_to eq(df_mi.index.object_id)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
context "with duplicate tuples" do
|
|
28
|
-
let(:dup_df) do
|
|
29
|
-
DaruLite::DataFrame.new(
|
|
30
|
-
[[1, 2], [3, 4], [5, 6], [7, 8]],
|
|
31
|
-
order: DaruLite::MultiIndex.from_tuples([
|
|
32
|
-
[:weighted_count, 'Wave'], [:weighted_count, 'Wave'],
|
|
33
|
-
[:percentage, 'Wave'], [:percentage, 'Wave']
|
|
34
|
-
]),
|
|
35
|
-
index: %w[Yes No]
|
|
36
|
-
)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it "dups without corrupting the columns and preserves the MultiIndex" do
|
|
40
|
-
copy = dup_df.dup
|
|
41
|
-
|
|
42
|
-
expect(copy).to eq(dup_df)
|
|
43
|
-
expect(copy.vectors).to be_a(DaruLite::MultiIndex)
|
|
44
|
-
expect(copy.vectors).to eq(dup_df.vectors)
|
|
45
|
-
expect(copy.data.map(&:to_a)).to eq([[1, 2], [3, 4], [5, 6], [7, 8]])
|
|
46
|
-
expect(copy.vectors.object_id).not_to eq(dup_df.vectors.object_id)
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
describe "#clone_structure" do
|
|
53
|
-
subject { df.clone_structure }
|
|
54
|
-
|
|
55
|
-
it "clones only the index and vector structures of the data frame" do
|
|
56
|
-
expect(subject.vectors).to eq(df.vectors)
|
|
57
|
-
expect(subject.index).to eq(df.index)
|
|
58
|
-
expect(subject[:a]).to eq(DaruLite::Vector.new([nil] * subject[:a].size, index: df.index))
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
describe "#clone" do
|
|
63
|
-
subject { df.clone }
|
|
64
|
-
|
|
65
|
-
context 'no argument is passed' do
|
|
66
|
-
subject { df.clone }
|
|
67
|
-
|
|
68
|
-
it "returns a view of the whole dataframe" do
|
|
69
|
-
expect(df.object_id).to_not eq(subject.object_id)
|
|
70
|
-
expect(df[:a].object_id).to eq(subject[:a].object_id)
|
|
71
|
-
expect(df[:b].object_id).to eq(subject[:b].object_id)
|
|
72
|
-
expect(df[:c].object_id).to eq(subject[:c].object_id)
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
context 'vector names are passed' do
|
|
77
|
-
subject { df.clone(:a, :b) }
|
|
78
|
-
|
|
79
|
-
it "returns a view of selected vectors" do
|
|
80
|
-
expect(subject.object_id).to_not eq(df.object_id)
|
|
81
|
-
expect(subject[:a].object_id).to eq(df[:a].object_id)
|
|
82
|
-
expect(subject[:b].object_id).to eq(df[:b].object_id)
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
context 'array of vector names is passed' do
|
|
87
|
-
subject { df.clone([:a, :b]) }
|
|
88
|
-
|
|
89
|
-
it "clones properly when supplied array" do
|
|
90
|
-
expect(subject.object_id).to_not eq(df.object_id)
|
|
91
|
-
expect(subject[:a].object_id).to eq(df[:a].object_id)
|
|
92
|
-
expect(subject[:b].object_id).to eq(df[:b].object_id)
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
it "original dataframe remains unaffected when operations are applied on subject data frame" do
|
|
97
|
-
original = df.dup
|
|
98
|
-
subject.delete_vector :a
|
|
99
|
-
|
|
100
|
-
expect(df).to eq(original)
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
describe "#clone_only_valid" do
|
|
105
|
-
subject { df.clone_only_valid }
|
|
106
|
-
|
|
107
|
-
context 'df has missing values' do
|
|
108
|
-
let(:df) do
|
|
109
|
-
DaruLite::DataFrame.new({
|
|
110
|
-
a: [1 , 2, 3, nil, 4, nil, 5],
|
|
111
|
-
b: [nil, 2, 3, nil, 4, nil, 5],
|
|
112
|
-
c: [1, 2, 3, 43 , 4, nil, 5]
|
|
113
|
-
})
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
it 'clones only valid values' do
|
|
117
|
-
expect(subject).to eq(df.reject_values(*DaruLite::MISSING_VALUES))
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
context 'df has no missing values' do
|
|
122
|
-
let(:df) do
|
|
123
|
-
DaruLite::DataFrame.new({
|
|
124
|
-
a: [2,3,4,5],
|
|
125
|
-
c: [2,3,4,5]
|
|
126
|
-
})
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
it 'clones all values' do
|
|
130
|
-
expect(subject).to eq(df.clone)
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
end
|