Skip to content

Commit 754e992

Browse files
authored
Merge pull request #39 from JuliaComputing/sp/tables1
update to Tables 1.0
2 parents 4b9fbc8 + 4d4813b commit 754e992

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.jl.cov
22
*.jl.*.cov
33
*.jl.mem
4+
Manifest.toml

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ julia:
66
- 1.0
77
- 1.1
88
- 1.2
9+
- 1.3
10+
- 1.4
911
- nightly
1012
matrix:
1113
allow_failures:

Project.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
1212
WebIO = "0f1e0344-ec1d-5b48-a673-e5cf874b6c29"
1313

1414
[compat]
15-
julia = "≥ 0.7.0"
15+
JSExpr = "0.4, 0.5"
16+
JSON = "0.18, 0.19, 0.20, 0.21"
17+
Observables = "0.2"
18+
Tables = "1"
19+
WebIO = "0.8"
20+
julia = "0.7, 1"
1621

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

src/TableView.jl

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,13 @@ function showtable(table, options::Dict{Symbol, Any} = Dict{Symbol, Any}(); dark
155155

156156
showfun = async ? _showtable_async! : _showtable_sync!
157157

158-
showfun(w, names, types, rows, coldefs, tablelength, id, options)
158+
showfun(w, schema, names, types, rows, coldefs, tablelength, id, options)
159159

160160
w
161161
end
162162

163-
function _showtable_sync!(w, names, types, rows, coldefs, tablelength, id, options)
164-
options[:rowData] = JSONText(table2json(rows, names, types))
163+
function _showtable_sync!(w, schema, names, types, rows, coldefs, tablelength, id, options)
164+
options[:rowData] = JSONText(table2json(schema, rows, types))
165165
handler = @js function (agGrid)
166166
@var gridOptions = $options
167167
@var el = document.getElementById($id)
@@ -171,14 +171,13 @@ function _showtable_sync!(w, names, types, rows, coldefs, tablelength, id, optio
171171
onimport(w, handler)
172172
end
173173

174-
175-
function _showtable_async!(w, names, types, rows, coldefs, tablelength, id, options)
174+
function _showtable_async!(w, schema, names, types, rows, coldefs, tablelength, id, options)
176175
rowparams = Observable(w, "rowparams", Dict("startRow" => 1,
177176
"endRow" => 100,
178177
"successCallback" => @js v -> nothing))
179178
requestedrows = Observable(w, "requestedrows", JSONText("{}"))
180179
on(rowparams) do x
181-
requestedrows[] = JSONText(table2json(rows, names, types, requested = [x["startRow"] + 1, x["endRow"] + 1]))
180+
requestedrows[] = JSONText(table2json(schema, rows, types, requested = [x["startRow"] + 1, x["endRow"] + 1]))
182181
end
183182

184183
onjs(requestedrows, @js function (val)
@@ -208,25 +207,23 @@ function _showtable_async!(w, names, types, rows, coldefs, tablelength, id, opti
208207
end
209208

210209
# directly write JSON instead of allocating temporary dicts etc
211-
function table2json(rows, names, types; requested = nothing)
210+
function table2json(schema, rows, types; requested = nothing)
212211
io = IOBuffer()
213212
print(io, '[')
214213
for (i, row) in enumerate(rows)
215214
if requested == nothing || first(requested) <= i <= last(requested)
216215
print(io, '{')
217-
i = 1
218-
for col in Tables.eachcolumn(row)
219-
JSON.print(io, names[i])
220-
i += 1
216+
Tables.eachcolumn(schema, row) do val, ind, name
217+
JSON.print(io, name)
221218
print(io, ':')
222-
if col isa Number && isfinite(col)
223-
JSON.print(io, col)
224-
elseif col === nothing
219+
if val isa Number && isfinite(val)
220+
JSON.print(io, val)
221+
elseif val === nothing
225222
JSON.print(io, "nothing")
226-
elseif col === missing
223+
elseif val === missing
227224
JSON.print(io, "missing")
228225
else
229-
JSON.print(io, sprint(print, col))
226+
JSON.print(io, sprint(print, val))
230227
end
231228
print(io, ',')
232229
end

test/runtests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ end
2121
end
2222
@testset "inf and nan serializing" begin
2323
rows = Tables.table([NaN Inf -Inf 0])
24-
names = [:a, :b, :c, :d, :e, :f]
25-
types = [Float64 for _ in 1:6]
26-
json = TableView.table2json(rows, names, types)
24+
names = [:a, :b, :c, :d]
25+
types = [Float64 for _ in 1:4]
26+
json = TableView.table2json(Tables.Schema(names, types), rows, types)
2727
firstrow = JSON.parse(json)[1]
2828
@test firstrow["a"] == "NaN"
2929
@test firstrow["b"] == "Inf"

0 commit comments

Comments
 (0)