Skip to content

Commit

Permalink
Merge pull request #9 from queryverse/eltypeunknown
Browse files Browse the repository at this point in the history
Eltypeunknown
  • Loading branch information
davidanthoff authored Feb 10, 2019
2 parents 19824af + e1f25ec commit 1613f4a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# TableShowUtils.jl v0.2.4 Release Notes
* Make printdataresource work with EltypeUnknown

# TableShowUtils.jl v0.2.3 Release Notes
* Show NA values in gray

Expand Down
11 changes: 8 additions & 3 deletions src/TableShowUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,14 @@ own_json_formatter(io, x) = JSON.print(io, x)
own_json_formatter(io, x::DataValues.DataValue) = DataValues.isna(x) ? JSON.print(io,nothing) : own_json_formatter(io, x[])

function printdataresource(io::IO, source)
col_names = String.(fieldnames(eltype(source)))
col_types = [fieldtype(eltype(source), i) for i=1:length(col_names)]

if Base.IteratorEltype(source) isa Base.EltypeUnknown
first_el = first(source)
col_names = String.(propertynames(first_el))
col_types = [fieldtype(typeof(first_el), i) for i=1:length(col_names)]
else
col_names = String.(fieldnames(eltype(source)))
col_types = [fieldtype(eltype(source), i) for i=1:length(col_names)]
end
schema = Dict("fields" => [Dict("name"=>string(i[1]), "type"=>julia_type_to_schema_type(i[2])) for i in zip(col_names, col_types)])

print(io, "{")
Expand Down

0 comments on commit 1613f4a

Please sign in to comment.