Skip to content

Commit 86a9799

Browse files
authored
Merge pull request #23 from JuliaComputing/sp/naninf
fix serializing for nan/inf
2 parents 8e112e1 + 5b99e03 commit 86a9799

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/TableView.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function table2json(rows, names, types; requested = nothing)
175175
JSON.print(io, names[i])
176176
i += 1
177177
print(io, ':')
178-
if col isa Number
178+
if col isa Number && isfinite(col)
179179
JSON.print(io, col)
180180
elseif col === nothing
181181
JSON.print(io, "nothing")

test/runtests.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using TableView
2-
using Test, WebIO
2+
using Test, WebIO, Tables, JSON
33

44
@testset "installation" begin
55
version = readchomp(joinpath(@__DIR__, "..", "ag-grid.version"))
@@ -19,6 +19,17 @@ end
1919
]
2020
@test showtable(nttable) isa WebIO.Scope
2121
end
22+
@testset "inf and nan serializing" begin
23+
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)
27+
firstrow = JSON.parse(json)[1]
28+
@test firstrow["a"] == "NaN"
29+
@test firstrow["b"] == "Inf"
30+
@test firstrow["c"] == "-Inf"
31+
@test firstrow["d"] == 0
32+
end
2233
@testset "normal array" begin
2334
array = rand(10, 10)
2435
@test showtable(array) isa WebIO.Scope

0 commit comments

Comments
 (0)