red-arrow 0.15.1 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/test-array.rb CHANGED
@@ -63,5 +63,107 @@ class ArrayTest < Test::Unit::TestCase
63
63
  end
64
64
  end
65
65
  end
66
+
67
+ sub_test_case("#cast") do
68
+ test("Symbol") do
69
+ assert_equal(Arrow::Int32Array.new([1, 2, 3]),
70
+ Arrow::StringArray.new(["1", "2", "3"]).cast(:int32))
71
+ end
72
+ end
73
+ end
74
+
75
+ sub_test_case("#filter") do
76
+ def setup
77
+ values = [true, false, false, true]
78
+ @array = Arrow::BooleanArray.new(values)
79
+ end
80
+
81
+ test("Array: boolean") do
82
+ filter = [nil, true, true, false]
83
+ filtered_array = Arrow::BooleanArray.new([nil, false, false])
84
+ assert_equal(filtered_array,
85
+ @array.filter(filter))
86
+ end
87
+
88
+ test("Arrow::BooleanArray") do
89
+ filter = Arrow::BooleanArray.new([nil, true, true, false])
90
+ filtered_array = Arrow::BooleanArray.new([nil, false, false])
91
+ assert_equal(filtered_array,
92
+ @array.filter(filter))
93
+ end
94
+
95
+ test("Arrow::ChunkedArray") do
96
+ chunks = [
97
+ Arrow::BooleanArray.new([nil, true]),
98
+ Arrow::BooleanArray.new([true, false]),
99
+ ]
100
+ filter = Arrow::ChunkedArray.new(chunks)
101
+ filtered_array = Arrow::BooleanArray.new([nil, false, false])
102
+ assert_equal(filtered_array,
103
+ @array.filter(filter))
104
+ end
105
+ end
106
+
107
+ sub_test_case("#take") do
108
+ def setup
109
+ values = [1, 0 ,2]
110
+ @array = Arrow::Int16Array.new(values)
111
+ end
112
+
113
+ test("Arrow: boolean") do
114
+ indices = [1, 0, 2]
115
+ assert_equal(Arrow::Int16Array.new([0, 1, 2]),
116
+ @array.take(indices))
117
+ end
118
+
119
+ test("Arrow::Array") do
120
+ indices = Arrow::Int16Array.new([1, 0, 2])
121
+ assert_equal(Arrow::Int16Array.new([0, 1, 2]),
122
+ @array.take(indices))
123
+ end
124
+
125
+ test("Arrow::ChunkedArray") do
126
+ taken_chunks = [
127
+ Arrow::Int16Array.new([0, 1]),
128
+ Arrow::Int16Array.new([2])
129
+ ]
130
+ taken_chunked_array = Arrow::ChunkedArray.new(taken_chunks)
131
+ indices_chunks = [
132
+ Arrow::Int16Array.new([1, 0]),
133
+ Arrow::Int16Array.new([2])
134
+ ]
135
+ indices = Arrow::ChunkedArray.new(indices_chunks)
136
+ assert_equal(taken_chunked_array,
137
+ @array.take(indices))
138
+ end
139
+ end
140
+
141
+ sub_test_case("#is_in") do
142
+ def setup
143
+ values = [1, 0, 1, 2]
144
+ @array = Arrow::Int16Array.new(values)
145
+ end
146
+
147
+ test("Arrow: Array") do
148
+ right = [2, 0]
149
+ assert_equal(Arrow::BooleanArray.new([false, true, false, true]),
150
+ @array.is_in(right))
151
+ end
152
+
153
+ test("Arrow::Array") do
154
+ right = Arrow::Int16Array.new([2, 0])
155
+ assert_equal(Arrow::BooleanArray.new([false, true, false, true]),
156
+ @array.is_in(right))
157
+ end
158
+
159
+ test("Arrow::ChunkedArray") do
160
+ chunks = [
161
+ Arrow::Int16Array.new([1, 0]),
162
+ Arrow::Int16Array.new([1, 0, 3])
163
+ ]
164
+ right = Arrow::ChunkedArray.new(chunks)
165
+ assert_equal(Arrow::BooleanArray.new([true, true, true, false]),
166
+ @array.is_in(right))
167
+ end
66
168
  end
67
169
  end
@@ -84,4 +84,98 @@ class ChunkedArrayTest < Test::Unit::TestCase
84
84
  end
85
85
  end
86
86
  end
87
+
88
+ sub_test_case("#filter") do
89
+ def setup
90
+ arrays = [
91
+ Arrow::BooleanArray.new([false, true]),
92
+ Arrow::BooleanArray.new([false, true, false]),
93
+ ]
94
+ @chunked_array = Arrow::ChunkedArray.new(arrays)
95
+ end
96
+
97
+ test("Array: boolean") do
98
+ filter = [nil, true, true, false, true]
99
+ chunks = [
100
+ Arrow::BooleanArray.new([nil, true]),
101
+ Arrow::BooleanArray.new([false, false]),
102
+ ]
103
+ filtered_chunked_array = Arrow::ChunkedArray.new(chunks)
104
+ assert_equal(filtered_chunked_array,
105
+ @chunked_array.filter(filter))
106
+ end
107
+
108
+ test("Arrow::BooleanArray") do
109
+ filter = Arrow::BooleanArray.new([nil, true, true, false, true])
110
+ chunks = [
111
+ Arrow::BooleanArray.new([nil, true]),
112
+ Arrow::BooleanArray.new([false, false]),
113
+ ]
114
+ filtered_chunked_array = Arrow::ChunkedArray.new(chunks)
115
+ assert_equal(filtered_chunked_array,
116
+ @chunked_array.filter(filter))
117
+ end
118
+
119
+ test("Arrow::ChunkedArray") do
120
+ chunks = [
121
+ Arrow::BooleanArray.new([nil, true]),
122
+ Arrow::BooleanArray.new([true, false, true]),
123
+ ]
124
+ filter = Arrow::ChunkedArray.new(chunks)
125
+ filtered_chunks = [
126
+ Arrow::BooleanArray.new([nil, true]),
127
+ Arrow::BooleanArray.new([false, false]),
128
+ ]
129
+ filtered_chunked_array = Arrow::ChunkedArray.new(filtered_chunks)
130
+ assert_equal(filtered_chunked_array,
131
+ @chunked_array.filter(filter))
132
+ end
133
+ end
134
+
135
+ sub_test_case("#take") do
136
+ def setup
137
+ chunks = [
138
+ Arrow::Int16Array.new([1, 0]),
139
+ Arrow::Int16Array.new([2]),
140
+ ]
141
+ @chunked_array = Arrow::ChunkedArray.new(chunks)
142
+ end
143
+
144
+ test("Arrow: boolean") do
145
+ chunks = [
146
+ Arrow::Int16Array.new([0, 1]),
147
+ Arrow::Int16Array.new([2])
148
+ ]
149
+ taken_chunked_array = Arrow::ChunkedArray.new(chunks)
150
+ indices = [1, 0, 2]
151
+ assert_equal(taken_chunked_array,
152
+ @chunked_array.take(indices))
153
+ end
154
+
155
+ test("Arrow::Array") do
156
+ chunks = [
157
+ Arrow::Int16Array.new([0, 1]),
158
+ Arrow::Int16Array.new([2])
159
+ ]
160
+ taken_chunked_array = Arrow::ChunkedArray.new(chunks)
161
+ indices = Arrow::Int16Array.new([1, 0, 2])
162
+ assert_equal(taken_chunked_array,
163
+ @chunked_array.take(indices))
164
+ end
165
+
166
+ test("Arrow::ChunkedArray") do
167
+ taken_chunks = [
168
+ Arrow::Int16Array.new([0, 1]),
169
+ Arrow::Int16Array.new([2])
170
+ ]
171
+ taken_chunked_array = Arrow::ChunkedArray.new(taken_chunks)
172
+ indices_chunks = [
173
+ Arrow::Int16Array.new([1, 0]),
174
+ Arrow::Int16Array.new([2])
175
+ ]
176
+ indices = Arrow::ChunkedArray.new(indices_chunks)
177
+ assert_equal(taken_chunked_array,
178
+ @chunked_array.take(indices))
179
+ end
180
+ end
87
181
  end
@@ -117,8 +117,8 @@ class CSVLoaderTest < Test::Unit::TestCase
117
117
  end
118
118
 
119
119
  sub_test_case("CSVReader") do
120
- def load_csv(data, options)
121
- Arrow::CSVLoader.load(data, options)
120
+ def load_csv(data, **options)
121
+ Arrow::CSVLoader.load(data, **options)
122
122
  end
123
123
 
124
124
  sub_test_case(":headers") do
@@ -48,6 +48,17 @@ class DataTypeTest < Test::Unit::TestCase
48
48
  assert_equal(Arrow::FixedSizeBinaryDataType.new(10),
49
49
  Arrow::DataType.resolve([:fixed_size_binary, 10]))
50
50
  end
51
+
52
+ test("abstract") do
53
+ message =
54
+ "abstract type: <:floating_point>: " +
55
+ "use one of not abstract type: [" +
56
+ "Arrow::DoubleDataType, " +
57
+ "Arrow::FloatDataType]"
58
+ assert_raise(ArgumentError.new(message)) do
59
+ Arrow::DataType.resolve(:floating_point)
60
+ end
61
+ end
51
62
  end
52
63
 
53
64
  sub_test_case("instance methods") do
@@ -23,7 +23,7 @@ class ListDataTypeTest < Test::Unit::TestCase
23
23
  Arrow::ListDataType.new(field).to_s)
24
24
  end
25
25
 
26
- test("Hash") do
26
+ test("name: String") do
27
27
  assert_equal("list<tag: string>",
28
28
  Arrow::ListDataType.new(name: "tag", type: :string).to_s)
29
29
  end
@@ -39,5 +39,31 @@ class ListDataTypeTest < Test::Unit::TestCase
39
39
  assert_equal("list<tag: string>",
40
40
  Arrow::ListDataType.new(field: field_description).to_s)
41
41
  end
42
+
43
+ test("Arrow::DataType") do
44
+ data_type = Arrow::BooleanDataType.new
45
+ assert_equal("list<item: bool>",
46
+ Arrow::ListDataType.new(data_type).to_s)
47
+ end
48
+
49
+ test("String") do
50
+ assert_equal("list<item: bool>",
51
+ Arrow::ListDataType.new("boolean").to_s)
52
+ end
53
+
54
+ test("Symbol") do
55
+ assert_equal("list<item: bool>",
56
+ Arrow::ListDataType.new(:boolean).to_s)
57
+ end
58
+
59
+ test("[data type name, additional information]") do
60
+ assert_equal("list<item: time32[ms]>",
61
+ Arrow::ListDataType.new([:time32, :milli]).to_s)
62
+ end
63
+
64
+ test("type: Symbol") do
65
+ assert_equal("list<item: bool>",
66
+ Arrow::ListDataType.new(type: :boolean).to_s)
67
+ end
42
68
  end
43
69
  end
@@ -0,0 +1,23 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ class NullArrayTest < Test::Unit::TestCase
19
+ test("#[]") do
20
+ array = Arrow::NullArray.new(1)
21
+ assert_nil(array[0])
22
+ end
23
+ end
data/test/test-slicer.rb CHANGED
@@ -46,10 +46,14 @@ class SlicerTest < Test::Unit::TestCase
46
46
  end
47
47
  assert_equal(<<-TABLE, sliced_table.to_s)
48
48
  count visible
49
- 0 1 true
50
- 1 8 true
51
- 2 16 true
52
- 3 256 true
49
+ 0
50
+ 1 1 true
51
+ 2
52
+ 3 8 true
53
+ 4 16 true
54
+ 5
55
+ 6
56
+ 7 256 true
53
57
  TABLE
54
58
  end
55
59
 
@@ -66,7 +70,8 @@ class SlicerTest < Test::Unit::TestCase
66
70
  4 16 true
67
71
  5 32 false
68
72
  6 64
69
- 7 256 true
73
+ 7
74
+ 8 256 true
70
75
  TABLE
71
76
  end
72
77
  end
@@ -78,8 +83,12 @@ class SlicerTest < Test::Unit::TestCase
78
83
  end
79
84
  assert_equal(<<-TABLE, sliced_table.to_s)
80
85
  count visible
81
- 0 2 false
82
- 1 32 false
86
+ 0
87
+ 1 2 false
88
+ 2
89
+ 3 32 false
90
+ 4
91
+ 5
83
92
  TABLE
84
93
  end
85
94
 
@@ -90,6 +99,7 @@ class SlicerTest < Test::Unit::TestCase
90
99
  assert_equal(<<-TABLE, sliced_table.to_s)
91
100
  count visible
92
101
  0 0
102
+ 1
93
103
  TABLE
94
104
  end
95
105
  end
@@ -142,10 +152,14 @@ class SlicerTest < Test::Unit::TestCase
142
152
  end
143
153
  assert_equal(<<-TABLE, sliced_table.to_s)
144
154
  count visible
145
- 0 1 true
146
- 1 8 true
147
- 2 16 true
148
- 3 256 true
155
+ 0
156
+ 1 1 true
157
+ 2
158
+ 3 8 true
159
+ 4 16 true
160
+ 5
161
+ 6
162
+ 7 256 true
149
163
  TABLE
150
164
  end
151
165
  end
@@ -172,8 +186,12 @@ class SlicerTest < Test::Unit::TestCase
172
186
  end
173
187
  assert_equal(<<-TABLE, sliced_table.to_s)
174
188
  count visible
175
- 0 2 false
176
- 1 32 false
189
+ 0
190
+ 1 2 false
191
+ 2
192
+ 3 32 false
193
+ 4
194
+ 5
177
195
  TABLE
178
196
  end
179
197
  end
@@ -200,8 +218,12 @@ class SlicerTest < Test::Unit::TestCase
200
218
  end
201
219
  assert_equal(<<-TABLE, sliced_table.to_s)
202
220
  count visible
203
- 0 2 false
204
- 1 32 false
221
+ 0
222
+ 1 2 false
223
+ 2
224
+ 3 32 false
225
+ 4
226
+ 5
205
227
  TABLE
206
228
  end
207
229
  end
@@ -217,6 +239,7 @@ class SlicerTest < Test::Unit::TestCase
217
239
  2 2 false
218
240
  3 4
219
241
  4 8 true
242
+ 5
220
243
  TABLE
221
244
  end
222
245
 
@@ -229,7 +252,8 @@ class SlicerTest < Test::Unit::TestCase
229
252
  0 16 true
230
253
  1 32 false
231
254
  2 64
232
- 3 256 true
255
+ 3
256
+ 4 256 true
233
257
  TABLE
234
258
  end
235
259
 
@@ -245,6 +269,7 @@ class SlicerTest < Test::Unit::TestCase
245
269
  3 4
246
270
  4 8 true
247
271
  5 16 true
272
+ 6
248
273
  TABLE
249
274
  end
250
275
 
@@ -256,7 +281,8 @@ class SlicerTest < Test::Unit::TestCase
256
281
  count visible
257
282
  0 32 false
258
283
  1 64
259
- 2 256 true
284
+ 2
285
+ 3 256 true
260
286
  TABLE
261
287
  end
262
288
 
@@ -268,7 +294,8 @@ class SlicerTest < Test::Unit::TestCase
268
294
  count visible
269
295
  0 32 false
270
296
  1 64
271
- 2 256 true
297
+ 2
298
+ 3 256 true
272
299
  TABLE
273
300
  end
274
301
 
@@ -284,6 +311,7 @@ class SlicerTest < Test::Unit::TestCase
284
311
  3 4
285
312
  4 8 true
286
313
  5 16 true
314
+ 6
287
315
  TABLE
288
316
  end
289
317
 
@@ -296,7 +324,8 @@ class SlicerTest < Test::Unit::TestCase
296
324
  0 16 true
297
325
  1 32 false
298
326
  2 64
299
- 3 256 true
327
+ 3
328
+ 4 256 true
300
329
  TABLE
301
330
  end
302
331
 
@@ -311,6 +340,7 @@ class SlicerTest < Test::Unit::TestCase
311
340
  2 2 false
312
341
  3 4
313
342
  4 8 true
343
+ 5
314
344
  TABLE
315
345
  end
316
346
 
@@ -324,6 +354,7 @@ class SlicerTest < Test::Unit::TestCase
324
354
  1 4
325
355
  2 16 true
326
356
  3 64
357
+ 4
327
358
  TABLE
328
359
  end
329
360
 
@@ -337,7 +368,8 @@ class SlicerTest < Test::Unit::TestCase
337
368
  1 2 false
338
369
  2 8 true
339
370
  3 32 false
340
- 4 256 true
371
+ 4
372
+ 5 256 true
341
373
  TABLE
342
374
  end
343
375
 
@@ -347,8 +379,12 @@ class SlicerTest < Test::Unit::TestCase
347
379
  end
348
380
  assert_equal(<<-TABLE, sliced_table.to_s)
349
381
  count visible
350
- 0 16 true
351
- 1 256 true
382
+ 0
383
+ 1
384
+ 2 16 true
385
+ 3
386
+ 4
387
+ 5 256 true
352
388
  TABLE
353
389
  end
354
390
 
@@ -358,11 +394,15 @@ class SlicerTest < Test::Unit::TestCase
358
394
  end
359
395
  assert_equal(<<-TABLE, sliced_table.to_s)
360
396
  count visible
361
- 0 1 true
362
- 1 8 true
363
- 2 16 true
364
- 3 32 false
365
- 4 256 true
397
+ 0
398
+ 1 1 true
399
+ 2
400
+ 3 8 true
401
+ 4 16 true
402
+ 5 32 false
403
+ 6
404
+ 7
405
+ 8 256 true
366
406
  TABLE
367
407
  end
368
408
 
@@ -372,9 +412,13 @@ class SlicerTest < Test::Unit::TestCase
372
412
  end
373
413
  assert_equal(<<-TABLE, sliced_table.to_s)
374
414
  count visible
375
- 0 1 true
376
- 1 8 true
377
- 2 32 false
415
+ 0
416
+ 1 1 true
417
+ 2
418
+ 3 8 true
419
+ 4 32 false
420
+ 5
421
+ 6
378
422
  TABLE
379
423
  end
380
424