-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from tk3369/tk/user-specified-column-type
Ability to convert column to specific types given by the user
- Loading branch information
Showing
5 changed files
with
200 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Case insensitive Dict - a simple wrapper over Dict | ||
|
||
struct CIDict{K, T} | ||
|
||
dct::Dict{K, T} | ||
|
||
# type checking | ||
check(K) = K <: AbstractString || K <: Symbol || | ||
throw(ArgumentError("Key must be Symbol or String type")) | ||
|
||
# constructors | ||
CIDict{K, T}() where {K,T} = (check(K); new(Dict{K,T}())) | ||
CIDict{K, T}(d::Dict{K,T}) where {K,T} = begin | ||
check(K) | ||
d2 = Dict{K,T}() | ||
for k in keys(d) | ||
d2[lcase(k)] = d[k] | ||
end | ||
new(d2) | ||
end | ||
end | ||
|
||
lcase(s::Symbol) = Symbol(lowercase(String(s))) | ||
lcase(s::AbstractString) = lowercase(s) | ||
|
||
Base.getindex(d::CIDict, s::Symbol) = d.dct[lcase(s)] | ||
Base.getindex(d::CIDict, s::String) = d.dct[lcase(s)] | ||
|
||
Base.setindex!(d::CIDict, v, s::Symbol) = d.dct[lcase(s)] = v | ||
Base.setindex!(d::CIDict, v, s::String) = d.dct[lcase(s)] = v | ||
|
||
Base.haskey(d::CIDict, s::Symbol) = haskey(d.dct, lcase(s)) | ||
Base.haskey(d::CIDict, s::String) = haskey(d.dct, lcase(s)) | ||
|
||
Base.keys(d::CIDict) = keys(d.dct) | ||
Base.values(d::CIDict) = values(d.dct) | ||
|
||
Base.start(d::CIDict) = start(d.dct) | ||
Base.next(d::CIDict, i::Int) = next(d.dct, i) | ||
Base.done(d::CIDict, i::Int) = done(d.dct, i) | ||
|
||
Base.length(d::CIDict) = length(d.dct) | ||
|
||
issym(x) = typeof(x) == Symbol | ||
|
||
function Base.show(io::IO, d::SASLib.CIDict) | ||
print(io, "CIDict(") | ||
for (i, (k,v)) in enumerate(d.dct) | ||
i > 1 && print(io, ", ") | ||
print(io, issym(k) ? ":" : "", k, " => ", v) | ||
end | ||
print(io, ")") | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters