Skip to content

Commit

Permalink
Format files using DocumentFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Apr 29, 2021
1 parent 55c5f4f commit 0172c61
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
8 changes: 4 additions & 4 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Documenter, CSVFiles

makedocs(
modules = [CSVFiles],
sitename = "CSVFiles.jl",
modules=[CSVFiles],
sitename="CSVFiles.jl",
analytics="UA-132838790-1",
pages = [
pages=[
"Introduction" => "index.md"
]
)

deploydocs(
repo = "github.com/queryverse/CSVFiles.jl.git"
repo="github.com/queryverse/CSVFiles.jl.git"
)
28 changes: 14 additions & 14 deletions src/CSVFiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,36 @@ end

Base.showable(::MIME"application/vnd.dataresource+json", source::CSVStream) = true

function fileio_load(f::FileIO.File{FileIO.format"CSV"}, deprecated_delim=nothing; delim=deprecated_delim===nothing ? ',' : deprecated_delim, args...)
if deprecated_delim!==nothing
deprecated_delim!=delim && error("deprecated_delim and delim can not both be used at the same time.")
function fileio_load(f::FileIO.File{FileIO.format"CSV"}, deprecated_delim=nothing; delim=deprecated_delim === nothing ? ',' : deprecated_delim, args...)
if deprecated_delim !== nothing
deprecated_delim != delim && error("deprecated_delim and delim can not both be used at the same time.")
Base.depwarn("The positional `delim` keyword in the `load` function is deprecated. Instead use the keyword argument `delim`.", :CSVFiles)
end

return CSVFile(f.filename, delim, args)
end

function fileio_load(f::FileIO.File{FileIO.format"TSV"}, deprecated_delim=nothing; delim=deprecated_delim===nothing ? '\t' : deprecated_delim, args...)
if deprecated_delim!==nothing
deprecated_delim!=delim && error("deprecated_delim and delim can not both be used at the same time.")
function fileio_load(f::FileIO.File{FileIO.format"TSV"}, deprecated_delim=nothing; delim=deprecated_delim === nothing ? '\t' : deprecated_delim, args...)
if deprecated_delim !== nothing
deprecated_delim != delim && error("deprecated_delim and delim can not both be used at the same time.")
Base.depwarn("The positional `delim` keyword in the `load` function is deprecated. Instead use the keyword argument `delim`.", :CSVFiles)
end

return CSVFile(f.filename, delim, args)
end

function fileio_load(s::FileIO.Stream{FileIO.format"CSV"}, deprecated_delim=nothing; delim=deprecated_delim===nothing ? ',' : deprecated_delim, args...)
if deprecated_delim!==nothing
deprecated_delim!=delim && error("deprecated_delim and delim can not both be used at the same time.")
function fileio_load(s::FileIO.Stream{FileIO.format"CSV"}, deprecated_delim=nothing; delim=deprecated_delim === nothing ? ',' : deprecated_delim, args...)
if deprecated_delim !== nothing
deprecated_delim != delim && error("deprecated_delim and delim can not both be used at the same time.")
Base.depwarn("The positional `delim` keyword in the `load` function is deprecated. Instead use the keyword argument `delim`.", :CSVFiles)
end

return CSVStream(s.io, delim, args)
end

function fileio_load(s::FileIO.Stream{FileIO.format"TSV"}, deprecated_delim=nothing; delim=deprecated_delim===nothing ? '\t' : deprecated_delim, args...)
if deprecated_delim!==nothing
deprecated_delim!=delim && error("deprecated_delim and delim can not both be used at the same time.")
function fileio_load(s::FileIO.Stream{FileIO.format"TSV"}, deprecated_delim=nothing; delim=deprecated_delim === nothing ? '\t' : deprecated_delim, args...)
if deprecated_delim !== nothing
deprecated_delim != delim && error("deprecated_delim and delim can not both be used at the same time.")
Base.depwarn("The positional `delim` keyword in the `load` function is deprecated. Instead use the keyword argument `delim`.", :CSVFiles)
end

Expand Down Expand Up @@ -114,7 +114,7 @@ end

function TableTraits.get_columns_copy_using_missing(file::CSVFile)
columns, colnames = _loaddata(file)
return NamedTuple{(Symbol.(colnames)...,), Tuple{typeof.(columns)...}}((columns...,))
return NamedTuple{(Symbol.(colnames)...,),Tuple{typeof.(columns)...}}((columns...,))
end

function IteratorInterfaceExtensions.getiterator(s::CSVStream)
Expand All @@ -127,7 +127,7 @@ end

function TableTraits.get_columns_copy_using_missing(s::CSVStream)
columns, colnames = TextParse.csvread(s.io, s.delim; stringarraytype=Array, s.keywords...)
return NamedTuple{(Symbol.(colnames)...,), Tuple{typeof.(columns)...}}((columns...,))
return NamedTuple{(Symbol.(colnames)...,),Tuple{typeof.(columns)...}}((columns...,))
end

function Base.collect(x::CSVFile)
Expand Down
22 changes: 11 additions & 11 deletions src/csv_writer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ end
function _writevalue(io::IO, value::AbstractString, delim, quotechar, escapechar, nastring)
print(io, quotechar)
for c in value
if c==quotechar || c==escapechar
if c == quotechar || c == escapechar
print(io, escapechar)
end
print(io, c)
Expand All @@ -32,8 +32,8 @@ end
push_exprs = Expr(:block)
for i in 1:n
push!(push_exprs.args, :( _writevalue(io, i.$(col_names[i]), delim, quotechar, escapechar, nastring) ))
if i<n
push!(push_exprs.args, :( print(io, delim ) ))
if i < n
push!(push_exprs.args, :( print(io, delim) ))
end
end
push!(push_exprs.args, :( println(io) ))
Expand All @@ -52,10 +52,10 @@ function _save(io, data; delim=',', quotechar='"', escapechar='"', nastring="NA"
colnames = collect(eltype(it).parameters[1])

if header
if quotechar===nothing
join(io,[string(colname) for colname in colnames],delim)
if quotechar === nothing
join(io, [string(colname) for colname in colnames], delim)
else
join(io,["$(quotechar)" * replace(string(colname), quotechar => "$(escapechar)$(quotechar)") * "$(quotechar)" for colname in colnames],delim)
join(io, ["$(quotechar)" * replace(string(colname), quotechar => "$(escapechar)$(quotechar)") * "$(quotechar)" for colname in colnames], delim)
end
println(io)
end
Expand Down Expand Up @@ -99,7 +99,7 @@ end
#
# Streaming version writes header (if any) on first call, then appends on subsequent calls.
#
const CSV_or_TSV = Union{FileIO.format"CSV", FileIO.format"TSV"}
const CSV_or_TSV = Union{FileIO.format"CSV",FileIO.format"TSV"}

_delim(T) = T <: FileIO.format"CSV" ? ',' : '\t'

Expand All @@ -117,21 +117,21 @@ function fileio_savestreaming(f::FileIO.File{T}, data=nothing; delim=_delim(T),
header=true) where T <: CSV_or_TSV
io = open(f.filename, "w")

if data!==nothing
if data !== nothing
_save(io, data; delim=delim, quotechar=quotechar, escapechar=escapechar, nastring=nastring, header=header)
end

return CSVFileSaveStream(io, data!==nothing, delim, quotechar, escapechar, nastring, header)
return CSVFileSaveStream(io, data !== nothing, delim, quotechar, escapechar, nastring, header)
end

function fileio_savestreaming(s::FileIO.Stream{T}, data=nothing; delim=_delim(T), quotechar='"', escapechar='"', nastring="NA",
header=false) where T <: CSV_or_TSV

if data!==nothing
if data !== nothing
_save(s.io, data; delim=delim, quotechar=quotechar, escapechar=escapechar, nastring=nastring, header=header)
end

return CSVFileSaveStream(s.io, data!==nothing, delim, quotechar, escapechar, nastring, header)
return CSVFileSaveStream(s.io, data !== nothing, delim, quotechar, escapechar, nastring, header)
end

function Base.write(s::CSVFileSaveStream, data)
Expand Down

0 comments on commit 0172c61

Please sign in to comment.