daru 0.1.5 → 0.1.6
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/.rubocop.yml +20 -7
- data/CONTRIBUTING.md +1 -1
- data/History.md +48 -1
- data/README.md +3 -3
- data/benchmarks/statistics.rb +6 -6
- data/benchmarks/where_clause.rb +1 -1
- data/benchmarks/where_vs_filter.rb +1 -1
- data/daru.gemspec +3 -2
- data/lib/daru.rb +14 -6
- data/lib/daru/accessors/gsl_wrapper.rb +1 -1
- data/lib/daru/accessors/nmatrix_wrapper.rb +2 -0
- data/lib/daru/category.rb +1 -1
- data/lib/daru/core/group_by.rb +32 -15
- data/lib/daru/core/query.rb +4 -4
- data/lib/daru/dataframe.rb +196 -48
- data/lib/daru/date_time/index.rb +7 -5
- data/lib/daru/formatters/table.rb +1 -0
- data/lib/daru/index/index.rb +121 -33
- data/lib/daru/index/multi_index.rb +83 -3
- data/lib/daru/io/csv/converters.rb +18 -0
- data/lib/daru/io/io.rb +80 -11
- data/lib/daru/io/sql_data_source.rb +10 -0
- data/lib/daru/iruby/templates/dataframe.html.erb +3 -50
- data/lib/daru/iruby/templates/dataframe_mi.html.erb +3 -56
- data/lib/daru/iruby/templates/dataframe_mi_tbody.html.erb +35 -0
- data/lib/daru/iruby/templates/dataframe_mi_thead.html.erb +21 -0
- data/lib/daru/iruby/templates/dataframe_tbody.html.erb +28 -0
- data/lib/daru/iruby/templates/dataframe_thead.html.erb +21 -0
- data/lib/daru/iruby/templates/vector.html.erb +3 -25
- data/lib/daru/iruby/templates/vector_mi.html.erb +3 -34
- data/lib/daru/iruby/templates/vector_mi_tbody.html.erb +26 -0
- data/lib/daru/iruby/templates/vector_mi_thead.html.erb +8 -0
- data/lib/daru/iruby/templates/vector_tbody.html.erb +17 -0
- data/lib/daru/iruby/templates/vector_thead.html.erb +8 -0
- data/lib/daru/maths/statistics/dataframe.rb +9 -11
- data/lib/daru/maths/statistics/vector.rb +139 -32
- data/lib/daru/plotting/gruff/dataframe.rb +13 -15
- data/lib/daru/plotting/nyaplot/category.rb +1 -1
- data/lib/daru/plotting/nyaplot/dataframe.rb +4 -4
- data/lib/daru/plotting/nyaplot/vector.rb +1 -2
- data/lib/daru/vector.rb +169 -80
- data/lib/daru/version.rb +1 -1
- data/spec/category_spec.rb +19 -19
- data/spec/core/group_by_spec.rb +47 -0
- data/spec/core/query_spec.rb +55 -50
- data/spec/daru_spec.rb +22 -0
- data/spec/dataframe_spec.rb +118 -6
- data/spec/date_time/index_spec.rb +34 -16
- data/spec/extensions/rserve_spec.rb +1 -1
- data/spec/fixtures/boolean_converter_test.csv +5 -0
- data/spec/fixtures/eciresults.html +394 -0
- data/spec/fixtures/empty_rows_test.csv +17 -0
- data/spec/fixtures/macau.html +3691 -0
- data/spec/fixtures/macd_data.csv +150 -0
- data/spec/fixtures/moneycontrol.html +6812 -0
- data/spec/fixtures/url_test.txt~ +0 -0
- data/spec/fixtures/valid_markup.html +62 -0
- data/spec/fixtures/wiki_climate.html +1243 -0
- data/spec/fixtures/wiki_table_info.html +631 -0
- data/spec/formatters/table_formatter_spec.rb +29 -0
- data/spec/index/categorical_index_spec.rb +33 -33
- data/spec/index/index_spec.rb +134 -41
- data/spec/index/multi_index_spec.rb +115 -31
- data/spec/io/io_spec.rb +201 -0
- data/spec/io/sql_data_source_spec.rb +31 -41
- data/spec/iruby/dataframe_spec.rb +17 -19
- data/spec/iruby/vector_spec.rb +26 -28
- data/spec/maths/statistics/vector_spec.rb +136 -14
- data/spec/plotting/gruff/category_spec.rb +3 -3
- data/spec/plotting/gruff/dataframe_spec.rb +14 -4
- data/spec/plotting/gruff/vector_spec.rb +9 -9
- data/spec/plotting/nyaplot/category_spec.rb +5 -9
- data/spec/plotting/nyaplot/dataframe_spec.rb +72 -47
- data/spec/plotting/nyaplot/vector_spec.rb +5 -11
- data/spec/shared/vector_display_spec.rb +12 -14
- data/spec/spec_helper.rb +21 -0
- data/spec/support/matchers.rb +5 -0
- data/spec/vector_spec.rb +222 -72
- metadata +68 -23
- data/spec/fixtures/stock_data.csv +0 -500
data/lib/daru/version.rb
CHANGED
data/spec/category_spec.rb
CHANGED
@@ -383,13 +383,13 @@ describe Daru::Vector, "categorical" do
|
|
383
383
|
context "#rename_categories" do
|
384
384
|
context 'rename base category' do
|
385
385
|
let(:dv) { Daru::Vector.new [:a, 1, :a, 1, :c], type: :category,
|
386
|
-
categories: [:a, :x, :y, :c, :b, 1]}
|
386
|
+
categories: [:a, :x, :y, :c, :b, 1]}
|
387
387
|
subject { dv.rename_categories :a => 1, 1 => 2 }
|
388
388
|
|
389
389
|
it { is_expected.to be_a Daru::Vector }
|
390
390
|
its(:to_a) { is_expected.to eq [1, 2, 1, 2, :c] }
|
391
391
|
its(:categories) { is_expected.to eq [:x, :y, :c, :b, 1, 2] }
|
392
|
-
its(:base_category) { is_expected.to eq 1 }
|
392
|
+
its(:base_category) { is_expected.to eq 1 }
|
393
393
|
end
|
394
394
|
|
395
395
|
context 'rename non-base category' do
|
@@ -1398,7 +1398,7 @@ describe Daru::Vector, "categorical" do
|
|
1398
1398
|
index: 11..18, type: :category }
|
1399
1399
|
context 'reject only nils' do
|
1400
1400
|
subject { dv.reject_values nil }
|
1401
|
-
|
1401
|
+
|
1402
1402
|
it { is_expected.to be_a Daru::Vector }
|
1403
1403
|
its(:type) { is_expected.to eq :category }
|
1404
1404
|
its(:to_a) { is_expected.to eq [1, 3, :a, Float::NAN, Float::NAN, 1] }
|
@@ -1407,7 +1407,7 @@ describe Daru::Vector, "categorical" do
|
|
1407
1407
|
|
1408
1408
|
context 'reject only float::NAN' do
|
1409
1409
|
subject { dv.reject_values Float::NAN }
|
1410
|
-
|
1410
|
+
|
1411
1411
|
it { is_expected.to be_a Daru::Vector }
|
1412
1412
|
its(:type) { is_expected.to eq :category }
|
1413
1413
|
its(:to_a) { is_expected.to eq [1, nil, 3, :a, nil, 1] }
|
@@ -1422,7 +1422,7 @@ describe Daru::Vector, "categorical" do
|
|
1422
1422
|
its(:to_a) { is_expected.to eq [1, 3, :a, 1] }
|
1423
1423
|
its(:'index.to_a') { is_expected.to eq [11, 13, 14, 18] }
|
1424
1424
|
end
|
1425
|
-
|
1425
|
+
|
1426
1426
|
context 'reject any other value' do
|
1427
1427
|
subject { dv.reject_values 1, 3, 20 }
|
1428
1428
|
|
@@ -1434,19 +1434,19 @@ describe Daru::Vector, "categorical" do
|
|
1434
1434
|
|
1435
1435
|
context 'when resultant vector has only one value' do
|
1436
1436
|
subject { dv.reject_values 1, :a, nil, Float::NAN }
|
1437
|
-
|
1437
|
+
|
1438
1438
|
it { is_expected.to be_a Daru::Vector }
|
1439
1439
|
its(:to_a) { is_expected.to eq [3] }
|
1440
1440
|
its(:'index.to_a') { is_expected.to eq [13] }
|
1441
1441
|
end
|
1442
|
-
|
1442
|
+
|
1443
1443
|
context 'when resultant vector has no value' do
|
1444
1444
|
subject { dv.reject_values 1, 3, :a, nil, Float::NAN, 5 }
|
1445
|
-
|
1445
|
+
|
1446
1446
|
it { is_expected.to be_a Daru::Vector }
|
1447
1447
|
its(:to_a) { is_expected.to eq [] }
|
1448
1448
|
its(:'index.to_a') { is_expected.to eq [] }
|
1449
|
-
end
|
1449
|
+
end
|
1450
1450
|
end
|
1451
1451
|
|
1452
1452
|
context '#include_values?' do
|
@@ -1484,27 +1484,27 @@ describe Daru::Vector, "categorical" do
|
|
1484
1484
|
type: :category}
|
1485
1485
|
it { expect(dv.include_values? nil, Float::NAN).to eq true }
|
1486
1486
|
end
|
1487
|
-
|
1487
|
+
|
1488
1488
|
context 'true with only Float::NAN' do
|
1489
1489
|
let(:dv) { Daru::Vector.new [1, nil, 2, 3],
|
1490
1490
|
type: :category}
|
1491
1491
|
it { expect(dv.include_values? nil, Float::NAN).to eq true }
|
1492
1492
|
end
|
1493
|
-
|
1493
|
+
|
1494
1494
|
context 'false' do
|
1495
1495
|
let(:dv) { Daru::Vector.new [1, 2, 3],
|
1496
1496
|
type: :category}
|
1497
1497
|
it { expect(dv.include_values? nil, Float::NAN).to eq false }
|
1498
1498
|
end
|
1499
1499
|
end
|
1500
|
-
|
1500
|
+
|
1501
1501
|
context 'any other value' do
|
1502
1502
|
context 'true' do
|
1503
1503
|
let(:dv) { Daru::Vector.new [1, 2, 3, 4, nil],
|
1504
1504
|
type: :category }
|
1505
1505
|
it { expect(dv.include_values? 1, 2, 3, 5).to eq true }
|
1506
1506
|
end
|
1507
|
-
|
1507
|
+
|
1508
1508
|
context 'false' do
|
1509
1509
|
let(:dv) { Daru::Vector.new [1, 2, 3, 4, nil],
|
1510
1510
|
type: :category }
|
@@ -1525,12 +1525,12 @@ describe Daru::Vector, "categorical" do
|
|
1525
1525
|
context Daru::Index do
|
1526
1526
|
let(:dv) { Daru::Vector.new [1, 2, 1, 2, 3, nil, nil, Float::NAN],
|
1527
1527
|
index: 11..18, type: :category }
|
1528
|
-
|
1528
|
+
|
1529
1529
|
subject { dv.indexes 1, 2, nil, Float::NAN }
|
1530
1530
|
it { is_expected.to be_a Array }
|
1531
1531
|
it { is_expected.to eq [11, 12, 13, 14, 16, 17, 18] }
|
1532
1532
|
end
|
1533
|
-
|
1533
|
+
|
1534
1534
|
context Daru::MultiIndex do
|
1535
1535
|
let(:mi) do
|
1536
1536
|
Daru::MultiIndex.from_tuples([
|
@@ -1546,7 +1546,7 @@ describe Daru::Vector, "categorical" do
|
|
1546
1546
|
end
|
1547
1547
|
let(:dv) { Daru::Vector.new [1, 2, 1, 2, 3, nil, nil, Float::NAN],
|
1548
1548
|
index: mi, type: :category }
|
1549
|
-
|
1549
|
+
|
1550
1550
|
subject { dv.indexes 1, 2, Float::NAN }
|
1551
1551
|
it { is_expected.to be_a Array }
|
1552
1552
|
it { is_expected.to eq(
|
@@ -1559,7 +1559,7 @@ describe Daru::Vector, "categorical" do
|
|
1559
1559
|
]) }
|
1560
1560
|
end
|
1561
1561
|
end
|
1562
|
-
|
1562
|
+
|
1563
1563
|
context '#replace_values' do
|
1564
1564
|
subject do
|
1565
1565
|
Daru::Vector.new(
|
@@ -1573,14 +1573,14 @@ describe Daru::Vector, "categorical" do
|
|
1573
1573
|
its(:type) { is_expected.to eq :category }
|
1574
1574
|
its(:to_a) { is_expected.to eq [1, 2, 1, 4, 10, 10, 10, 10] }
|
1575
1575
|
end
|
1576
|
-
|
1576
|
+
|
1577
1577
|
context 'replace arbitrary values' do
|
1578
1578
|
before { subject.replace_values [1, 2], 10 }
|
1579
1579
|
its(:type) { is_expected.to eq :category }
|
1580
1580
|
its(:to_a) { is_expected.to eq(
|
1581
1581
|
[10, 10, 10, 4, nil, Float::NAN, nil, Float::NAN]) }
|
1582
1582
|
end
|
1583
|
-
|
1583
|
+
|
1584
1584
|
context 'works for single value' do
|
1585
1585
|
before { subject.replace_values nil, 10 }
|
1586
1586
|
its(:type) { is_expected.to eq :category }
|
data/spec/core/group_by_spec.rb
CHANGED
@@ -29,6 +29,7 @@ describe Daru::Core::GroupBy do
|
|
29
29
|
['foo', 'three', 8],
|
30
30
|
['foo', 'two' , 3]
|
31
31
|
])
|
32
|
+
|
32
33
|
end
|
33
34
|
|
34
35
|
context 'with nil values' do
|
@@ -46,6 +47,34 @@ describe Daru::Core::GroupBy do
|
|
46
47
|
end
|
47
48
|
|
48
49
|
context "#initialize" do
|
50
|
+
let(:df_emp) { Daru::DataFrame.new(
|
51
|
+
employee: %w[John Jane Mark John Jane Mark],
|
52
|
+
month: %w[June June June July July July],
|
53
|
+
salary: [1000, 500, 700, 1200, 600, 600]
|
54
|
+
) }
|
55
|
+
let(:employee_grp) { df_emp.group_by(:employee).df }
|
56
|
+
let(:mi_single) { Daru::MultiIndex.from_tuples([
|
57
|
+
['Jane', 1], ['Jane', 4], ['John', 0],
|
58
|
+
['John', 3], ['Mark', 2], ['Mark', 5]
|
59
|
+
]
|
60
|
+
)}
|
61
|
+
|
62
|
+
let(:emp_month_grp) { df_emp.group_by([:employee, :month]).df }
|
63
|
+
let(:mi_double) { Daru::MultiIndex.from_tuples([
|
64
|
+
['Jane', 'July', 4], ['Jane', 'June', 1], ['John', 'July', 3],
|
65
|
+
['John', 'June', 0], ['Mark', 'July', 5], ['Mark', 'June', 2]
|
66
|
+
]
|
67
|
+
)}
|
68
|
+
|
69
|
+
let(:emp_month_salary_grp) {
|
70
|
+
df_emp.group_by([:employee, :month, :salary]).df }
|
71
|
+
let(:mi_triple) { Daru::MultiIndex.from_tuples([
|
72
|
+
['Jane', 'July', 600, 4], ['Jane', 'June', 500, 1],
|
73
|
+
['John', 'July', 1200, 3], ['John', 'June', 1000, 0],
|
74
|
+
['Mark', 'July', 600, 5], ['Mark', 'June', 700, 2]
|
75
|
+
]
|
76
|
+
)}
|
77
|
+
|
49
78
|
it "groups by a single tuple" do
|
50
79
|
expect(@sl_group.groups).to eq({
|
51
80
|
['bar'] => [1,3,5],
|
@@ -53,6 +82,24 @@ describe Daru::Core::GroupBy do
|
|
53
82
|
})
|
54
83
|
end
|
55
84
|
|
85
|
+
it "returns dataframe with MultiIndex, groups by single layer hierarchy" do
|
86
|
+
expect(employee_grp).to eq(Daru::DataFrame.new({
|
87
|
+
month: ["June", "July", "June", "July", "June", "July"],
|
88
|
+
salary: [500, 600, 1000, 1200, 700, 600]
|
89
|
+
}, index: mi_single))
|
90
|
+
end
|
91
|
+
|
92
|
+
it "returns dataframe with MultiIndex, groups by double layer hierarchy" do
|
93
|
+
expect(emp_month_grp).to eq(Daru::DataFrame.new({
|
94
|
+
salary: [600, 500, 1200, 1000, 600, 700]
|
95
|
+
}, index: mi_double))
|
96
|
+
end
|
97
|
+
|
98
|
+
it "returns dataframe with MultiIndex, groups by triple layer hierarchy" do
|
99
|
+
expect(emp_month_salary_grp).to eq(Daru::DataFrame.new({
|
100
|
+
}, index: mi_triple))
|
101
|
+
end
|
102
|
+
|
56
103
|
it "groups by a double layer hierarchy" do
|
57
104
|
expect(@dl_group.groups).to eq({
|
58
105
|
['foo', 'one'] => [0,6],
|
data/spec/core/query_spec.rb
CHANGED
@@ -43,79 +43,79 @@ describe "Arel-like syntax" do
|
|
43
43
|
@comparator = Daru::Vector.new([45,22,1214,55,32,9])
|
44
44
|
@klass = Daru::Core::Query::BoolArray
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
context "#eq" do
|
48
48
|
it "accepts scalar value" do
|
49
49
|
expect(@vector.eq(352)).to eq(
|
50
50
|
@klass.new([false,false,false,true,false,false]))
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
it "accepts vector and compares corrensponding elements" do
|
54
54
|
expect(@vector.eq(@comparator)).to eq(
|
55
55
|
@klass.new([false,false,true,false,true,false]))
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
context "#not_eq" do
|
60
60
|
it "accepts scalar value" do
|
61
61
|
expect(@vector.not_eq(51)).to eq(
|
62
62
|
@klass.new([true, false, true, true, true, true]))
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
it "accepts vector and compares corrensponding elements" do
|
66
66
|
expect(@vector.not_eq(@comparator)).to eq(
|
67
67
|
@klass.new([true, true, false, true, false, true]))
|
68
68
|
end
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
context "#lt" do
|
72
72
|
it "accepts scalar value" do
|
73
73
|
expect(@vector.lt(51)).to eq(
|
74
74
|
@klass.new([true, false, false, false, true, true]))
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
it "accepts vector and compares corrensponding elements" do
|
78
78
|
expect(@vector.lt(@comparator)).to eq(
|
79
79
|
@klass.new([true,false,false,false,false,false]))
|
80
80
|
end
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
context "#lteq" do
|
84
84
|
it "accepts scalar value" do
|
85
85
|
expect(@vector.lteq(51)).to eq(
|
86
86
|
@klass.new([true, true, false, false, true, true]))
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
it "accepts vector and compares corrensponding elements" do
|
90
90
|
expect(@vector.lteq(@comparator)).to eq(
|
91
91
|
@klass.new([true,false,true,false,true,false]))
|
92
92
|
end
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
context "#mt" do
|
96
96
|
it "accepts scalar value" do
|
97
97
|
expect(@vector.mt(51)).to eq(
|
98
98
|
@klass.new([false, false, true, true, false, false]))
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
it "accepts vector and compares corrensponding elements" do
|
102
102
|
expect(@vector.mt(@comparator)).to eq(
|
103
103
|
@klass.new([false,true,false,true,false,true]))
|
104
104
|
end
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
context "#mteq" do
|
108
108
|
it "accepts scalar value" do
|
109
109
|
expect(@vector.mteq(51)).to eq(
|
110
110
|
@klass.new([false, true, true, true, false, false]))
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
it "accepts vector and compares corrensponding elements" do
|
114
114
|
expect(@vector.mteq(@comparator)).to eq(
|
115
115
|
@klass.new([false,true,true,true,true,true]))
|
116
116
|
end
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
context "#in" do
|
120
120
|
it "checks if any of elements in the arg are present in the vector" do
|
121
121
|
expect(@vector.in([23,55,1,33,32])).to eq(
|
@@ -123,7 +123,7 @@ describe "Arel-like syntax" do
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
end
|
126
|
-
|
126
|
+
|
127
127
|
describe "categorical type" do
|
128
128
|
let(:dv) { Daru::Vector.new ['e', 'd', 'd', 'x', 'x'],
|
129
129
|
categories: ['a', 'x', 'c', 'd', 'e'], type: :category }
|
@@ -134,99 +134,99 @@ describe "Arel-like syntax" do
|
|
134
134
|
context "#eq" do
|
135
135
|
context "scalar" do
|
136
136
|
subject { dv.eq 'd' }
|
137
|
-
|
137
|
+
|
138
138
|
it { is_expected.to be_a query_bool_class }
|
139
139
|
its(:to_a) { is_expected.to eq [false, true, true, false, false] }
|
140
140
|
end
|
141
141
|
|
142
142
|
context "vector" do
|
143
143
|
subject { dv.eq comp }
|
144
|
-
|
144
|
+
|
145
145
|
it { is_expected.to be_a query_bool_class }
|
146
146
|
its(:to_a) { is_expected.to eq [false, true, false, false, true] }
|
147
147
|
end
|
148
148
|
end
|
149
|
-
|
149
|
+
|
150
150
|
context "#not_eq" do
|
151
151
|
context "scalar" do
|
152
152
|
subject { dv.not_eq 'd' }
|
153
|
-
|
153
|
+
|
154
154
|
it { is_expected.to be_a query_bool_class }
|
155
155
|
its(:to_a) { is_expected.to eq [true, false, false, true, true] }
|
156
156
|
end
|
157
|
-
|
157
|
+
|
158
158
|
context "vector" do
|
159
159
|
subject { dv.not_eq comp }
|
160
|
-
|
160
|
+
|
161
161
|
it { is_expected.to be_a query_bool_class }
|
162
162
|
its(:to_a) { is_expected.to eq [true, false, true, true, false] }
|
163
163
|
end
|
164
164
|
end
|
165
|
-
|
165
|
+
|
166
166
|
context "#lt" do
|
167
167
|
context "scalar" do
|
168
168
|
subject { dv.lt 'd' }
|
169
|
-
|
169
|
+
|
170
170
|
it { is_expected.to be_a query_bool_class }
|
171
171
|
its(:to_a) { is_expected.to eq [false, false, false, true, true] }
|
172
172
|
end
|
173
|
-
|
173
|
+
|
174
174
|
context "vector" do
|
175
175
|
subject { dv.lt comp }
|
176
|
-
|
176
|
+
|
177
177
|
it { is_expected.to be_a query_bool_class }
|
178
178
|
its(:to_a) { is_expected.to eq [false, false, false, true, false] }
|
179
179
|
end
|
180
180
|
end
|
181
|
-
|
181
|
+
|
182
182
|
context "#lteq" do
|
183
183
|
context "scalar" do
|
184
184
|
subject { dv.lteq 'd' }
|
185
|
-
|
185
|
+
|
186
186
|
it { is_expected.to be_a query_bool_class }
|
187
187
|
its(:to_a) { is_expected.to eq [false, true, true, true, true] }
|
188
188
|
end
|
189
|
-
|
189
|
+
|
190
190
|
context "vector" do
|
191
191
|
subject { dv.lteq comp }
|
192
|
-
|
192
|
+
|
193
193
|
it { is_expected.to be_a query_bool_class }
|
194
194
|
its(:to_a) { is_expected.to eq [false, true, false, true, true] }
|
195
195
|
end
|
196
196
|
end
|
197
|
-
|
197
|
+
|
198
198
|
context "#mt" do
|
199
199
|
context "scalar" do
|
200
200
|
subject { dv.mt 'd' }
|
201
|
-
|
201
|
+
|
202
202
|
it { is_expected.to be_a query_bool_class }
|
203
203
|
its(:to_a) { is_expected.to eq [true, false, false, false, false] }
|
204
204
|
end
|
205
|
-
|
205
|
+
|
206
206
|
context "vector" do
|
207
207
|
subject { dv.mt comp }
|
208
|
-
|
208
|
+
|
209
209
|
it { is_expected.to be_a query_bool_class }
|
210
210
|
its(:to_a) { is_expected.to eq [true, false, true, false, false] }
|
211
211
|
end
|
212
212
|
end
|
213
|
-
|
213
|
+
|
214
214
|
context "#mteq" do
|
215
215
|
context "scalar" do
|
216
216
|
subject { dv.mteq 'd' }
|
217
|
-
|
217
|
+
|
218
218
|
it { is_expected.to be_a query_bool_class }
|
219
219
|
its(:to_a) { is_expected.to eq [true, true, true, false, false] }
|
220
220
|
end
|
221
|
-
|
221
|
+
|
222
222
|
context "vector" do
|
223
223
|
subject { dv.mteq comp }
|
224
|
-
|
224
|
+
|
225
225
|
it { is_expected.to be_a query_bool_class }
|
226
226
|
its(:to_a) { is_expected.to eq [true, true, true, false, true] }
|
227
227
|
end
|
228
228
|
end
|
229
|
-
|
229
|
+
|
230
230
|
# context "#in" do
|
231
231
|
# subject { dv.in ['b', 'd'] }
|
232
232
|
# it { is_expected.to be_a query_bool_class }
|
@@ -240,9 +240,9 @@ describe "Arel-like syntax" do
|
|
240
240
|
context Daru::DataFrame do
|
241
241
|
before do
|
242
242
|
@df = Daru::DataFrame.new({
|
243
|
-
number: [1,2,3,4,5,6],
|
244
|
-
sym: [:one, :two, :three, :four, :five, :six],
|
245
|
-
names: ['sameer', 'john', 'james', 'omisha', 'priyanka', 'shravan']
|
243
|
+
number: [1,2,3,4,5,6,Float::NAN],
|
244
|
+
sym: [:one, :two, :three, :four, :five, :six, :seven],
|
245
|
+
names: ['sameer', 'john', 'james', 'omisha', 'priyanka', 'shravan',nil]
|
246
246
|
})
|
247
247
|
end
|
248
248
|
|
@@ -267,6 +267,11 @@ describe "Arel-like syntax" do
|
|
267
267
|
).to eq(answer)
|
268
268
|
end
|
269
269
|
|
270
|
+
let(:dv) { Daru::Vector.new([1,11,32,Float::NAN,nil]) }
|
271
|
+
it "handles empty data" do
|
272
|
+
expect(dv.where(dv.lt(14))).to eq(Daru::Vector.new([1,11]))
|
273
|
+
end
|
274
|
+
|
270
275
|
it "does not give SystemStackError" do
|
271
276
|
v = Daru::Vector.new [1]*300_000
|
272
277
|
expect { v.where v.eq(1) }.not_to raise_error
|
@@ -276,45 +281,45 @@ describe "Arel-like syntax" do
|
|
276
281
|
context Daru::Vector do
|
277
282
|
context "non-categorical type" do
|
278
283
|
before do
|
279
|
-
@vector = Daru::Vector.new([2,5,1,22,51,4])
|
284
|
+
@vector = Daru::Vector.new([2,5,1,22,51,4,nil,Float::NAN])
|
280
285
|
end
|
281
|
-
|
286
|
+
|
282
287
|
it "accepts a simple single statement" do
|
283
288
|
expect(@vector.where(@vector.lt(10))).to eq(
|
284
289
|
Daru::Vector.new([2,5,1,4], index: Daru::Index.new([0,1,2,5])))
|
285
290
|
end
|
286
|
-
|
291
|
+
|
287
292
|
it "accepts somewhat complex operator chaining" do
|
288
293
|
expect(@vector.where((@vector.lt(6) | @vector.eq(51)))).to eq(
|
289
294
|
Daru::Vector.new([2,5,1,51,4], index: Daru::Index.new([0,1,2,4,5])))
|
290
295
|
end
|
291
296
|
end
|
292
|
-
|
297
|
+
|
293
298
|
context "categorical type" do
|
294
299
|
let(:dv) { Daru::Vector.new ['a', 'c', 'x', 'x', 'c'],
|
295
300
|
categories: ['a', 'x', 'c'], type: :category }
|
296
|
-
|
301
|
+
|
297
302
|
context "simple single statement" do
|
298
303
|
subject { dv.where(dv.lt('x')) }
|
299
|
-
|
304
|
+
|
300
305
|
it { is_expected.to be_a Daru::Vector }
|
301
306
|
its(:type) { is_expected.to eq :category }
|
302
307
|
its(:to_a) { is_expected.to eq ['a'] }
|
303
308
|
its(:'index.to_a') { is_expected.to eq [0] }
|
304
309
|
end
|
305
|
-
|
310
|
+
|
306
311
|
context "complex operator chaining" do
|
307
312
|
subject { dv.where((dv.lt('x') | dv.eq('c'))) }
|
308
|
-
|
313
|
+
|
309
314
|
it { is_expected.to be_a Daru::Vector }
|
310
315
|
its(:type) { is_expected.to eq :category }
|
311
316
|
its(:to_a) { is_expected.to eq ['a', 'c', 'c'] }
|
312
317
|
its(:'index.to_a') { is_expected.to eq [0, 1, 4] }
|
313
318
|
end
|
314
|
-
|
319
|
+
|
315
320
|
context "preserve categories" do
|
316
321
|
subject { dv.where((dv.lt('x') | dv.eq('c'))) }
|
317
|
-
|
322
|
+
|
318
323
|
it { is_expected.to be_a Daru::Vector }
|
319
324
|
its(:type) { is_expected.to eq :category }
|
320
325
|
its(:to_a) { is_expected.to eq ['a', 'c', 'c'] }
|