Skip to content

Commit 67098fd

Browse files
Format files using DocumentFormat
1 parent e6f1a3f commit 67098fd

File tree

4 files changed

+52
-52
lines changed

4 files changed

+52
-52
lines changed

docs/make.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
using Documenter, CSVFiles
22

33
makedocs(
4-
modules = [CSVFiles],
5-
sitename = "CSVFiles.jl",
4+
modules=[CSVFiles],
5+
sitename="CSVFiles.jl",
66
analytics="UA-132838790-1",
7-
pages = [
7+
pages=[
88
"Introduction" => "index.md"
99
]
1010
)
1111

1212
deploydocs(
13-
repo = "github.com/queryverse/CSVFiles.jl.git"
13+
repo="github.com/queryverse/CSVFiles.jl.git"
1414
)

src/CSVFiles.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,36 +50,36 @@ end
5050

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

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

5959
return CSVFile(f.filename, delim, args)
6060
end
6161

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

6868
return CSVFile(f.filename, delim, args)
6969
end
7070

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

7777
return CSVStream(s.io, delim, args)
7878
end
7979

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

@@ -114,7 +114,7 @@ end
114114

115115
function TableTraits.get_columns_copy_using_missing(file::CSVFile)
116116
columns, colnames = _loaddata(file)
117-
return NamedTuple{(Symbol.(colnames)...,), Tuple{typeof.(columns)...}}((columns...,))
117+
return NamedTuple{(Symbol.(colnames)...,),Tuple{typeof.(columns)...}}((columns...,))
118118
end
119119

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

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

133133
function Base.collect(x::CSVFile)

src/csv_writer.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ end
55
function _writevalue(io::IO, value::AbstractString, delim, quotechar, escapechar, nastring)
66
print(io, quotechar)
77
for c in value
8-
if c==quotechar || c==escapechar
8+
if c == quotechar || c == escapechar
99
print(io, escapechar)
1010
end
1111
print(io, c)
@@ -32,8 +32,8 @@ end
3232
push_exprs = Expr(:block)
3333
for i in 1:n
3434
push!(push_exprs.args, :( _writevalue(io, i.$(col_names[i]), delim, quotechar, escapechar, nastring) ))
35-
if i<n
36-
push!(push_exprs.args, :( print(io, delim ) ))
35+
if i < n
36+
push!(push_exprs.args, :( print(io, delim) ))
3737
end
3838
end
3939
push!(push_exprs.args, :( println(io) ))
@@ -52,10 +52,10 @@ function _save(io, data; delim=',', quotechar='"', escapechar='"', nastring="NA"
5252
colnames = collect(eltype(it).parameters[1])
5353

5454
if header
55-
if quotechar===nothing
56-
join(io,[string(colname) for colname in colnames],delim)
55+
if quotechar === nothing
56+
join(io, [string(colname) for colname in colnames], delim)
5757
else
58-
join(io,["$(quotechar)" * replace(string(colname), quotechar => "$(escapechar)$(quotechar)") * "$(quotechar)" for colname in colnames],delim)
58+
join(io, ["$(quotechar)" * replace(string(colname), quotechar => "$(escapechar)$(quotechar)") * "$(quotechar)" for colname in colnames], delim)
5959
end
6060
println(io)
6161
end
@@ -99,7 +99,7 @@ end
9999
#
100100
# Streaming version writes header (if any) on first call, then appends on subsequent calls.
101101
#
102-
const CSV_or_TSV = Union{FileIO.format"CSV", FileIO.format"TSV"}
102+
const CSV_or_TSV = Union{FileIO.format"CSV",FileIO.format"TSV"}
103103

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

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

120-
if data!==nothing
120+
if data !== nothing
121121
_save(io, data; delim=delim, quotechar=quotechar, escapechar=escapechar, nastring=nastring, header=header)
122122
end
123123

124-
return CSVFileSaveStream(io, data!==nothing, delim, quotechar, escapechar, nastring, header)
124+
return CSVFileSaveStream(io, data !== nothing, delim, quotechar, escapechar, nastring, header)
125125
end
126126

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

130-
if data!==nothing
130+
if data !== nothing
131131
_save(s.io, data; delim=delim, quotechar=quotechar, escapechar=escapechar, nastring=nastring, header=header)
132132
end
133133

134-
return CSVFileSaveStream(s.io, data!==nothing, delim, quotechar, escapechar, nastring, header)
134+
return CSVFileSaveStream(s.io, data !== nothing, delim, quotechar, escapechar, nastring, header)
135135
end
136136

137137
function Base.write(s::CSVFileSaveStream, data)

test/runtests.jl

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ using Test
77

88
@testset "CSVFiles" begin
99

10-
@testset "basic" begin
11-
array = collect(load(joinpath(@__DIR__, "data.csv")))
12-
@test length(array) == 3
13-
@test array == [(Name="John",Age=34.,Children=2),(Name="Sally",Age=54.,Children=1),(Name="Jim",Age=23.,Children=0)]
10+
@testset "basic" begin
11+
array = collect(load(joinpath(@__DIR__, "data.csv")))
12+
@test length(array) == 3
13+
@test array == [(Name = "John", Age = 34., Children = 2),(Name = "Sally", Age = 54., Children = 1),(Name = "Jim", Age = 23., Children = 0)]
1414

15-
output_filename = tempname() * ".csv"
15+
output_filename = tempname() * ".csv"
1616

17-
try
18-
array |> save(output_filename)
17+
try
18+
array |> save(output_filename)
1919

20-
array2 = collect(load(output_filename))
20+
array2 = collect(load(output_filename))
2121

22-
@test array == array2
23-
finally
22+
@test array == array2
23+
finally
2424
GC.gc()
2525
rm(output_filename)
2626
end
@@ -35,7 +35,7 @@ end
3535
end
3636

3737
@testset "missing values" begin
38-
array3 = [(a=DataValue(3),b="df\"e"),(a=DataValue{Int}(),b="something")]
38+
array3 = [(a = DataValue(3), b = "df\"e"),(a = DataValue{Int}(), b = "something")]
3939

4040
@testset "default" begin
4141
output_filename2 = tempname() * ".csv"
@@ -48,7 +48,7 @@ end
4848
end
4949

5050
@testset "alternate" begin
51-
output_filename2 = tempname() * ".csv"
51+
output_filename2 = tempname() * ".csv"
5252

5353
try
5454
array3 |> save(output_filename2, nastring="")
@@ -62,11 +62,11 @@ end
6262
csvf2 = load(joinpath(@__DIR__, "data.csv"))
6363
@test TableTraits.supports_get_columns_copy_using_missing(csvf2) == true
6464
data = TableTraits.get_columns_copy_using_missing(csvf2)
65-
@test data == (Name=["John", "Sally", "Jim"], Age=[34.,54.,23.], Children=[2,1,0])
65+
@test data == (Name = ["John", "Sally", "Jim"], Age = [34.,54.,23.], Children = [2,1,0])
6666
end
6767

6868
@testset "Less Basic" begin
69-
array = [(Name="John",Age=34.,Children=2),(Name="Sally",Age=54.,Children=1),(Name="Jim",Age=23.,Children=0)]
69+
array = [(Name = "John", Age = 34., Children = 2),(Name = "Sally", Age = 54., Children = 1),(Name = "Jim", Age = 23., Children = 0)]
7070
@testset "remote loading" begin
7171
rem_array = collect(load("https://raw.githubusercontent.com/queryverse/CSVFiles.jl/v0.2.0/test/data.csv"))
7272
@test length(rem_array) == 3
@@ -102,7 +102,7 @@ end
102102
end
103103

104104
@testset "Streams" begin
105-
data = [(Name="John",Age=34.,Children=2),(Name="Sally",Age=54.,Children=1),(Name="Jim",Age=23.,Children=0)]
105+
data = [(Name = "John", Age = 34., Children = 2),(Name = "Sally", Age = 54., Children = 1),(Name = "Jim", Age = 23., Children = 0)]
106106

107107
@testset "CSV" begin
108108
stream = IOBuffer()
@@ -121,7 +121,7 @@ end
121121
reset(stream)
122122
csvstream = load(fileiostream)
123123
reloaded_data2 = TableTraits.get_columns_copy_using_missing(csvstream)
124-
@test reloaded_data2 == (Name=["John", "Sally", "Jim"], Age=[34., 54., 23.], Children=[2, 1, 0])
124+
@test reloaded_data2 == (Name = ["John", "Sally", "Jim"], Age = [34., 54., 23.], Children = [2, 1, 0])
125125
end
126126

127127
@testset "TSV" begin
@@ -141,12 +141,12 @@ end
141141
reset(stream)
142142
csvstream = load(fileiostream)
143143
reloaded_data2 = TableTraits.get_columns_copy_using_missing(csvstream)
144-
@test reloaded_data2 == (Name=["John", "Sally", "Jim"], Age=[34., 54., 23.], Children=[2, 1, 0])
144+
@test reloaded_data2 == (Name = ["John", "Sally", "Jim"], Age = [34., 54., 23.], Children = [2, 1, 0])
145145
end
146146
end
147147

148148
@testset "Compression" begin
149-
data = [(Name="John",Age=34.,Children=2),(Name="Sally",Age=54.,Children=1),(Name="Jim",Age=23.,Children=0)]
149+
data = [(Name = "John", Age = 34., Children = 2),(Name = "Sally", Age = 54., Children = 1),(Name = "Jim", Age = 23., Children = 0)]
150150

151151
@testset "CSV" begin
152152
output_filename = "output.csv.gz"
@@ -182,10 +182,10 @@ end
182182
Sally │ 54.0 │ 1
183183
Jim │ 23.0 │ 0 """
184184

185-
@test sprint((stream,data)->show(stream, "text/html", data), x) ==
185+
@test sprint((stream, data) -> show(stream, "text/html", data), x) ==
186186
"<table><thead><tr><th>Name</th><th>Age</th><th>Children</th></tr></thead><tbody><tr><td>&quot;John&quot;</td><td>34.0</td><td>2</td></tr><tr><td>&quot;Sally&quot;</td><td>54.0</td><td>1</td></tr><tr><td>&quot;Jim&quot;</td><td>23.0</td><td>0</td></tr></tbody></table>"
187187

188-
@test sprint((stream,data)->show(stream, "application/vnd.dataresource+json", data), x) ==
188+
@test sprint((stream, data) -> show(stream, "application/vnd.dataresource+json", data), x) ==
189189
"{\"schema\":{\"fields\":[{\"name\":\"Name\",\"type\":\"string\"},{\"name\":\"Age\",\"type\":\"number\"},{\"name\":\"Children\",\"type\":\"integer\"}]},\"data\":[{\"Name\":\"John\",\"Age\":34.0,\"Children\":2},{\"Name\":\"Sally\",\"Age\":54.0,\"Children\":1},{\"Name\":\"Jim\",\"Age\":23.0,\"Children\":0}]}"
190190

191191
@test showable("text/html", x) == true
@@ -202,10 +202,10 @@ end
202202
Sally │ 54.0 │ 1
203203
Jim │ 23.0 │ 0 """
204204

205-
@test sprint((stream,data)->show(stream, "text/html", data), x2) ==
205+
@test sprint((stream, data) -> show(stream, "text/html", data), x2) ==
206206
"<table><thead><tr><th>Name</th><th>Age</th><th>Children</th></tr></thead><tbody><tr><td>&quot;John&quot;</td><td>34.0</td><td>2</td></tr><tr><td>&quot;Sally&quot;</td><td>54.0</td><td>1</td></tr><tr><td>&quot;Jim&quot;</td><td>23.0</td><td>0</td></tr></tbody></table>"
207207

208-
@test sprint((stream,data)->show(stream, "application/vnd.dataresource+json", data), x2) ==
208+
@test sprint((stream, data) -> show(stream, "application/vnd.dataresource+json", data), x2) ==
209209
"{\"schema\":{\"fields\":[{\"name\":\"Name\",\"type\":\"string\"},{\"name\":\"Age\",\"type\":\"number\"},{\"name\":\"Children\",\"type\":\"integer\"}]},\"data\":[{\"Name\":\"John\",\"Age\":34.0,\"Children\":2},{\"Name\":\"Sally\",\"Age\":54.0,\"Children\":1},{\"Name\":\"Jim\",\"Age\":23.0,\"Children\":0}]}"
210210

211211
@test showable("text/html", x2) == true
@@ -217,7 +217,7 @@ end
217217
@testset "savestreaming" begin
218218
using DataFrames
219219

220-
df = DataFrame(A = 1:2:1000, B = repeat(1:10, inner=50), C = 1:500)
220+
df = DataFrame(A=1:2:1000, B=repeat(1:10, inner=50), C=1:500)
221221
df1 = df[1:5, :]
222222
df2 = df[6:10, :]
223223

0 commit comments

Comments
 (0)