Skip to content

Commit

Permalink
Format files using DocumentFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
davidanthoff authored Dec 29, 2023
1 parent f00af7b commit 7bfb765
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
8 changes: 4 additions & 4 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Documenter, TableTraitsUtils

makedocs(
modules=[TableTraitsUtils],
sitename="TableTraitsUtils.jl",
analytics="UA-132838790-1",
pages=[
modules=[TableTraitsUtils],
sitename="TableTraitsUtils.jl",
analytics="UA-132838790-1",
pages=[
"Introduction" => "index.md"
]
)
Expand Down
12 changes: 6 additions & 6 deletions src/collect1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ end
for col_idx in 1:length(fieldnames(T))
if fieldtype(TYPES, col_idx) !== Nothing
if fieldtype(TYPES, col_idx) == Array{Any,1} && fieldtype(T, col_idx) == DataValue{Any}
ex = :( dest[$col_idx][i] = get(el[$col_idx], missing) )
ex = :(dest[$col_idx][i] = get(el[$col_idx], missing))
else
ex = :( dest[$col_idx][i] = el[$col_idx] )
ex = :(dest[$col_idx][i] = el[$col_idx])
end
push!(push_exprs.args, ex)
end
Expand All @@ -89,9 +89,9 @@ end
for col_idx in 1:length(fieldnames(T))
if fieldtype(TYPES, col_idx) !== Nothing
if fieldtype(TYPES, col_idx) == Array{Any,1} && fieldtype(T, col_idx) == DataValue{Any}
ex = :( push!(dest[$col_idx], get(el[$col_idx], missing)) )
ex = :(push!(dest[$col_idx], get(el[$col_idx], missing)))
else
ex = :( push!(dest[$col_idx], el[$col_idx]) )
ex = :(push!(dest[$col_idx], el[$col_idx]))
end
push!(push_exprs.args, ex)
end
Expand Down Expand Up @@ -119,7 +119,7 @@ function _collect_columns(itr, ::Union{Base.HasShape,Base.HasLength}, array_fact
_collect_to_columns!(dest, itr, 2, y[2], sel_cols, errorhandling)
end

function _collect_to_columns!(dest::T, itr, offs, st, sel_cols, errorhandling) where {T <: NamedTuple}
function _collect_to_columns!(dest::T, itr, offs, st, sel_cols, errorhandling) where {T<:NamedTuple}
i = offs
y = iterate(itr, st)
while y !== nothing
Expand Down Expand Up @@ -156,7 +156,7 @@ function _collect_columns(itr, ::Base.SizeUnknown, array_factory, sel_cols, erro
_grow_to_columns!(dest, itr, y[2], sel_cols, errorhandling)
end

function _grow_to_columns!(dest::T, itr, st, sel_cols, errorhandling) where {T <: NamedTuple}
function _grow_to_columns!(dest::T, itr, st, sel_cols, errorhandling) where {T<:NamedTuple}
y = iterate(itr, st)
while y !== nothing
_pushrow(dest, y[1])
Expand Down
56 changes: 28 additions & 28 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ include("test_source_without_length.jl")
@test_throws ArgumentError TableTraitsUtils.create_columns_from_iterabletable(nothing, errorhandling=:error)
@test TableTraitsUtils.create_columns_from_iterabletable(nothing, errorhandling=:returnvalue) === nothing

@test_throws ArgumentError TableTraitsUtils.create_columns_from_iterabletable([1,2,3])
@test_throws ArgumentError TableTraitsUtils.create_columns_from_iterabletable([1,2,3], errorhandling=:error)
@test TableTraitsUtils.create_columns_from_iterabletable([1,2,3], errorhandling=:returnvalue) === nothing
@test_throws ArgumentError TableTraitsUtils.create_columns_from_iterabletable([1, 2, 3])
@test_throws ArgumentError TableTraitsUtils.create_columns_from_iterabletable([1, 2, 3], errorhandling=:error)
@test TableTraitsUtils.create_columns_from_iterabletable([1, 2, 3], errorhandling=:returnvalue) === nothing

@test_throws ArgumentError TableTraitsUtils.create_columns_from_iterabletable(Iterators.filter(i -> true, [1,2,3]))
@test_throws ArgumentError TableTraitsUtils.create_columns_from_iterabletable(Iterators.filter(i -> true, [1,2,3]), errorhandling=:error)
@test TableTraitsUtils.create_columns_from_iterabletable(Iterators.filter(i -> true, [1,2,3]), errorhandling=:returnvalue) === nothing
@test_throws ArgumentError TableTraitsUtils.create_columns_from_iterabletable(Iterators.filter(i -> true, [1, 2, 3]))
@test_throws ArgumentError TableTraitsUtils.create_columns_from_iterabletable(Iterators.filter(i -> true, [1, 2, 3]), errorhandling=:error)
@test TableTraitsUtils.create_columns_from_iterabletable(Iterators.filter(i -> true, [1, 2, 3]), errorhandling=:returnvalue) === nothing

@test create_columns_from_iterabletable(NamedTuple{(:a, :b),Tuple{Int,String}}[]) == (Any[Int[],String[]], [:a,:b])
@test create_columns_from_iterabletable((i for i in NamedTuple{(:a, :b),Tuple{Int,String}}[])) == (Any[Int[],String[]], [:a,:b])
@test create_columns_from_iterabletable(NamedTuple{(:a, :b),Tuple{Int,String}}[]) == (Any[Int[], String[]], [:a, :b])
@test create_columns_from_iterabletable((i for i in NamedTuple{(:a, :b),Tuple{Int,String}}[])) == (Any[Int[], String[]], [:a, :b])

@test_throws ArgumentError create_columns_from_iterabletable(Int[])
@test_throws ArgumentError create_columns_from_iterabletable(Int[], errorhandling=:error)
Expand All @@ -28,7 +28,7 @@ include("test_source_without_length.jl")
@test_throws ArgumentError create_columns_from_iterabletable((i for i in Int[]), errorhandling=:error)
@test create_columns_from_iterabletable((i for i in Int[]), errorhandling=:returnvalue) === nothing

columns = (Int[1,2,3], Float64[1.,2.,3.], String["John", "Sally", "Drew"])
columns = (Int[1, 2, 3], Float64[1., 2., 3.], String["John", "Sally", "Drew"])
names = [:children, :age, :name]

it = TableTraitsUtils.create_tableiterator(columns, names)
Expand All @@ -37,7 +37,7 @@ include("test_source_without_length.jl")

columns3, names3 = TableTraitsUtils.create_columns_from_iterabletable(it, sel_cols=:all)

columns23, names23 = TableTraitsUtils.create_columns_from_iterabletable(it, sel_cols=[2,3])
columns23, names23 = TableTraitsUtils.create_columns_from_iterabletable(it, sel_cols=[2, 3])

@test columns[1] == columns2[1] == columns3[1]
@test columns[2] == columns2[2] == columns3[2]
Expand All @@ -50,48 +50,48 @@ include("test_source_without_length.jl")
@test names == names2 == names3
@test names[2:3] == names23

@test isequal(create_columns_from_iterabletable([(a = DataValue{Any}(), b = DataValue{Int}())], na_representation=:missing),
([Any[missing], Union{Missing,Int}[missing]], [:a, :b])
)
@test isequal(create_columns_from_iterabletable([(a=DataValue{Any}(), b=DataValue{Int}())], na_representation=:missing),
([Any[missing], Union{Missing,Int}[missing]], [:a, :b])
)

@test create_columns_from_iterabletable([(a = DataValue{Any}(), b = DataValue{Int}())], na_representation=:datavalue) ==
([DataValue{Any}[NA], DataValue{Int}[NA]], [:a, :b])
@test create_columns_from_iterabletable([(a=DataValue{Any}(), b=DataValue{Int}())], na_representation=:datavalue) ==
([DataValue{Any}[NA], DataValue{Int}[NA]], [:a, :b])

it2 = TestSourceWithoutLength()

columns4, names4 = TableTraitsUtils.create_columns_from_iterabletable(it2)
@test columns4[1] == [1,2]
@test columns4[2] == [1.,2.]
@test columns4[1] == [1, 2]
@test columns4[2] == [1., 2.]
@test names4 == [:a, :b]

columns5, names5 = TableTraitsUtils.create_columns_from_iterabletable(it2, sel_cols=:all)
@test columns5[1] == [1,2]
@test columns5[2] == [1.,2.]
@test columns5[1] == [1, 2]
@test columns5[2] == [1., 2.]
@test names5 == [:a, :b]

columns6, names6 = TableTraitsUtils.create_columns_from_iterabletable(it2, sel_cols=[2])
@test columns6[1] == [1.,2.]
@test columns6[1] == [1., 2.]
@test names6 == [:b]

columns_with_nulls = (Union{Int,Missing}[3, 2, missing], Float64[2.,5.,9.], Union{String,Missing}["a", missing, "b"])
columns_with_nulls = (Union{Int,Missing}[3, 2, missing], Float64[2., 5., 9.], Union{String,Missing}["a", missing, "b"])
it3 = TableTraitsUtils.create_tableiterator(columns_with_nulls, names)

columns7, names7 = TableTraitsUtils.create_columns_from_iterabletable(it3)

@test columns7[1] == [3,2,NA]
@test columns7[2] == [2.,5.,9.]
@test columns7[3] == ["a",NA,"b"]
@test columns7[1] == [3, 2, NA]
@test columns7[2] == [2., 5., 9.]
@test columns7[3] == ["a", NA, "b"]
@test length(columns7) == 3
@test names7 == names

columns_with_DV = ([3, 2, NA], [2.,5.,9.], ["a", NA, "b"])
columns_with_DV = ([3, 2, NA], [2., 5., 9.], ["a", NA, "b"])
it4 = TableTraitsUtils.create_tableiterator(columns_with_DV, names)

columns8, names8 = TableTraitsUtils.create_columns_from_iterabletable(it4)

@test columns8[1] == [3,2,NA]
@test columns8[2] == [2.,5.,9.]
@test columns8[3] == ["a",NA,"b"]
@test columns8[1] == [3, 2, NA]
@test columns8[2] == [2., 5., 9.]
@test columns8[3] == ["a", NA, "b"]
@test length(columns8) == 3
@test names8 == names

Expand Down
6 changes: 3 additions & 3 deletions test/test_source_without_length.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ function Base.eltype(iter::TestSourceWithoutLength)
return NamedTuple{(:a, :b),Tuple{Int,Float64}}
end

Base.IteratorSize(::Type{T}) where {T <: TestSourceWithoutLength} = Base.SizeUnknown()
Base.IteratorSize(::Type{T}) where {T<:TestSourceWithoutLength} = Base.SizeUnknown()

function Base.iterate(iter::TestSourceWithoutLength, state=1)
if state == 1
return (a = 1, b = 1.), 2
return (a=1, b=1.), 2
elseif state == 2
return (a = 2, b = 2.), 3
return (a=2, b=2.), 3
else
return nothing
end
Expand Down

0 comments on commit 7bfb765

Please sign in to comment.