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.
- checksums.yaml +4 -4
- data/History.md +60 -0
- data/README.md +1 -1
- data/lib/daru_lite/category.rb +1 -1
- data/lib/daru_lite/date_time/index.rb +2 -2
- data/lib/daru_lite/maths/statistics/vector.rb +1 -1
- data/lib/daru_lite/version.rb +1 -1
- data/lib/daru_lite.rb +1 -0
- metadata +54 -284
- 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/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,465 +0,0 @@
|
|
|
1
|
-
include DaruLite
|
|
2
|
-
|
|
3
|
-
describe DateOffset do
|
|
4
|
-
context "#initialize, #+, #-" do
|
|
5
|
-
it "creates a seconds offset" do
|
|
6
|
-
offset = DateOffset.new(secs: 5)
|
|
7
|
-
expect(offset + DateTime.new(2012,3,4,23,4,00)).to eq(
|
|
8
|
-
DateTime.new(2012,3,4,23,4,05))
|
|
9
|
-
expect(offset - DateTime.new(2012,4,2,22,4,23)).to eq(
|
|
10
|
-
DateTime.new(2012,4,2,22,4,18))
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "creates a minutes offset" do
|
|
14
|
-
offset = DateOffset.new(mins: 2)
|
|
15
|
-
expect(offset + DateTime.new(2013,4,5,12,45,44)).to eq(
|
|
16
|
-
DateTime.new(2013,4,5,12,47,44))
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "creates an hours offset" do
|
|
20
|
-
offset = DateOffset.new(hours: 3)
|
|
21
|
-
expect(offset + DateTime.new(2024,3,2)).to eq(
|
|
22
|
-
DateTime.new(2024,3,2,03,0,0))
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it "creates a days offset" do
|
|
26
|
-
offset = DateOffset.new(days: 12)
|
|
27
|
-
expect(offset + DateTime.new(2012,5,4)).to eq(
|
|
28
|
-
DateTime.new(2012,5,16))
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "creates a weeks offset" do
|
|
32
|
-
offset = DateOffset.new(weeks: 2)
|
|
33
|
-
expect(offset + DateTime.new(2012,3,1)).to eq(
|
|
34
|
-
DateTime.new(2012,3,15))
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "creates a months offset" do
|
|
38
|
-
offset = DateOffset.new(months: 1)
|
|
39
|
-
expect(offset + DateTime.new(2012,3,1)).to eq(
|
|
40
|
-
DateTime.new(2012,4,1))
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it "creates a years offset" do
|
|
44
|
-
offset = DateOffset.new(years: 2)
|
|
45
|
-
expect(offset + DateTime.new(2012,5,30)).to eq(
|
|
46
|
-
DateTime.new(2014,5,30))
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it "supports 'n' option to apply same offset multiple times" do
|
|
50
|
-
offset = DateOffset.new(days: 3, n: 4)
|
|
51
|
-
expect(offset + DateTime.new(2012,3,1)).to eq(
|
|
52
|
-
DateTime.new(2012,3,13))
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
describe NegativeDateOffset do
|
|
58
|
-
context "#initialize, #+, #-" do
|
|
59
|
-
it "creates a seconds offset" do
|
|
60
|
-
offset = -DateOffset.new(secs: 5)
|
|
61
|
-
expect(offset + DateTime.new(2012,3,4,23,4,05)).to eq(
|
|
62
|
-
DateTime.new(2012,3,4,23,4,00))
|
|
63
|
-
expect(offset - DateTime.new(2012,4,2,22,4,18)).to eq(
|
|
64
|
-
DateTime.new(2012,4,2,22,4,23))
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
it "creates a minutes offset" do
|
|
68
|
-
offset = -DateOffset.new(mins: 2)
|
|
69
|
-
expect(offset + DateTime.new(2013,4,5,12,47,44)).to eq(
|
|
70
|
-
DateTime.new(2013,4,5,12,45,44))
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
it "creates an hours offset" do
|
|
74
|
-
offset = -DateOffset.new(hours: 3)
|
|
75
|
-
expect(offset + DateTime.new(2024,3,2,3)).to eq(
|
|
76
|
-
DateTime.new(2024,3,2,0))
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
it "creates a days offset" do
|
|
80
|
-
offset = -DateOffset.new(days: 12)
|
|
81
|
-
expect(offset + DateTime.new(2012,5,16)).to eq(
|
|
82
|
-
DateTime.new(2012,5,4))
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "creates a weeks offset" do
|
|
86
|
-
offset = -DateOffset.new(weeks: 2)
|
|
87
|
-
expect(offset + DateTime.new(2012,3,15)).to eq(
|
|
88
|
-
DateTime.new(2012,3,1))
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
it "creates a months offset" do
|
|
92
|
-
offset = -DateOffset.new(months: 1)
|
|
93
|
-
expect(offset + DateTime.new(2012,4,1)).to eq(
|
|
94
|
-
DateTime.new(2012,3,1))
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
it "creates a years offset" do
|
|
98
|
-
offset = -DateOffset.new(years: 2)
|
|
99
|
-
expect(offset + DateTime.new(2014,5,30)).to eq(
|
|
100
|
-
DateTime.new(2012,5,30))
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
it "supports 'n' option to apply same offset multiple times" do
|
|
104
|
-
offset = -DateOffset.new(days: 3, n: 4)
|
|
105
|
-
expect(offset + DateTime.new(2012,3,13)).to eq(
|
|
106
|
-
DateTime.new(2012,3,1))
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
context "#-@" do
|
|
111
|
-
it "creates a date offset" do
|
|
112
|
-
negative_offset = -DateOffset.new(secs: 5)
|
|
113
|
-
offset = -negative_offset
|
|
114
|
-
|
|
115
|
-
expect(offset + DateTime.new(2012,3,4,23,4,0)).to eq(
|
|
116
|
-
DateTime.new(2012,3,4,23,4,5))
|
|
117
|
-
expect(offset - DateTime.new(2012,4,2,22,4,23)).to eq(
|
|
118
|
-
DateTime.new(2012,4,2,22,4,18))
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
include DaruLite::Offsets
|
|
124
|
-
describe Offsets do
|
|
125
|
-
describe Second do
|
|
126
|
-
before do
|
|
127
|
-
@offset = Offsets::Second.new(5)
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
context "#initialize" do
|
|
131
|
-
it "creates a seconds offset" do
|
|
132
|
-
expect(@offset + DateTime.new(2012,3,4,23,4,00)).to eq(
|
|
133
|
-
DateTime.new(2012,3,4,23,4,05))
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
context "#-" do
|
|
138
|
-
it "reduces by seconds" do
|
|
139
|
-
expect(@offset - DateTime.new(2012,2,3,12,4,23)).to eq(
|
|
140
|
-
DateTime.new(2012,2,3,12,4,18))
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
context "#==" do
|
|
145
|
-
it 'equals the same offset' do
|
|
146
|
-
expect(Offsets::Second.new(5)).to eq(Offsets::Second.new(5))
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
it 'does equal a different offset' do
|
|
150
|
-
expect(Offsets::Second.new(5)).to_not eq(Offsets::Second.new(4))
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
it 'equals offets with the same period' do
|
|
154
|
-
expect(Offsets::Second.new(60)).to eq(Offsets::Minute.new())
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
describe Minute do
|
|
160
|
-
context "#initialize" do
|
|
161
|
-
it "creates a minutes offset" do
|
|
162
|
-
offset = Offsets::Minute.new(2)
|
|
163
|
-
expect(offset + DateTime.new(2013,4,5,12,45,44)).to eq(
|
|
164
|
-
DateTime.new(2013,4,5,12,47,44))
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
context "#-" do
|
|
169
|
-
it "reduces by minutes" do
|
|
170
|
-
end
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
describe Hour do
|
|
175
|
-
context "#initialize" do
|
|
176
|
-
it "creates an hours offset" do
|
|
177
|
-
offset = Offsets::Hour.new(3)
|
|
178
|
-
expect(offset + DateTime.new(2024,3,2)).to eq(
|
|
179
|
-
DateTime.new(2024,3,2,03,0,0))
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
context "#-" do
|
|
184
|
-
it "reduces by hours" do
|
|
185
|
-
end
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
describe Day do
|
|
190
|
-
context "#initialize" do
|
|
191
|
-
it "creates a days offset" do
|
|
192
|
-
offset = Offsets::Day.new(12)
|
|
193
|
-
expect(offset + DateTime.new(2012,5,4)).to eq(
|
|
194
|
-
DateTime.new(2012,5,16))
|
|
195
|
-
end
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
context "#-" do
|
|
199
|
-
it "reduces by days" do
|
|
200
|
-
end
|
|
201
|
-
end
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
describe Week do
|
|
205
|
-
DAYS_ADVANCE = {
|
|
206
|
-
sunday: DateTime.new(2015,7,12),
|
|
207
|
-
monday: DateTime.new(2015,7,13),
|
|
208
|
-
tuesday: DateTime.new(2015,7,14),
|
|
209
|
-
wednesday: DateTime.new(2015,7,15),
|
|
210
|
-
thursday: DateTime.new(2015,7,16),
|
|
211
|
-
friday: DateTime.new(2015,7,17),
|
|
212
|
-
saturday: DateTime.new(2015,7,11)
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
DAYS_ADVANCE.each.with_index do |day_date, i|
|
|
216
|
-
offset = Offsets::Week.new(weekday: i)
|
|
217
|
-
|
|
218
|
-
context "#initialize" do
|
|
219
|
-
date = DateTime.new(2015,7,10)
|
|
220
|
-
|
|
221
|
-
it "creates anchored Week offset for #{day_date[0]}" do
|
|
222
|
-
expect(offset + date).to eq(day_date[1])
|
|
223
|
-
end
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
context "#on_offset?" do
|
|
227
|
-
it "checks if given DateTime is on the offset itself? (#{day_date[0]})" do
|
|
228
|
-
expect(offset.on_offset?(DAYS_ADVANCE[day_date[0]])).to eq(true)
|
|
229
|
-
end
|
|
230
|
-
end
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
context "#-" do
|
|
234
|
-
DAYS_RETREAT = {
|
|
235
|
-
sunday: DateTime.new(2015,7,12),
|
|
236
|
-
monday: DateTime.new(2015,7,13),
|
|
237
|
-
tuesday: DateTime.new(2015,7,14),
|
|
238
|
-
wednesday: DateTime.new(2015,7,8),
|
|
239
|
-
thursday: DateTime.new(2015,7,9),
|
|
240
|
-
friday: DateTime.new(2015,7,10),
|
|
241
|
-
saturday: DateTime.new(2015,7,11)
|
|
242
|
-
}
|
|
243
|
-
date = DateTime.new(2015,7,15)
|
|
244
|
-
|
|
245
|
-
DAYS_RETREAT.each.with_index do |day_date, i|
|
|
246
|
-
it "decreases the date to nearest preceding #{day_date[0]}" do
|
|
247
|
-
offset = Offsets::Week.new(weekday: i)
|
|
248
|
-
expect(offset - date).to eq(day_date[1])
|
|
249
|
-
end
|
|
250
|
-
end
|
|
251
|
-
end
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
describe Month do
|
|
255
|
-
context "#initialize" do
|
|
256
|
-
it "creates a month offset" do
|
|
257
|
-
offset = Offsets::Month.new(3)
|
|
258
|
-
expect(offset + DateTime.new(2012,2,29)).to eq(
|
|
259
|
-
DateTime.new(2012,5,29))
|
|
260
|
-
end
|
|
261
|
-
end
|
|
262
|
-
|
|
263
|
-
context "#-" do
|
|
264
|
-
it "reduces date by a month" do
|
|
265
|
-
offset = Offsets::Month.new(2)
|
|
266
|
-
expect(offset - DateTime.new(2012,4,2)).to eq(
|
|
267
|
-
DateTime.new(2012,2,2))
|
|
268
|
-
end
|
|
269
|
-
end
|
|
270
|
-
end
|
|
271
|
-
|
|
272
|
-
describe MonthBegin do
|
|
273
|
-
before do
|
|
274
|
-
@offset = Offsets::MonthBegin.new
|
|
275
|
-
@n_offset = Offsets::MonthBegin.new(3)
|
|
276
|
-
end
|
|
277
|
-
|
|
278
|
-
context "#+" do
|
|
279
|
-
it "offsets to beginning of next month" do
|
|
280
|
-
expect(@offset + DateTime.new(2012,3,25)).to eq(
|
|
281
|
-
DateTime.new(2012,4,1))
|
|
282
|
-
|
|
283
|
-
expect(@n_offset + DateTime.new(2011,3,1,5)).to eq(
|
|
284
|
-
DateTime.new(2011,6,1,5))
|
|
285
|
-
end
|
|
286
|
-
end
|
|
287
|
-
|
|
288
|
-
context "#on_offset?" do
|
|
289
|
-
it "returns true if date is on the offset" do
|
|
290
|
-
expect(@offset.on_offset?(DateTime.new(2012,4,1))).to eq(true)
|
|
291
|
-
end
|
|
292
|
-
|
|
293
|
-
it "returns false if date is not on the offset" do
|
|
294
|
-
expect(@offset.on_offset?(DateTime.new(2012,4,30))).to eq(false)
|
|
295
|
-
end
|
|
296
|
-
end
|
|
297
|
-
|
|
298
|
-
context "#-" do
|
|
299
|
-
it "decreases to beginning of the current month if not on offset" do
|
|
300
|
-
expect(@offset - DateTime.new(2012,4,5)).to eq(
|
|
301
|
-
DateTime.new(2012,4,1))
|
|
302
|
-
|
|
303
|
-
expect(@n_offset - DateTime.new(2012,5,3)).to eq(
|
|
304
|
-
DateTime.new(2012,3,1))
|
|
305
|
-
end
|
|
306
|
-
|
|
307
|
-
it "decreases to beginning of the previous month if on offset" do
|
|
308
|
-
expect(@offset - DateTime.new(2012,5,1)).to eq(
|
|
309
|
-
DateTime.new(2012,4,1))
|
|
310
|
-
|
|
311
|
-
expect(@n_offset - DateTime.new(2012,6,1)).to eq(
|
|
312
|
-
DateTime.new(2012,3,1))
|
|
313
|
-
end
|
|
314
|
-
end
|
|
315
|
-
end
|
|
316
|
-
|
|
317
|
-
describe MonthEnd do
|
|
318
|
-
before do
|
|
319
|
-
@offset = Offsets::MonthEnd.new
|
|
320
|
-
@n_offset = Offsets::MonthEnd.new(2)
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
context "#+" do
|
|
324
|
-
it "increases date to end of next month if on offset" do
|
|
325
|
-
expect(@offset + DateTime.new(2012,2,29)).to eq(
|
|
326
|
-
DateTime.new(2012,3,31))
|
|
327
|
-
|
|
328
|
-
expect(@n_offset + DateTime.new(2012,2,29)).to eq(
|
|
329
|
-
DateTime.new(2012,4,30))
|
|
330
|
-
end
|
|
331
|
-
|
|
332
|
-
it "increases date to end of this month if not on offset" do
|
|
333
|
-
expect(@offset + DateTime.new(2012,4,4)).to eq(
|
|
334
|
-
DateTime.new(2012,4,30))
|
|
335
|
-
|
|
336
|
-
expect(@n_offset + DateTime.new(2012,5,2)).to eq(
|
|
337
|
-
DateTime.new(2012,6,30))
|
|
338
|
-
end
|
|
339
|
-
end
|
|
340
|
-
|
|
341
|
-
context "#-" do
|
|
342
|
-
it "decreases to end of the previous month" do
|
|
343
|
-
expect(@offset - DateTime.new(2012,2,29)).to eq(
|
|
344
|
-
DateTime.new(2012,1,31))
|
|
345
|
-
|
|
346
|
-
expect(@n_offset - DateTime.new(2015,3,3)).to eq(
|
|
347
|
-
DateTime.new(2015,1,31))
|
|
348
|
-
end
|
|
349
|
-
end
|
|
350
|
-
|
|
351
|
-
context "#on_offset?" do
|
|
352
|
-
it "returns true if date is on the offset" do
|
|
353
|
-
expect(@offset.on_offset?(DateTime.new(2012,4,30))).to eq(true)
|
|
354
|
-
end
|
|
355
|
-
|
|
356
|
-
it "returns false if date is not on the offset" do
|
|
357
|
-
expect(@offset.on_offset?(DateTime.new(2012,4,1))).to eq(false)
|
|
358
|
-
end
|
|
359
|
-
end
|
|
360
|
-
end
|
|
361
|
-
|
|
362
|
-
describe Year do
|
|
363
|
-
before do
|
|
364
|
-
@offset = Offsets::Year.new
|
|
365
|
-
end
|
|
366
|
-
|
|
367
|
-
context "#+" do
|
|
368
|
-
it "increaes date by a year" do
|
|
369
|
-
expect(@offset + DateTime.new(2012,5,2)).to eq(
|
|
370
|
-
DateTime.new(2013,5,2))
|
|
371
|
-
end
|
|
372
|
-
end
|
|
373
|
-
|
|
374
|
-
context "#-" do
|
|
375
|
-
it "decreases date by a year" do
|
|
376
|
-
expect(@offset - DateTime.new(2011,6,25)).to eq(
|
|
377
|
-
DateTime.new(2010,6,25))
|
|
378
|
-
end
|
|
379
|
-
end
|
|
380
|
-
end
|
|
381
|
-
|
|
382
|
-
describe YearBegin do
|
|
383
|
-
before do
|
|
384
|
-
@offset = Offsets::YearBegin.new
|
|
385
|
-
@n_offset = Offsets::YearBegin.new(2)
|
|
386
|
-
end
|
|
387
|
-
|
|
388
|
-
context "#+" do
|
|
389
|
-
it "offsets date to future" do
|
|
390
|
-
expect(@n_offset + DateTime.new(2012,3,25)).to eq(
|
|
391
|
-
DateTime.new(2014,1,1))
|
|
392
|
-
end
|
|
393
|
-
end
|
|
394
|
-
|
|
395
|
-
context "#on_offset?" do
|
|
396
|
-
it "checks if date is on the offset" do
|
|
397
|
-
expect(@offset.on_offset?(DateTime.new(2012,1,1))).to eq(
|
|
398
|
-
true)
|
|
399
|
-
|
|
400
|
-
expect(@offset.on_offset?(DateTime.new(2012,12,31))).to eq(
|
|
401
|
-
false)
|
|
402
|
-
end
|
|
403
|
-
end
|
|
404
|
-
|
|
405
|
-
context "#-" do
|
|
406
|
-
it "decreases to beginning of the year if not on offset" do
|
|
407
|
-
expect(@offset - DateTime.new(2012,4,2)).to eq(
|
|
408
|
-
DateTime.new(2012,1,1))
|
|
409
|
-
|
|
410
|
-
expect(@n_offset - DateTime.new(2012,5,5)).to eq(
|
|
411
|
-
DateTime.new(2011,1,1))
|
|
412
|
-
end
|
|
413
|
-
|
|
414
|
-
it "decreases to beginning of previous year if on offset" do
|
|
415
|
-
expect(@offset - DateTime.new(2012,1,1)).to eq(
|
|
416
|
-
DateTime.new(2011,1,1))
|
|
417
|
-
|
|
418
|
-
expect(@n_offset - DateTime.new(2013,1,1)).to eq(
|
|
419
|
-
DateTime.new(2011,1,1))
|
|
420
|
-
end
|
|
421
|
-
end
|
|
422
|
-
end
|
|
423
|
-
|
|
424
|
-
describe YearEnd do
|
|
425
|
-
before do
|
|
426
|
-
@offset = Offsets::YearEnd.new
|
|
427
|
-
@n_offset = Offsets::YearEnd.new(2)
|
|
428
|
-
end
|
|
429
|
-
|
|
430
|
-
context "#+" do
|
|
431
|
-
it "increases to end of same year if not on offset" do
|
|
432
|
-
expect(@offset + DateTime.new(2011,5,2,4,2)).to eq(
|
|
433
|
-
DateTime.new(2011,12,31,4,2))
|
|
434
|
-
|
|
435
|
-
expect(@n_offset + DateTime.new(2011,5,2,4,2)).to eq(
|
|
436
|
-
DateTime.new(2012,12,31,4,2))
|
|
437
|
-
end
|
|
438
|
-
|
|
439
|
-
it "increases to end of next year if on offset" do
|
|
440
|
-
expect(@offset + DateTime.new(2012,12,31,4)).to eq(
|
|
441
|
-
DateTime.new(2013,12,31,4))
|
|
442
|
-
|
|
443
|
-
expect(@n_offset + DateTime.new(2012,12,31,4)).to eq(
|
|
444
|
-
DateTime.new(2014,12,31,4))
|
|
445
|
-
end
|
|
446
|
-
end
|
|
447
|
-
|
|
448
|
-
context "#-" do
|
|
449
|
-
it "decreases to end of previous year" do
|
|
450
|
-
expect(@offset - DateTime.new(2012,2,3)).to eq(
|
|
451
|
-
DateTime.new(2011,12,31))
|
|
452
|
-
|
|
453
|
-
expect(@n_offset - DateTime.new(2011,5,6)).to eq(
|
|
454
|
-
DateTime.new(2010,12,31))
|
|
455
|
-
end
|
|
456
|
-
end
|
|
457
|
-
|
|
458
|
-
context "#on_offset?" do
|
|
459
|
-
it "reports whether on offset or not" do
|
|
460
|
-
expect(@offset.on_offset?(DateTime.new(2012,12,31))).to eq(true)
|
|
461
|
-
expect(@offset.on_offset?(DateTime.new(2012,1,1))).to eq(false)
|
|
462
|
-
end
|
|
463
|
-
end
|
|
464
|
-
end
|
|
465
|
-
end
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
require 'daru_lite/extensions/which_dsl'
|
|
2
|
-
|
|
3
|
-
describe "which DSL" do
|
|
4
|
-
before do
|
|
5
|
-
@df = DaruLite::DataFrame.new({
|
|
6
|
-
number: [1,2,3,4,5,6,Float::NAN],
|
|
7
|
-
sym: [:one, :two, :three, :four, :five, :six, :seven],
|
|
8
|
-
names: ['sameer', 'john', 'james', 'omisha', 'priyanka', 'shravan',nil]
|
|
9
|
-
})
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "accepts simple single eq statement" do
|
|
13
|
-
answer = DaruLite::DataFrame.new({
|
|
14
|
-
number: [4],
|
|
15
|
-
sym: [:four],
|
|
16
|
-
names: ['omisha']
|
|
17
|
-
}, index: DaruLite::Index.new([3])
|
|
18
|
-
)
|
|
19
|
-
expect( @df.which{ `number` == 4 } ).to eq(answer)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it "accepts somewhat complex comparison operator chaining" do
|
|
23
|
-
answer = DaruLite::DataFrame.new({
|
|
24
|
-
number: [3,4],
|
|
25
|
-
sym: [:three, :four],
|
|
26
|
-
names: ['james', 'omisha']
|
|
27
|
-
}, index: DaruLite::Index.new([2,3]))
|
|
28
|
-
expect(
|
|
29
|
-
@df.which{ (`names` == 'james') | (`sym` == :four) }
|
|
30
|
-
).to eq(answer)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "accepts vector methods" do
|
|
34
|
-
# expect( @df.which{ `number` == `number`.only_valid.max } ).to eq(@df.row_at(5)) # row_at(5) return a Vector object!?
|
|
35
|
-
expect( @df.which{ `number` <= `number`.only_valid.max } ).to eq(@df.row_at(0..5))
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
end
|