Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Documenter, QueryTables

makedocs(
modules = [QueryTables],
sitename = "QueryTables.jl",
modules=[QueryTables],
sitename="QueryTables.jl",
analytics="UA-132838790-1",
pages = [
pages=[
"Introduction" => "index.md"
]
)

deploydocs(
repo = "github.com/queryverse/QueryTables.jl.git"
repo="github.com/queryverse/QueryTables.jl.git"
)
10 changes: 5 additions & 5 deletions src/QueryTables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ using DataValues

export DataTable, NA, isna

struct DataTable{T, TCOLS} <: AbstractVector{T}
struct DataTable{T,TCOLS} <: AbstractVector{T}
columns::TCOLS
end

function fromNT(nt)
nt = map(i->i isa ReadOnlyArrays.ReadOnlyArray ? i : ReadOnlyArrays.ReadOnlyArray(i), nt)
nt = map(i -> i isa ReadOnlyArrays.ReadOnlyArray ? i : ReadOnlyArrays.ReadOnlyArray(i), nt)
tx = typeof(nt)
et = NamedTuple{propertynames(nt), Tuple{(eltype(fieldtype(tx, i)) for i in 1:fieldcount(typeof(nt)))...}}
return DataTable{et, typeof(nt)}(nt)
et = NamedTuple{propertynames(nt),Tuple{(eltype(fieldtype(tx, i)) for i in 1:fieldcount(typeof(nt)))...}}
return DataTable{et,typeof(nt)}(nt)
end

swap_dva_in(A) = A
Expand All @@ -40,7 +40,7 @@ Base.IndexStyle(::Type{DataTable}) = Base.IndexLinear()

function Base.checkbounds(::Type{Bool}, dt::DataTable, i)
cols = columns(dt)
if length(cols)==0
if length(cols) == 0
return true
else
return checkbounds(Bool, cols[1], i)
Expand Down
42 changes: 21 additions & 21 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,43 @@ using Test

@testset "QueryTables" begin

dt1 = DataTable(a=[1,2,3], b=[4.,5.,6.], c=["John", "Sally", "Jim"])
dt1 = DataTable(a=[1,2,3], b=[4.,5.,6.], c=["John", "Sally", "Jim"])

@testset "Core" begin
@testset "Core" begin

@test length(dt1) == 3
@test dt1.a == [1,2,3]
@test dt1.b == [4.,5.,6.]
@test dt1.c == ["John", "Sally", "Jim"]
@test dt1[1] == (a=1, b=4., c="John")
@test dt1[2] == (a=2, b=5., c="Sally")
@test dt1[3] == (a=3, b=6., c="Jim")
@test length(dt1) == 3
@test dt1.a == [1,2,3]
@test dt1.b == [4.,5.,6.]
@test dt1.c == ["John", "Sally", "Jim"]
@test dt1[1] == (a = 1, b = 4., c = "John")
@test dt1[2] == (a = 2, b = 5., c = "Sally")
@test dt1[3] == (a = 3, b = 6., c = "Jim")

@test collect(dt1) == [(a=1, b=4., c="John"), (a=2, b=5., c="Sally"), (a=3, b=6., c="Jim")]
@test collect(dt1) == [(a = 1, b = 4., c = "John"), (a = 2, b = 5., c = "Sally"), (a = 3, b = 6., c = "Jim")]

dt2 = DataTable([(a=1, b=4., c="John"), (a=2, b=5., c="Sally"), (a=3, b=6., c="Jim")])
dt2 = DataTable([(a = 1, b = 4., c = "John"), (a = 2, b = 5., c = "Sally"), (a = 3, b = 6., c = "Jim")])

@test dt1 == dt2
@test dt1 == dt2

end
end

@testset "show" begin
@testset "show" begin

@test sprint(show, dt1) ==
@test sprint(show, dt1) ==
"3x3 DataTable\na │ b │ c \n──┼─────┼──────\n1 │ 4.0 │ John \n2 │ 5.0 │ Sally\n3 │ 6.0 │ Jim "

@test sprint((stream,data)->show(stream, "text/plain", data), dt1) ==
@test sprint((stream, data) -> show(stream, "text/plain", data), dt1) ==
"3x3 DataTable\na │ b │ c \n──┼─────┼──────\n1 │ 4.0 │ John \n2 │ 5.0 │ Sally\n3 │ 6.0 │ Jim "

@test sprint((stream,data)->show(stream, "text/html", data), dt1) ==
@test sprint((stream, data) -> show(stream, "text/html", data), dt1) ==
"<table><thead><tr><th>a</th><th>b</th><th>c</th></tr></thead><tbody><tr><td>1</td><td>4.0</td><td>&quot;John&quot;</td></tr><tr><td>2</td><td>5.0</td><td>&quot;Sally&quot;</td></tr><tr><td>3</td><td>6.0</td><td>&quot;Jim&quot;</td></tr></tbody></table>"

@test sprint((stream,data)->show(stream, "application/vnd.dataresource+json", data), dt1) ==
@test sprint((stream, data) -> show(stream, "application/vnd.dataresource+json", data), dt1) ==
"{\"schema\":{\"fields\":[{\"name\":\"a\",\"type\":\"integer\"},{\"name\":\"b\",\"type\":\"number\"},{\"name\":\"c\",\"type\":\"string\"}]},\"data\":[{\"a\":1,\"b\":4.0,\"c\":\"John\"},{\"a\":2,\"b\":5.0,\"c\":\"Sally\"},{\"a\":3,\"b\":6.0,\"c\":\"Jim\"}]}"

@test showable("text/html", dt1) == true
@test showable("application/vnd.dataresource+json", dt1) == true
@test showable("text/html", dt1) == true
@test showable("application/vnd.dataresource+json", dt1) == true

end
end

end