Skip to content

Commit 888ce65

Browse files
authored
Merge pull request #20 from JuliaComputing/sp/nothingmissing
Various fixes
2 parents 7633909 + aac8671 commit 888ce65

File tree

5 files changed

+53
-15
lines changed

5 files changed

+53
-15
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ os:
55
julia:
66
- 1.0
77
- 1.1
8+
- 1.2
89
- nightly
910
matrix:
1011
allow_failures:

Project.toml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name = "TableView"
2+
uuid = "40c74d1a-b44c-5b06-a7c1-6cbea58ea978"
3+
4+
[deps]
5+
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
6+
JSExpr = "97c1335a-c9c5-57fe-bc5d-ec35cebe8660"
7+
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
8+
Observables = "510215fc-4207-5dde-b226-833fc4488ee2"
9+
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
10+
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
11+
WebIO = "0f1e0344-ec1d-5b48-a673-e5cf874b6c29"
12+
13+
[compat]
14+
julia = "≥ 0.7.0"
15+
16+
[extras]
17+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
18+
19+
[targets]
20+
test = ["Test"]

REQUIRE

-6
This file was deleted.

src/TableView.jl

+10
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ struct IteratorAndFirst{F, T}
2828
first = iterate(x)
2929
return new{typeof(first), typeof(x)}(first, x, len)
3030
end
31+
function IteratorAndFirst(first, x)
32+
len = Base.haslength(x) ? length(x) + 1 : 1
33+
return new{typeof(first), typeof(x)}(first, x, len)
34+
end
3135
end
3236
Base.IteratorSize(::Type{IteratorAndFirst{F, T}}) where {F, T} = Base.IteratorSize(T)
3337
Base.length(x::IteratorAndFirst) = x.len
@@ -39,6 +43,8 @@ function Base.iterate(x::IteratorAndFirst, st)
3943
return iterate(x.source, st)
4044
end
4145

46+
showtable(table::AbstractMatrix; kwargs...) = showtable(Tables.table(table); kwargs...)
47+
4248
function showtable(table; dark = false, height = :auto, width = "100%")
4349
rows = Tables.rows(table)
4450
tablelength = Base.IteratorSize(rows) == Base.HasLength() ? length(rows) : nothing
@@ -171,6 +177,10 @@ function table2json(rows, names, types; requested = nothing)
171177
print(io, ':')
172178
if col isa Number
173179
JSON.print(io, col)
180+
elseif col === nothing
181+
JSON.print(io, "nothing")
182+
elseif col === missing
183+
JSON.print(io, "missing")
174184
else
175185
JSON.print(io, sprint(print, col))
176186
end

test/runtests.jl

+22-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
using TableView
22
using Test, WebIO
33

4-
version = readchomp(joinpath(@__DIR__, "..", "ag-grid.version"))
5-
6-
@test isfile(joinpath(@__DIR__, "..", "deps", "ag-grid-$(version)", "ag-grid.js"))
7-
8-
nttable = [
9-
(a = 2.0, b = 3),
10-
(a = 3.0, b = 12)
11-
]
12-
@test showtable(nttable) isa WebIO.Scope
4+
@testset "installation" begin
5+
version = readchomp(joinpath(@__DIR__, "..", "ag-grid.version"))
6+
@test isfile(joinpath(@__DIR__, "..", "deps", "ag-grid-$(version)", "ag-grid.js"))
7+
end
8+
@testset "named tuple table" begin
9+
nttable = [
10+
(a = 2.0, b = 3),
11+
(a = 3.0, b = 12)
12+
]
13+
@test showtable(nttable) isa WebIO.Scope
14+
end
15+
@testset "named tuple table with missing and nothing" begin
16+
nttable = [
17+
(a = 2.0, b = 3, c = missing),
18+
(a = 3.0, b = 12, c = nothing)
19+
]
20+
@test showtable(nttable) isa WebIO.Scope
21+
end
22+
@testset "normal array" begin
23+
array = rand(10, 10)
24+
@test showtable(array) isa WebIO.Scope
25+
end

0 commit comments

Comments
 (0)