Skip to content

Commit 2cb1399

Browse files
bkaminsnalimilan
andauthored
Update DictRows and DictColumns definition (#310)
* Update DictRows and DictColumns definition * Update Project.toml * Update runtests.jl * Update runtests.jl * Update test/runtests.jl * Update src/Tables.jl Co-authored-by: Milan Bouchet-Valat <[email protected]> * Update src/Tables.jl Co-authored-by: Milan Bouchet-Valat <[email protected]>
1 parent e48ec0d commit 2cb1399

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Tables"
22
uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
33
authors = ["quinnj <[email protected]>"]
4-
version = "1.9.0"
4+
version = "1.10.0"
55

66
[deps]
77
DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"

src/Tables.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ getcolumn(x::AbstractDict{Symbol}, nm::Symbol) = x[nm]
144144
getcolumn(x::AbstractDict{Symbol}, ::Type{T}, i::Int, nm::Symbol) where {T} = x[nm]
145145
columnnames(x::AbstractDict{Symbol}) = collect(keys(x))
146146

147-
getcolumn(x::AbstractDict{String}, i::Int) = x[String(columnnames(x)[i])]
148-
getcolumn(x::AbstractDict{String}, nm::Symbol) = x[String(nm)]
149-
getcolumn(x::AbstractDict{String}, ::Type{T}, i::Int, nm::Symbol) where {T} = x[String(nm)]
150-
columnnames(x::AbstractDict{String}) = collect(Symbol(k) for k in keys(x))
147+
getcolumn(x::AbstractDict{<:AbstractString}, i::Int) = x[String(columnnames(x)[i])]
148+
getcolumn(x::AbstractDict{<:AbstractString}, nm::Symbol) = x[String(nm)]
149+
getcolumn(x::AbstractDict{<:AbstractString}, ::Type{T}, i::Int, nm::Symbol) where {T} = x[String(nm)]
150+
columnnames(x::AbstractDict{<:AbstractString}) = collect(Symbol(k) for k in keys(x))
151151

152152
# AbstractVector of Dicts for Tables.rows
153-
const DictRows = AbstractVector{T} where {T <: Union{AbstractDict{String}, AbstractDict{Symbol}}}
153+
const DictRows = AbstractVector{T} where {T <: Union{AbstractDict{<:AbstractString}, AbstractDict{Symbol}}}
154154
isrowtable(::Type{<:DictRows}) = true
155155
# DictRows doesn't naturally lend itself to the `Tables.schema` requirement
156156
# we can't just look at the first row, because the types might change,
@@ -159,7 +159,7 @@ isrowtable(::Type{<:DictRows}) = true
159159
schema(x::DictRows) = nothing
160160

161161
# Dict of AbstractVectors for Tables.columns
162-
const DictColumns = AbstractDict{K, V} where {K <: Union{Symbol, String}, V <: AbstractVector}
162+
const DictColumns = Union{<:AbstractDict{<:AbstractString, <:AbstractVector}, <:AbstractDict{Symbol, <:AbstractVector}}
163163
istable(::Type{<:DictColumns}) = true
164164
columnaccess(::Type{<:DictColumns}) = true
165165
columns(x::DictColumns) = x

test/runtests.jl

+31
Original file line numberDiff line numberDiff line change
@@ -900,3 +900,34 @@ end
900900
@test_throws MethodError Tables.ByRow(identity)(1)
901901
@test_throws MethodError Tables.ByRow(identity)([1 2])
902902
end
903+
904+
@testset "istable on dictionaries" begin
905+
@test Tables.istable(Dict{Union{String}, Vector})
906+
@test Tables.istable(Dict{Union{Symbol}, Vector})
907+
@test Tables.istable(Dict{Union{SubString}, Vector})
908+
@test Tables.istable(Dict{Union{AbstractString}, Vector})
909+
@test !Tables.istable(Dict{Union{String, Symbol}, Vector})
910+
@test Tables.istable(Vector{Dict{Symbol}})
911+
@test Tables.istable(Vector{Dict{String}})
912+
@test Tables.istable(Vector{Dict{SubString}})
913+
@test Tables.istable(Vector{Dict{AbstractString}})
914+
915+
@test Set(Tables.columnnames(Dict(:a=>1, :b=>2))) == Set([:a, :b])
916+
@test Set(Tables.columnnames(Dict("a"=>1, "b"=>2))) == Set([:a, :b])
917+
@test Set(Tables.columnnames(Dict("a"=>1, SubString("b")=>2))) == Set([:a, :b])
918+
@test Set(Tables.columnnames(Dict(SubString("a")=>1, SubString("b")=>2))) == Set([:a, :b])
919+
920+
@test Tables.getcolumn(Dict(:a=>1, :b=>2), 1) == 1
921+
@test Tables.getcolumn(Dict("a"=>1, "b"=>2), 1 + (Int === Int64)) == 1
922+
@test Tables.getcolumn(Dict("a"=>1, SubString("b")=>2), 1 + (Int === Int64)) == 1
923+
@test Tables.getcolumn(Dict(SubString("a")=>1, SubString("b")=>2), 1 + (Int === Int64)) == 1
924+
@test Tables.getcolumn(Dict(:a=>1, :b=>2), :a) == 1
925+
@test Tables.getcolumn(Dict("a"=>1, "b"=>2), :a) == 1
926+
@test Tables.getcolumn(Dict("a"=>1, SubString("b")=>2), :a) == 1
927+
@test Tables.getcolumn(Dict(SubString("a")=>1, SubString("b")=>2), :a) == 1
928+
@test Tables.getcolumn(Dict(:a=>1, :b=>2), Int, 1, :a) == 1
929+
@test Tables.getcolumn(Dict("a"=>1, "b"=>2), Int, 1, :a) == 1
930+
@test Tables.getcolumn(Dict("a"=>1, SubString("b")=>2), Int, 1, :a) == 1
931+
@test Tables.getcolumn(Dict(SubString("a")=>1, SubString("b")=>2), Int, 1, :a) == 1
932+
end
933+

0 commit comments

Comments
 (0)