Showing 2 of 5 files from the diff.

@@ -1,33 +1,33 @@
Loading
1 1
# Main entry point
2 -
function create_columns_from_iterabletable(itr; sel_cols=:all, na_representation=:datavalue, errorhandling=:error)
2 +
function create_columns_from_iterabletable(itr; sel_cols = :all, na_representation = :datavalue, errorhandling = :error)
3 3
    in(errorhandling, (:error, :returnvalue)) || throw(ArgumentError("'$errorhandling' is not a valid argument for errorhandling."))
4 4
    in(na_representation, (:datavalue, :missing)) || throw(ArgumentError("'$na_representation' is not a valid argument for na_representation."))
5 5
6 -
    if TableTraits.isiterabletable(itr)===false
7 -
        if errorhandling==:error
6 +
    if TableTraits.isiterabletable(itr) === false
7 +
        if errorhandling == :error
8 8
            throw(ArgumentError("itr is not a table."))
9 -
        elseif errorhandling==:returnvalue
9 +
        elseif errorhandling == :returnvalue
10 10
            return nothing
11 11
        end
12 12
    else
13 13
14 -
        array_factory = if na_representation==:datavalue
15 -
                (t,rows) -> begin
16 -
                    if t <: DataValue
17 -
                        return DataValueArray{eltype(t)}(rows)
18 -
                    else
19 -
                        return Array{t}(undef, rows)
20 -
                    end
14 +
        array_factory = if na_representation == :datavalue
15 +
            (t, rows)->begin
16 +
                if t <: DataValue
17 +
                    return DataValueArray{eltype(t)}(rows)
18 +
                else
19 +
                    return Array{t}(undef, rows)
21 20
                end
22 -
            elseif na_representation==:missing
23 -
                (t,rows) -> begin
24 -
                    if t <: DataValue
25 -
                        return Array{Union{eltype(t),Missing}}(undef, rows)
26 -
                    else
27 -
                        return Array{t}(undef, rows)
28 -
                    end
21 +
            end
22 +
        elseif na_representation == :missing
23 +
            (t, rows)->begin
24 +
                if t <: DataValue
25 +
                    return Array{Union{eltype(t),Missing}}(undef, rows)
26 +
                else
27 +
                    return Array{t}(undef, rows)
29 28
                end
30 29
            end
30 +
        end
31 31
32 32
        itr2 = IteratorInterfaceExtensions.getiterator(itr)
33 33
        return _collect_columns(itr2, Base.IteratorSize(itr2), array_factory, sel_cols, errorhandling)
@@ -37,41 +37,41 @@
Loading
37 37
function collect_empty_columns(itr::T, ::Base.EltypeUnknown, array_factory, sel_cols, errorhandling) where {T}
38 38
    S = Core.Compiler.return_type(first, Tuple{T})
39 39
    if S == Union{} || !(S <: NamedTuple)
40 -
        if errorhandling==:error
40 +
        if errorhandling == :error
41 41
            throw(ArgumentError("itr is not a table."))
42 -
        elseif errorhandling==:returnvalue
42 +
        elseif errorhandling == :returnvalue
43 43
            return nothing
44 44
        end
45 45
    end
46 -
    dest = getdest(S,0, array_factory, sel_cols)
46 +
    dest = getdest(S, 0, array_factory, sel_cols)
47 47
    return collect(values(dest)), collect(keys(dest))
48 48
end
49 49
50 50
function collect_empty_columns(itr::T, ::Base.HasEltype, array_factory, sel_cols, errorhandling) where {T}
51 51
    if eltype(itr) <: NamedTuple
52 -
        dest = getdest(eltype(itr),0, array_factory, sel_cols)
52 +
        dest = getdest(eltype(itr), 0, array_factory, sel_cols)
53 53
        return collect(values(dest)), collect(keys(dest))
54 54
    else
55 -
        if errorhandling==:error
55 +
        if errorhandling == :error
56 56
            throw(ArgumentError("itr is not a table."))
57 -
        elseif errorhandling==:returnvalue
57 +
        elseif errorhandling == :returnvalue
58 58
            return nothing
59 59
        end
60 60
    end
61 61
end
62 62
63 63
function getdest(T, n, array_factory, sel_cols)
64 -
    if sel_cols==:all
65 -
        return NamedTuple{fieldnames(T)}(tuple((array_factory(fieldtype(T,i),n) for i in 1:length(fieldnames(T)))...))
64 +
    if sel_cols == :all
65 +
        return NamedTuple{fieldnames(T)}(tuple((array_factory(fieldtype(T, i), n) for i in 1:length(fieldnames(T)))...))
66 66
    else
67 -
        return NamedTuple{fieldnames(T)}(tuple((i in sel_cols ? array_factory(fieldtype(T,i),n) : nothing for i in 1:length(fieldnames(T)))...))
67 +
        return NamedTuple{fieldnames(T)}(tuple((i in sel_cols ? array_factory(fieldtype(T, i), n) : nothing for i in 1:length(fieldnames(T)))...))
68 68
    end
69 69
end
70 70
71 71
@generated function _setrow(dest::NamedTuple{NAMES,TYPES}, i, el::T) where {T,NAMES,TYPES}
72 72
    push_exprs = Expr(:block)
73 73
    for col_idx in 1:length(fieldnames(T))
74 -
        if fieldtype(TYPES, col_idx)!==Nothing
74 +
        if fieldtype(TYPES, col_idx) !== Nothing
75 75
            if fieldtype(TYPES, col_idx) == Array{Any,1} && fieldtype(T, col_idx) == DataValue{Any}
76 76
                ex = :( dest[$col_idx][i] = get(el[$col_idx], missing) )
77 77
            else
@@ -87,7 +87,7 @@
Loading
87 87
@generated function _pushrow(dest::NamedTuple{NAMES,TYPES}, el::T) where {T,NAMES,TYPES}
88 88
    push_exprs = Expr(:block)
89 89
    for col_idx in 1:length(fieldnames(T))
90 -
        if fieldtype(TYPES, col_idx)!==Nothing
90 +
        if fieldtype(TYPES, col_idx) !== Nothing
91 91
            if fieldtype(TYPES, col_idx) == Array{Any,1} && fieldtype(T, col_idx) == DataValue{Any}
92 92
                ex = :( push!(dest[$col_idx], get(el[$col_idx], missing)) )
93 93
            else
@@ -100,38 +100,38 @@
Loading
100 100
    return push_exprs
101 101
end
102 102
103 -
function _collect_columns(itr, ::Union{Base.HasShape, Base.HasLength}, array_factory, sel_cols, errorhandling)
103 +
function _collect_columns(itr, ::Union{Base.HasShape,Base.HasLength}, array_factory, sel_cols, errorhandling)
104 104
    y = iterate(itr)
105 -
    y===nothing && return collect_empty_columns(itr, Base.IteratorEltype(itr), array_factory, sel_cols, errorhandling)
105 +
    y === nothing && return collect_empty_columns(itr, Base.IteratorEltype(itr), array_factory, sel_cols, errorhandling)
106 106
107 -
    if !(typeof(y[1])<:NamedTuple)
108 -
        if errorhandling==:error
107 +
    if !(typeof(y[1]) <: NamedTuple)
108 +
        if errorhandling == :error
109 109
            throw(ArgumentError("itr is not a table."))
110 -
        elseif errorhandling==:returnvalue
110 +
        elseif errorhandling == :returnvalue
111 111
            return nothing
112 112
        end
113 113
    end
114 114
115 115
    dest = getdest(typeof(y[1]), length(itr), array_factory, sel_cols)
116 116
117 -
    _setrow(dest,1,y[1])
117 +
    _setrow(dest, 1, y[1])
118 118
119 119
    _collect_to_columns!(dest, itr, 2, y[2], sel_cols, errorhandling)
120 120
end
121 121
122 -
function _collect_to_columns!(dest::T, itr, offs, st, sel_cols, errorhandling) where {T<:NamedTuple}
122 +
function _collect_to_columns!(dest::T, itr, offs, st, sel_cols, errorhandling) where {T <: NamedTuple}
123 123
    i = offs
124 -
    y = iterate(itr,st)
125 -
    while y!==nothing
126 -
        _setrow(dest,i,y[1])
124 +
    y = iterate(itr, st)
125 +
    while y !== nothing
126 +
        _setrow(dest, i, y[1])
127 127
        i += 1
128 -
        y = iterate(itr,y[2])
128 +
        y = iterate(itr, y[2])
129 129
    end
130 130
131 -
    if sel_cols==:all
131 +
    if sel_cols == :all
132 132
        return collect(values(dest)), collect(keys(dest))
133 133
    else
134 -
        names_to_use = tuple((fieldname(T,i) for i in sel_cols)...)
134 +
        names_to_use = tuple((fieldname(T, i) for i in sel_cols)...)
135 135
        r = NamedTuple{names_to_use}(dest)
136 136
        return collect(values(r)), collect(keys(r))
137 137
    end
@@ -139,34 +139,34 @@
Loading
139 139
140 140
function _collect_columns(itr, ::Base.SizeUnknown, array_factory, sel_cols, errorhandling)
141 141
    y = iterate(itr)
142 -
    y===nothing && return collect_empty_columns(itr, Base.IteratorEltype(itr), array_factory, sel_cols, errorhandling)
142 +
    y === nothing && return collect_empty_columns(itr, Base.IteratorEltype(itr), array_factory, sel_cols, errorhandling)
143 143
144 -
    if !(typeof(y[1])<:NamedTuple)
145 -
        if errorhandling==:error
144 +
    if !(typeof(y[1]) <: NamedTuple)
145 +
        if errorhandling == :error
146 146
            throw(ArgumentError("itr is not a table."))
147 -
        elseif errorhandling==:returnvalue
147 +
        elseif errorhandling == :returnvalue
148 148
            return nothing
149 149
        end
150 150
    end
151 151
152 152
    dest = getdest(typeof(y[1]), 1, array_factory, sel_cols)
153 153
154 -
    _setrow(dest,1,y[1])
154 +
    _setrow(dest, 1, y[1])
155 155
156 156
    _grow_to_columns!(dest, itr, y[2], sel_cols, errorhandling)
157 157
end
158 158
159 -
function _grow_to_columns!(dest::T, itr, st, sel_cols, errorhandling) where {T<:NamedTuple}
159 +
function _grow_to_columns!(dest::T, itr, st, sel_cols, errorhandling) where {T <: NamedTuple}
160 160
    y = iterate(itr, st)
161 -
    while y!==nothing
161 +
    while y !== nothing
162 162
        _pushrow(dest, y[1])
163 -
        y = iterate(itr,y[2])
163 +
        y = iterate(itr, y[2])
164 164
    end
165 165
166 -
    if sel_cols==:all
166 +
    if sel_cols == :all
167 167
        return collect(values(dest)), collect(keys(dest))
168 168
    else
169 -
        names_to_use = tuple((fieldname(T,i) for i in sel_cols)...)
169 +
        names_to_use = tuple((fieldname(T, i) for i in sel_cols)...)
170 170
        r = NamedTuple{names_to_use}(dest)
171 171
        return collect(values(r)), collect(keys(r))
172 172
    end

@@ -6,7 +6,7 @@
Loading
6 6
7 7
# T is the type of the elements produced
8 8
# TS is a tuple type that stores the columns of the table
9 -
struct TableIterator{T, TS}
9 +
struct TableIterator{T,TS}
10 10
    columns::TS
11 11
end
12 12
@@ -19,19 +19,19 @@
Loading
19 19
            push!(field_types, i)
20 20
        end
21 21
    end
22 -
    return TableIterator{NamedTuple{(names...,), Tuple{field_types...}}, Tuple{typeof.(columns)...}}((columns...,))
22 +
    return TableIterator{NamedTuple{(names...,),Tuple{field_types...}},Tuple{typeof.(columns)...}}((columns...,))
23 23
end
24 24
25 25
function Base.length(iter::TableIterator{T,TS}) where {T,TS}
26 -
    return length(iter.columns)==0 ? 0 : length(iter.columns[1])
26 +
    return length(iter.columns) == 0 ? 0 : length(iter.columns[1])
27 27
end
28 28
29 29
Base.eltype(::Type{TableIterator{T,TS}}) where {T,TS} = T
30 30
31 -
@generated function Base.iterate(iter::TableIterator{T,TS}, state=1) where {T,TS}
31 +
@generated function Base.iterate(iter::TableIterator{T,TS}, state = 1) where {T,TS}
32 32
    columns = map(1:length(TS.parameters)) do i
33 -
        if fieldtype(T,i) <: DataValue && eltype(TS.parameters[i]) >: Missing
34 -
            return :($(fieldtype(T,i))(iter.columns[$i][state]))
33 +
        if fieldtype(T, i) <: DataValue && eltype(TS.parameters[i]) >: Missing
34 +
            return :($(fieldtype(T, i))(iter.columns[$i][state]))
35 35
        else
36 36
            return :(iter.columns[$i][state])
37 37
        end
@@ -39,8 +39,8 @@
Loading
39 39
    return quote
40 40
        if state > length(iter)
41 41
            return nothing
42 -
        else            
43 -
            return $(T)(($(columns...),)), state+1
42 +
        else
43 +
            return $(T)(($(columns...),)), state + 1
44 44
        end
45 45
    end
46 46
end
Files Coverage
src 93.14%
Project Totals (2 files) 93.14%
Untitled
Untitled
Untitled
Untitled
Untitled
Untitled
Untitled
Untitled
Untitled
Untitled
Untitled
Untitled
Untitled
Untitled
Untitled
Untitled
Untitled
Untitled
Untitled
Untitled

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading