From 7bfb7658cfae872f8be2ab561884f5c5b1ca4c2d Mon Sep 17 00:00:00 2001 From: davidanthoff Date: Fri, 29 Dec 2023 03:23:09 +0000 Subject: [PATCH] Format files using DocumentFormat --- docs/make.jl | 8 ++--- src/collect1.jl | 12 +++---- test/runtests.jl | 56 +++++++++++++++--------------- test/test_source_without_length.jl | 6 ++-- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 1d7c752..a73f795 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -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" ] ) diff --git a/src/collect1.jl b/src/collect1.jl index 6106ada..7acb2b3 100644 --- a/src/collect1.jl +++ b/src/collect1.jl @@ -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 @@ -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 @@ -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 @@ -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]) diff --git a/test/runtests.jl b/test/runtests.jl index c01802d..eb1c9fa 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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) @@ -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) @@ -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] @@ -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 diff --git a/test/test_source_without_length.jl b/test/test_source_without_length.jl index 24e72e1..34e0f87 100644 --- a/test/test_source_without_length.jl +++ b/test/test_source_without_length.jl @@ -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