Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes #20

Merged
merged 4 commits into from
Jun 4, 2019
Merged
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ os:
julia:
- 1.0
- 1.1
- 1.2
- nightly
matrix:
allow_failures:
Expand Down
20 changes: 20 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name = "TableView"
uuid = "40c74d1a-b44c-5b06-a7c1-6cbea58ea978"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
JSExpr = "97c1335a-c9c5-57fe-bc5d-ec35cebe8660"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Observables = "510215fc-4207-5dde-b226-833fc4488ee2"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
WebIO = "0f1e0344-ec1d-5b48-a673-e5cf874b6c29"

[compat]
julia = "≥ 0.7.0"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
6 changes: 0 additions & 6 deletions REQUIRE

This file was deleted.

10 changes: 10 additions & 0 deletions src/TableView.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ struct IteratorAndFirst{F, T}
first = iterate(x)
return new{typeof(first), typeof(x)}(first, x, len)
end
function IteratorAndFirst(first, x)
len = Base.haslength(x) ? length(x) + 1 : 1
return new{typeof(first), typeof(x)}(first, x, len)
end
end
Base.IteratorSize(::Type{IteratorAndFirst{F, T}}) where {F, T} = Base.IteratorSize(T)
Base.length(x::IteratorAndFirst) = x.len
Expand All @@ -39,6 +43,8 @@ function Base.iterate(x::IteratorAndFirst, st)
return iterate(x.source, st)
end

showtable(table::AbstractMatrix; kwargs...) = showtable(Tables.table(table); kwargs...)

function showtable(table; dark = false, height = :auto, width = "100%")
rows = Tables.rows(table)
tablelength = Base.IteratorSize(rows) == Base.HasLength() ? length(rows) : nothing
Expand Down Expand Up @@ -171,6 +177,10 @@ function table2json(rows, names, types; requested = nothing)
print(io, ':')
if col isa Number
JSON.print(io, col)
elseif col === nothing
JSON.print(io, "nothing")
elseif col === missing
JSON.print(io, "missing")
else
JSON.print(io, sprint(print, col))
end
Expand Down
31 changes: 22 additions & 9 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
using TableView
using Test, WebIO

version = readchomp(joinpath(@__DIR__, "..", "ag-grid.version"))

@test isfile(joinpath(@__DIR__, "..", "deps", "ag-grid-$(version)", "ag-grid.js"))

nttable = [
(a = 2.0, b = 3),
(a = 3.0, b = 12)
]
@test showtable(nttable) isa WebIO.Scope
@testset "installation" begin
version = readchomp(joinpath(@__DIR__, "..", "ag-grid.version"))
@test isfile(joinpath(@__DIR__, "..", "deps", "ag-grid-$(version)", "ag-grid.js"))
end
@testset "named tuple table" begin
nttable = [
(a = 2.0, b = 3),
(a = 3.0, b = 12)
]
@test showtable(nttable) isa WebIO.Scope
end
@testset "named tuple table with missing and nothing" begin
nttable = [
(a = 2.0, b = 3, c = missing),
(a = 3.0, b = 12, c = nothing)
]
@test showtable(nttable) isa WebIO.Scope
end
@testset "normal array" begin
array = rand(10, 10)
@test showtable(array) isa WebIO.Scope
end