Skip to content

Commit 82210ef

Browse files
authored
Merge pull request #60 from tk3369/julia1-update
Removed Compat/Missings and bring code up to Julia 1.x
2 parents dc7249a + 6f47a0d commit 82210ef

File tree

5 files changed

+40
-53
lines changed

5 files changed

+40
-53
lines changed

Project.toml

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@ authors = ["Tom Kwong <tk3369@gmail.com>"]
44
version = "1.0.0"
55

66
[deps]
7-
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
8-
Missings = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"
7+
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
98
StringEncodings = "69024149-9ee7-55f6-a4c4-859efe599b68"
109
TabularDisplay = "3eeacb1d-13c2-54cc-9b18-30c86af3cadb"
1110

1211
[compat]
13-
Compat = "3.2"
14-
Missings = "0.4"
1512
StringEncodings = "0.3"
1613
TabularDisplay = "1"
1714
julia = "1"
1815

1916
[extras]
2017
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
2118
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
19+
SharedArrays = "1a1011a3-84de-559e-8e89-a11a2f7dc383"
2220
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
21+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2322

2423
[targets]
25-
test = ["Statistics", "InteractiveUtils", "Printf"]
24+
test = ["Test", "Statistics", "InteractiveUtils", "Printf", "SharedArrays"]

src/Metadata.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ function colfmt(md::Metadata)
7070
end
7171

7272
# Compact types format
73-
# e.g. (Date, Missings.Missing) => "Date/Missings.Missing"
73+
# e.g. (Date, Missing) => "Date/Missing"
7474
function typesfmt(ty::Tuple; excludemissing = false)
7575
ar = excludemissing ?
76-
collect(Iterators.filter(x -> x != Missings.Missing, ty)) : [ty...]
76+
collect(Iterators.filter(x -> x != Missing, ty)) : [ty...]
7777
join(string.(ar), "/")
7878
end
7979

@@ -88,4 +88,4 @@ function typesof(ty::Type)
8888
else
8989
(ty,)
9090
end
91-
end
91+
end

src/SASLib.jl

+15-17
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
VERSION < v"0.7-" && __precompile__()
2-
31
module SASLib
42

5-
using StringEncodings, Missings, Compat.Dates, Compat.Distributed, Compat
3+
using StringEncodings
64
using TabularDisplay
5+
using Dates
76

87
export readsas, REGULAR_STR_ARRAY
98

@@ -66,8 +65,7 @@ read the entire file content. When called again, fetch the next `nrows` rows.
6665
function read(handler::Handler, nrows=0)
6766
# println("Reading $(handler.config.filename)")
6867
elapsed = @elapsed result = read_chunk(handler, nrows)
69-
# TODO base keyword arg should not be needed due to Compat.jl issue #567
70-
elapsed = Compat.round(elapsed; digits = 5, base = 10)
68+
elapsed = round(elapsed, digits = 5)
7169
println1(handler, "Read $(handler.config.filename) with size $(size(result, 1)) x $(size(result, 2)) in $elapsed seconds")
7270
return result
7371
end
@@ -186,7 +184,7 @@ end
186184
return handler.cached_page[offset+1:offset+len] #offset is 0-based
187185
# => too conservative.... we expect cached_page to be filled before this function is called
188186
# if handler.cached_page == []
189-
# Compat.@warn("_read_byte function going to disk")
187+
# @warn("_read_byte function going to disk")
190188
# seek(handler.io, offset)
191189
# try
192190
# return Base.read(handler.io, len)
@@ -275,14 +273,14 @@ function read_header(handler)
275273
else
276274
handler.file_encoding = FALLBACK_ENCODING # hope for the best
277275
handler.config.verbose_level > 0 &&
278-
Compat.@warn("Unknown file encoding value ($buf), defaulting to $(handler.file_encoding)")
276+
@warn("Unknown file encoding value ($buf), defaulting to $(handler.file_encoding)")
279277
end
280278
#println2(handler, "file_encoding = $(handler.file_encoding)")
281279

282280
# User override for encoding
283281
if handler.config.encoding != ""
284282
handler.config.verbose_level > 0 &&
285-
Compat.@warn("Encoding has been overridden from $(handler.file_encoding) to $(handler.config.encoding)")
283+
@warn("Encoding has been overridden from $(handler.file_encoding) to $(handler.config.encoding)")
286284
handler.file_encoding = handler.config.encoding
287285
end
288286
# println2(handler, "Final encoding = $(handler.file_encoding)")
@@ -405,7 +403,7 @@ function check_user_column_types(handler)
405403
# check column_types
406404
for k in keys(handler.config.column_types)
407405
if !case_insensitive_in(k, handler.column_symbols)
408-
Compat.@warn("Unknown column symbol ($k) in column_types. Ignored.")
406+
@warn("Unknown column symbol ($k) in column_types. Ignored.")
409407
end
410408
end
411409
end
@@ -613,7 +611,7 @@ function _process_columnsize_subheader(handler, offset, length)
613611
offset += int_len
614612
handler.column_count = _read_int(handler, offset, int_len)
615613
if (handler.col_count_p1 + handler.col_count_p2 != handler.column_count)
616-
Compat.@warn("Warning: column count mismatch ($(handler.col_count_p1) + $(handler.col_count_p2) != $(handler.column_count))")
614+
@warn("Warning: column count mismatch ($(handler.col_count_p1) + $(handler.col_count_p2) != $(handler.column_count))")
617615
end
618616
end
619617

@@ -833,13 +831,13 @@ end
833831
function read_chunk(handler, nrows=0)
834832

835833
if !isdefined(handler, :column_types)
836-
Compat.@warn("No columns to parse from file")
834+
@warn("No columns to parse from file")
837835
return ResultSet()
838836
end
839837
# println("column_types = $(handler.column_types)")
840838

841839
if handler.row_count == 0
842-
Compat.@warn("File has no data")
840+
@warn("File has no data")
843841
return ResultSet()
844842
end
845843

@@ -971,7 +969,7 @@ end
971969

972970
# convert Float64 value into Date object
973971
function date_from_float(x::Vector{Float64})
974-
@compat v = Vector{Union{Date, Missing}}(undef, length(x))
972+
v = Vector{Union{Date, Missing}}(undef, length(x))
975973
for i in 1:length(x)
976974
v[i] = isnan(x[i]) ? missing : (sas_date_origin + Dates.Day(round(Int64, x[i])))
977975
end
@@ -980,7 +978,7 @@ end
980978

981979
# convert Float64 value into DateTime object
982980
function datetime_from_float(x::Vector{Float64})
983-
@compat v = Vector{Union{DateTime, Missing}}(undef, length(x))
981+
v = Vector{Union{DateTime, Missing}}(undef, length(x))
984982
for i in 1:length(x)
985983
v[i] = isnan(x[i]) ? missing : (sas_datetime_origin + Dates.Second(round(Int64, x[i])))
986984
end
@@ -1040,7 +1038,7 @@ function convert_column_type_if_needed!(handler, rslt, name)
10401038
try
10411039
rslt[name] = convert(Vector{type_wanted}, rslt[name])
10421040
catch ex
1043-
Compat.@warn("Unable to convert column to type $type_wanted, error=$ex")
1041+
@warn("Unable to convert column to type $type_wanted, error=$ex")
10441042
end
10451043
end
10461044
end
@@ -1587,13 +1585,13 @@ function populate_column_indices(handler)
15871585
if inflag && length(processed) != length(handler.config.include_columns)
15881586
diff = setdiff(handler.config.include_columns, processed)
15891587
for c in diff
1590-
Compat.@warn("Unknown include column $c")
1588+
@warn("Unknown include column $c")
15911589
end
15921590
end
15931591
if exflag && length(processed) != length(handler.config.exclude_columns)
15941592
diff = setdiff(handler.config.exclude_columns, processed)
15951593
for c in diff
1596-
Compat.@warn("Unknown exclude column $c")
1594+
@warn("Unknown exclude column $c")
15971595
end
15981596
end
15991597
# println2(handler, "column_indices = $(handler.column_indices)")

src/constants.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,6 @@ const VENDOR_SAS = 0x01
213213
const FALLBACK_ENCODING = "UTF-8"
214214
const ENCODINGS_OK_WITH_BASE_TRANSCODER = [ "UTF-8" , "US-ASCII" ]
215215

216-
@compat const REGULAR_STR_ARRAY(n) = Array{String}(undef, n)
216+
const REGULAR_STR_ARRAY(n) = Array{String}(undef, n)
217217
const EMPTY_STRING = ""
218218

test/runtests.jl

+17-27
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using SASLib, Missings
2-
using Compat.Test, Compat.Dates, Compat.Distributed, Compat.SharedArrays, Compat
1+
using Test
2+
using SASLib
33

4-
@static if VERSION > v"0.7-"
5-
import Statistics: mean
6-
end
4+
using Dates
5+
using Statistics: mean
6+
using SharedArrays: SharedArray
77

88
function getpath(dir, file)
99
path = joinpath(dir, file)
@@ -28,7 +28,7 @@ Base.convert(::Type{YearStr}, v::Float64) = YearStr(string(round(Int, v)))
2828
x = SASLib.ObjectPool{String, UInt8}(default, 5)
2929
@test length(x) == 5
3030
@test size(x) == (5, )
31-
@test @compat lastindex(x) == 5
31+
@test lastindex(x) == 5
3232
@test count(v -> v == default, x) == 5
3333
@test count(v -> v === default, x) == 5
3434
@test map(v -> "x$v", x) == [ "x", "x", "x", "x", "x" ]
@@ -169,15 +169,10 @@ Base.convert(::Type{YearStr}, v::Float64) = YearStr(string(round(Int, v)))
169169

170170
# test bad include/exclude param
171171
# see https://discourse.julialang.org/t/test-warn-doesnt-work-with-warn-in-0-7/9001
172-
@static if VERSION > v"0.7-"
173-
Compat.Test.@test_logs (:warn, "Unknown include column blah") (:warn,
174-
"Unknown include column Year") readsas(fname, include_columns=[:blah, :Year])
175-
Compat.Test.@test_logs (:warn, "Unknown exclude column blah") (:warn,
176-
"Unknown exclude column Year") readsas(fname, exclude_columns=[:blah, :Year])
177-
else
178-
@test_warn "Unknown include column" readsas(fname, include_columns=[:blah, :Year])
179-
@test_warn "Unknown exclude column" readsas(fname, exclude_columns=[:blah, :Year])
180-
end
172+
@test_logs (:warn, "Unknown include column blah") (:warn,
173+
"Unknown include column Year") readsas(fname, include_columns=[:blah, :Year])
174+
@test_logs (:warn, "Unknown exclude column blah") (:warn,
175+
"Unknown exclude column Year") readsas(fname, exclude_columns=[:blah, :Year])
181176
# error handling
182177
@test_throws SASLib.ConfigError readsas(fname,
183178
include_columns=[1], exclude_columns=[1])
@@ -240,24 +235,19 @@ Base.convert(::Type{YearStr}, v::Float64) = YearStr(string(round(Int, v)))
240235
@test show(md) == nothing
241236
println()
242237

243-
# Deal with v0.6/v0.7 difference
244-
# v0.6 shows Missings.Missing
245-
# v0.7 shows Missing
246-
ty(x) = replace(x, "Missings." => "")
247-
248238
# convenient comparison routine since v0.6/v0.7 displays different order
249-
same(x,y) = sort(ty.(string.(collect(x)))) == sort(ty.(string.(collect(y))))
239+
same(x,y) = sort(string.(collect(x))) == sort(string.(collect(y)))
250240

251241
@test same(SASLib.typesof(Int64), (Int64,))
252242
@test same(SASLib.typesof(Union{Int64,Int32}), (Int64,Int32))
253-
@test same(SASLib.typesof(Union{Int64,Int32,Missings.Missing}),
254-
(Int64,Int32,Missings.Missing))
243+
@test same(SASLib.typesof(Union{Int64,Int32,Missing}),
244+
(Int64,Int32,Missing))
255245

256246
@test SASLib.typesfmt((Int64,)) == "Int64"
257247
@test SASLib.typesfmt((Int64,Int32)) == "Int64/Int32"
258-
@test ty(SASLib.typesfmt((Int64,Int32,Missings.Missing))) == "Int64/Int32/Missing"
248+
@test SASLib.typesfmt((Int64,Int32,Missing)) == "Int64/Int32/Missing"
259249
@test SASLib.typesfmt((Int64,Int32); excludemissing=true) == "Int64/Int32"
260-
@test SASLib.typesfmt((Int64,Int32,Missings.Missing); excludemissing=true) == "Int64/Int32"
250+
@test SASLib.typesfmt((Int64,Int32,Missing); excludemissing=true) == "Int64/Int32"
261251
@test SASLib.colfmt(md)[1] == "ACTUAL(Float64)"
262252
end
263253

@@ -402,8 +392,8 @@ Base.convert(::Type{YearStr}, v::Float64) = YearStr(string(round(Int, v)))
402392
end
403393
end
404394

405-
@testset "exception" begin
395+
@testset "exception" begin
406396
@test_throws SASLib.FileFormatError readsas("runtests.jl")
407-
end
397+
end
408398

409399
end

0 commit comments

Comments
 (0)