Skip to content

Commit e6124de

Browse files
authored
Merge pull request #58 from baumgold/custom_string_repr
#57 enable custom string representation of missing and nothing values
2 parents faaa7e0 + 4f603f2 commit e6124de

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/TableView.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ function table2json(schema, rows, types; requested = nothing)
263263
if val isa Number && isfinite(val)
264264
JSON.print(io, val)
265265
elseif val === nothing
266-
JSON.print(io, "nothing")
266+
JSON.print(io, repr(nothing))
267267
elseif val === missing
268-
JSON.print(io, "missing")
268+
JSON.print(io, repr(missing))
269269
else
270270
JSON.print(io, sprint(print, val))
271271
end

test/runtests.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ 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]
25-
types = [Float64 for _ in 1:4]
22+
@testset "inf, nan, and missing serializing" begin
23+
rows = Tables.table([NaN Inf -Inf 0 missing])
24+
names = [:a, :b, :c, :d, :e]
25+
types = vcat([Float64 for _ in 1:4], [Missing])
26+
Base.show(io::IO, x::Missing) = print(io, "test_missing")
2627
json = TableView.table2json(Tables.Schema(names, types), rows, types)
2728
firstrow = JSON.parse(json)[1]
2829
@test firstrow["a"] == "NaN"
2930
@test firstrow["b"] == "Inf"
3031
@test firstrow["c"] == "-Inf"
3132
@test firstrow["d"] == 0
33+
@test firstrow["e"] == "test_missing"
3234
end
3335
@testset "normal array" begin
3436
array = rand(10, 10)

0 commit comments

Comments
 (0)