@@ -117,60 +117,53 @@ end
117
117
# end
118
118
119
119
"""
120
- AxisKeys.populate!(A, table, value; force=false, quiet=false )
120
+ AxisKeys.populate!(A, table, value; force=false)
121
121
122
- Populate `A` with the contents of the `value` column in a provided `table`.
123
- The `table` must contain columns corresponding to the keys in `A` and support row iteration.
124
- If the keys in `A` do not uniquely identify rows in the `table` then an
125
- ` ArgumentError` is throw. If `force` is true then the duplicate (non-unique) entries will be
126
- overwritten. Setting `quiet` to true will avoid any non-unique warnings .
122
+ Populate `A` with the contents of the `value` column in a provided `table`, matching the
123
+ [Tables.jl](https://github.com/JuliaData/Tables.jl) API. The `table` must contain columns
124
+ corresponding to the keys in `A` and implements `Tables. rows`. If the keys in `A` do not
125
+ uniquely identify rows in the `table` then an ` ArgumentError` is throw. If `force` is true
126
+ then the duplicate (non-unique) entries will be overwritten .
127
127
"""
128
- function populate! (A, table, value:: Symbol ; force= false , quiet = false )
128
+ function populate! (A, table, value:: Symbol ; force= false )
129
129
# Use a BitArray mask to detect duplicates and error instead of overwriting.
130
- mask = falses (size (A))
131
- overwritten = false
130
+ mask = force ? falses () : falses (size (A))
132
131
133
132
for r in Tables. rows (table)
134
133
vals = Tuple (Tables. getcolumn (r, c) for c in dimnames (A))
135
134
inds = map (findindex, vals, axiskeys (A))
136
135
137
- # Handle duplicate error if applicable
138
- if mask[inds... ]
139
- if force
140
- overwritten = true
141
- else
142
- throw (ArgumentError (" Key $vals is not unique" ))
143
- end
136
+ # Handle duplicate error checking if applicable
137
+ if ! force
138
+ # Error if mask already set.
139
+ mask[inds... ] && throw (ArgumentError (" Key $vals is not unique" ))
140
+ # Set mask, marking that we've set this index
141
+ setindex! (mask, true , inds... )
144
142
end
145
143
146
- # Set or mask marking that we've set this index
147
- setindex! (mask, true , inds... )
148
-
149
144
# Insert our value into the data array
150
145
setindex! (A, Tables. getcolumn (r, value), inds... )
151
146
end
152
147
153
- if overwritten && ! quiet
154
- @warn " Columns $(dimnames (A)) do not uniquely identify rows in the table"
155
- end
156
-
157
148
return A
158
149
end
159
150
160
151
"""
161
- wrapdims(table, [Type,] value, keys...; default=undef, sort=false, force=false, quiet=false)
162
-
163
- Construct a KeyedArray/NamedDimsArray from a `table` supporting column and row.
164
- The `default` value is used in cases where no value is identified for a given keypair.
165
- If the `keys` columns do not uniquely identify rows in the table then an `ArgumentError` is
166
- throw. If `force` is true then the duplicate (non-unique) entries will be
167
- overwritten. Setting `quiet` to true will avoid any non-unique warnings.
152
+ wrapdims(table, value, keys...; default=undef, sort=false, force=false) -> KeyedArray
153
+ wrapdims(T, table, value, keys...; default=undef, sort=false, force=false) -> T
154
+
155
+ Construct a `KeyedArray`/`NamedDimsArray` (specified by type `T`) from a `table` matching
156
+ the [Tables.jl](https://github.com/JuliaData/Tables.jl) API. The `table` should support both
157
+ `Tables.columns` and `Tables.rows`. The `default` value is used in cases where no
158
+ value is identified for a given keypair. If the `keys` columns do not uniquely identify
159
+ rows in the table then an `ArgumentError` is throw. If `force` is true then the duplicate
160
+ (non-unique) entries will be overwritten.
168
161
"""
169
162
function wrapdims (table, value:: Symbol , keys:: Symbol... ; kwargs... )
170
- wrapdims (table, KeyedArray , value, keys... ; kwargs... )
163
+ wrapdims (KeyedArray, table , value, keys... ; kwargs... )
171
164
end
172
165
173
- function wrapdims (table, T:: Type , value:: Symbol , keys:: Symbol... ; default= undef, sort:: Bool = false , kwargs... )
166
+ function wrapdims (T:: Type , table , value:: Symbol , keys:: Symbol... ; default= undef, sort:: Bool = false , kwargs... )
174
167
# get columns of the input table source
175
168
cols = Tables. columns (table)
176
169
0 commit comments