Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up writetable #667

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions src/dataframe/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,28 @@ function escapedprint(io::IO, x::String, escapes::String)
print_escaped(io, x, escapes)
end

using Base.Cartesian
@ngenerate N Nothing function _printtable(io::IO, header::Bool, separator::Char, quotemark::Char, col::NTuple{N, AbstractVector}...)
@nexprs N j->(extr_j = DataArrays.daextract(col_j))
for i = 1:length(col_1)
@nexprs N j->(begin
if DataArrays.unsafe_isna(col_j, extr_j, i)
print(io, "NA")
elseif !(eltype(col_j) <: Real)
print(io, quotemark)
escapedprint(io, DataArrays.unsafe_getindex_notna(col_j, extr_j, i), "\"'")
print(io, quotemark)
else
print(io, DataArrays.unsafe_getindex_notna(col_j, extr_j, i))
end
if j < N
print(io, separator)
end
end)
print(io, '\n')
end
end

function printtable(io::IO,
df::DataFrame;
header::Bool = true,
Expand All @@ -1010,22 +1032,7 @@ function printtable(io::IO,
end
end
end
for i in 1:n
for j in 1:p
if ! (etypes[j] <: Real)
print(io, quotemark)
escapedprint(io, df[i, j], "\"'")
print(io, quotemark)
else
print(io, df[i, j])
end
if j < p
print(io, separator)
else
print(io, '\n')
end
end
end
_printtable(io, header, separator, quotemark, df.columns...)
return
end

Expand Down