@@ -7,7 +7,7 @@ using SharedArrays: SharedArray
7
7
using Tables
8
8
import IteratorInterfaceExtensions, TableTraits
9
9
10
- function getpath (dir, file)
10
+ function getpath (dir, file)
11
11
path = joinpath (dir, file)
12
12
# println("================ $path ================")
13
13
path
@@ -59,7 +59,7 @@ Base.convert(::Type{YearStr}, v::Float64) = YearStr(string(round(Int, v)))
59
59
end
60
60
61
61
@testset " case insensitive dict" begin
62
- function testdict (lowercase_key, mixedcase_key, second_lowercase_key)
62
+ function testdict (lowercase_key, mixedcase_key, second_lowercase_key)
63
63
64
64
T = typeof (lowercase_key)
65
65
d = SASLib. CIDict {T,Int} ()
@@ -108,7 +108,7 @@ Base.convert(::Type{YearStr}, v::Float64) = YearStr(string(round(Int, v)))
108
108
109
109
@testset " read basic test files (test*.sas7bdat)" begin
110
110
dir = " data_pandas"
111
- files = filter (x -> endswith (x, " sas7bdat" ) && startswith (x, " test" ),
111
+ files = filter (x -> endswith (x, " sas7bdat" ) && startswith (x, " test" ),
112
112
Base. Filesystem. readdir (" $dir " ))
113
113
for f in files
114
114
result = readfile (dir, f)
@@ -150,7 +150,7 @@ Base.convert(::Type{YearStr}, v::Float64) = YearStr(string(round(Int, v)))
150
150
rs = readsas (fname, include_columns= [:MONTH , :YEAR ])
151
151
@test size (rs, 2 ) == 2
152
152
@test sort (names (rs)) == sort ([:MONTH , :YEAR ])
153
-
153
+
154
154
rs = readsas (fname, include_columns= [1 , 2 , 7 ])
155
155
@test size (rs, 2 ) == 3
156
156
@test sort (names (rs)) == sort ([:ACTUAL , :PREDICT , :PRODUCT ])
@@ -171,12 +171,12 @@ Base.convert(::Type{YearStr}, v::Float64) = YearStr(string(round(Int, v)))
171
171
172
172
# test bad include/exclude param
173
173
# see https://discourse.julialang.org/t/test-warn-doesnt-work-with-warn-in-0-7/9001
174
- @test_logs (:warn , " Unknown include column blah" ) (:warn ,
174
+ @test_logs (:warn , " Unknown include column blah" ) (:warn ,
175
175
" Unknown include column Year" ) readsas (fname, include_columns= [:blah , :Year ])
176
- @test_logs (:warn , " Unknown exclude column blah" ) (:warn ,
176
+ @test_logs (:warn , " Unknown exclude column blah" ) (:warn ,
177
177
" Unknown exclude column Year" ) readsas (fname, exclude_columns= [:blah , :Year ])
178
178
# error handling
179
- @test_throws SASLib. ConfigError readsas (fname,
179
+ @test_throws SASLib. ConfigError readsas (fname,
180
180
include_columns= [1 ], exclude_columns= [1 ])
181
181
end
182
182
@@ -187,8 +187,8 @@ Base.convert(::Type{YearStr}, v::Float64) = YearStr(string(round(Int, v)))
187
187
@test size (rs) == (1440 , 10 )
188
188
@test size (rs,1 ) == 1440
189
189
@test size (rs,2 ) == 10
190
- @test length (columns (rs)) == 10
191
- @test length (names (rs)) == 10
190
+ @test length (columns (rs)) == 10
191
+ @test length (names (rs)) == 10
192
192
193
193
# cell indexing
194
194
@test rs[1 ][1 ] ≈ 925.0
@@ -204,40 +204,61 @@ Base.convert(::Type{YearStr}, v::Float64) = YearStr(string(round(Int, v)))
204
204
205
205
# iteration
206
206
@test sum (r[1 ] for r in rs) ≈ 730337.0
207
-
207
+
208
208
# portion of result set
209
209
@test typeof (rs[1 : 2 ]) == SASLib. ResultSet
210
210
@test typeof (rs[:ACTUAL , :PREDICT ]) == SASLib. ResultSet
211
211
@test rs[1 : 2 ][1 ][1 ] ≈ 925.0
212
212
@test rs[:ACTUAL , :PREDICT ][1 ][1 ] ≈ 925.0
213
213
214
214
# setindex!
215
- rs[1 ,1 ] = 100.0
216
- @test rs[1 ,1 ] ≈ 100.0
217
- rs[1 ,:ACTUAL ] = 200.0
218
- @test rs[1 ,:ACTUAL ] ≈ 200.0
215
+ let rscopy = deepcopy (rs)
216
+ rs[1 ,1 ] = 100.0
217
+ @test rs[1 ,1 ] ≈ 100.0
218
+ rs[1 ,:ACTUAL ] = 200.0
219
+ @test rs[1 ,:ACTUAL ] ≈ 200.0
220
+ end
219
221
220
222
# display related
221
223
@test show (rs) == nothing
222
224
@test SASLib. sizestr (rs) == " 1440 rows x 10 columns"
223
225
224
- # Tables.jl interface - getproperty test
225
- @test rs. ACTUAL == rs[:ACTUAL ]
226
- @test names (rs) == propertynames (rs)
226
+ # Tables.jl
227
+ let twocols = rs[:ACTUAL , :PREDICT ]
228
+
229
+ # General
230
+ @test Tables. istable (typeof (rs))
231
+ @test Tables. rowaccess (typeof (rs))
232
+ @test Tables. columnaccess (typeof (rs))
233
+
234
+ # AbstractRow interface
235
+ let row = twocols[3 ] # (ACTUAL = 608.0, PREDICT = 846.0)
236
+ @test Tables. getcolumn (row, 1 ) ≈ 608.0
237
+ @test Tables. getcolumn (row, :ACTUAL ) ≈ 608.0
238
+ @test Tables. columnnames (row) === (:ACTUAL , :PREDICT )
239
+ end
227
240
228
- # Tables.jl coverage - indirect tests / usage
229
- @test Tables. schema (rs). names == Tuple (names (rs))
230
- @test Tables. schema (rs). types == Tuple (eltype .([rs[s] for s in names (rs)]))
231
- @test length (Tables. rowtable (rs)) == 1440
232
- @test length (Tables. columntable (rs)) == 10
233
- @test size (Tables. matrix (rs[:ACTUAL , :PREDICT ])) == (1440 ,2 )
241
+ # AbstractColumns interface
242
+ let tab = Tables. columns (twocols)
243
+ @test Tables. getcolumn (tab, 1 ) isa Array{Float64,1 }
244
+ @test Tables. getcolumn (tab, 1 ) |> size === (1440 ,)
245
+ @test Tables. getcolumn (tab, :ACTUAL ) isa Array{Float64,1 }
246
+ @test Tables. getcolumn (tab, :ACTUAL ) |> size === (1440 ,)
247
+ @test Tables. columnnames (tab) === propertynames (twocols)
248
+ end
234
249
235
- # Tables.jl coverage - direct tests
236
- @test Tables. istable (typeof (rs)) === true
237
- @test Tables. rowaccess (typeof (rs)) === true
238
- @test Tables. columnaccess (typeof (rs)) === true
239
- @test Tables. rows (rs) |> first |> propertynames |> Tuple == Tuple (names (rs))
240
- @test Tables. columns (rs) |> propertynames |> Tuple == Tuple (names (rs))
250
+ # Usages
251
+ @test size (Tables. matrix (twocols)) == (1440 , 2 )
252
+ end
253
+
254
+ # old tests
255
+ # @test Tables.schema(rs).names == Tuple(names(rs))
256
+ # @test Tables.schema(rs).types == Tuple(eltype.([rs[s] for s in names(rs)]))
257
+ # @test length(Tables.rowtable(rs)) == 1440
258
+ # @test length(Tables.columntable(rs)) == 10
259
+ # @test size(Tables.matrix(rs[:ACTUAL, :PREDICT])) == (1440,2)
260
+ # @test Tables.rows(rs) |> first |> propertynames |> Tuple == Tuple(names(rs))
261
+ # @test Tables.columns(rs) |> propertynames |> Tuple == Tuple(names(rs))
241
262
242
263
# Queryverse integration
243
264
@test TableTraits. isiterabletable (rs) == true
@@ -333,18 +354,18 @@ Base.convert(::Type{YearStr}, v::Float64) = YearStr(string(round(Int, v)))
333
354
end
334
355
335
356
@testset " array constructors" begin
336
-
357
+
337
358
rs = readfile (" data_AHS2013" , " homimp.sas7bdat" )
338
359
@test typeof (rs[:RAS ]) == SASLib. ObjectPool{String,UInt16}
339
360
340
361
# string_array_fn test for specific string columns
341
- rs = readfile (" data_AHS2013" , " homimp.sas7bdat" ,
362
+ rs = readfile (" data_AHS2013" , " homimp.sas7bdat" ,
342
363
string_array_fn = Dict (:RAS => REGULAR_STR_ARRAY))
343
364
@test typeof (rs[:RAS ]) == Array{String,1 }
344
365
@test typeof (rs[:RAH ]) != Array{String,1 }
345
366
346
367
# string_array_fn test for all string columns
347
- rs = readfile (" data_AHS2013" , " homimp.sas7bdat" ,
368
+ rs = readfile (" data_AHS2013" , " homimp.sas7bdat" ,
348
369
string_array_fn = Dict (:_all_ => REGULAR_STR_ARRAY))
349
370
@test typeof (rs[:RAS ]) == Array{String,1 }
350
371
@test typeof (rs[:RAH ]) == Array{String,1 }
@@ -354,13 +375,13 @@ Base.convert(::Type{YearStr}, v::Float64) = YearStr(string(round(Int, v)))
354
375
355
376
# number_array_fn test by column name
356
377
makesharedarray (n) = SharedArray {Float64} (n)
357
- rs = readfile (" data_misc" , " numeric_1000000_2.sas7bdat" ,
378
+ rs = readfile (" data_misc" , " numeric_1000000_2.sas7bdat" ,
358
379
number_array_fn = Dict (:f => makesharedarray))
359
380
@test typeof (rs[:f ]) == SharedArray{Float64,1 }
360
381
@test typeof (rs[:x ]) == Array{Float64,1 }
361
382
362
383
# number_array_fn test for all numeric columns
363
- rs = readfile (" data_misc" , " numeric_1000000_2.sas7bdat" ,
384
+ rs = readfile (" data_misc" , " numeric_1000000_2.sas7bdat" ,
364
385
number_array_fn = Dict (:_all_ => makesharedarray))
365
386
@test typeof (rs[:f ]) == SharedArray{Float64,1 }
366
387
@test typeof (rs[:x ]) == SharedArray{Float64,1 }
@@ -371,31 +392,31 @@ Base.convert(::Type{YearStr}, v::Float64) = YearStr(string(round(Int, v)))
371
392
@testset " user specified column types" begin
372
393
373
394
# normal use case
374
- rs = readfile (" data_pandas" , " productsales.sas7bdat" ;
395
+ rs = readfile (" data_pandas" , " productsales.sas7bdat" ;
375
396
verbose_level = 0 , column_types = Dict (:YEAR => Int16, :QUARTER => Int8))
376
397
@test eltype (rs[:YEAR ]) == Int16
377
398
@test eltype (rs[:QUARTER ]) == Int8
378
399
379
400
# error handling - warn() when a column cannot be converted
380
- rs = readfile (" data_pandas" , " productsales.sas7bdat" ;
401
+ rs = readfile (" data_pandas" , " productsales.sas7bdat" ;
381
402
verbose_level = 0 , column_types = Dict (:YEAR => Int8, :QUARTER => Int8))
382
403
@test eltype (rs[:YEAR ]) == Float64
383
404
@test eltype (rs[:QUARTER ]) == Int8
384
405
# TODO expect warning for :YEAR conversion
385
406
386
407
# case insensitive column symbol
387
- rs = readfile (" data_pandas" , " productsales.sas7bdat" ;
408
+ rs = readfile (" data_pandas" , " productsales.sas7bdat" ;
388
409
verbose_level = 0 , column_types = Dict (:Quarter => Int8))
389
410
@test eltype (rs[:QUARTER ]) == Int8
390
411
391
412
# conversion to custom types
392
- rs = readfile (" data_pandas" , " productsales.sas7bdat" ;
413
+ rs = readfile (" data_pandas" , " productsales.sas7bdat" ;
393
414
verbose_level = 0 , column_types = Dict (:Year => YearStr))
394
415
@test eltype (rs[:YEAR ]) == YearStr
395
416
396
417
# test Union type
397
- let T = Union{Int,Missing}
398
- rs = readfile (" data_pandas" , " productsales.sas7bdat" ;
418
+ let T = Union{Int,Missing}
419
+ rs = readfile (" data_pandas" , " productsales.sas7bdat" ;
399
420
verbose_level = 0 , column_types = Dict (:Year => T))
400
421
@test eltype (rs[:YEAR ]) == T
401
422
end
@@ -410,7 +431,7 @@ Base.convert(::Type{YearStr}, v::Float64) = YearStr(string(round(Int, v)))
410
431
@testset " just reads" begin
411
432
for dir in [" data_pandas" , " data_reikoch" , " data_AHS2013" , " data_misc" ]
412
433
for f in readdir (dir)
413
- if endswith (f, " .sas7bdat" ) &&
434
+ if endswith (f, " .sas7bdat" ) &&
414
435
! (f in [" zero_variables.sas7bdat" ])
415
436
rs = readfile (dir, f)
416
437
@test size (rs, 1 ) > 0
0 commit comments