-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbyrow.jl
294 lines (218 loc) · 21.3 KB
/
byrow.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
struct _DUMMY_STRUCT
end
# anymissing(::_DUMMY_STRUCT) = false
nunique(::_DUMMY_STRUCT) = false
stdze!(::_DUMMY_STRUCT) = false
stdze(::_DUMMY_STRUCT) = false
select(::_DUMMY_STRUCT) = false
byrow(ds::AbstractDataset, ::typeof(Base.sum), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); by = identity, threads = nrow(ds) > Threads.nthreads()*10) = row_sum(ds, by, cols, threads = threads)
byrow(ds::AbstractDataset, ::typeof(Base.sum), col::ColumnIndex; by = identity, threads = nrow(ds) > Threads.nthreads()*10) = byrow(ds, sum, [col]; by = by, threads = threads)
byrow(ds::AbstractDataset, ::typeof(IMD.sum), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); by = identity, threads = nrow(ds) > Threads.nthreads()*10) = row_sum(ds, by, cols, threads = threads)
byrow(ds::AbstractDataset, ::typeof(IMD.sum), col::ColumnIndex; by = identity, threads = nrow(ds) > Threads.nthreads()*10) = byrow(ds, sum, [col]; by = by, threads = threads)
byrow(ds::AbstractDataset, ::typeof(prod), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); by = identity, threads = nrow(ds) > Threads.nthreads()*10) = row_prod(ds, by, cols; threads = threads)
byrow(ds::AbstractDataset, ::typeof(prod), col::ColumnIndex; by = identity, threads = nrow(ds) > Threads.nthreads()*10) = byrow(ds, prod, [col]; by = by, threads = threads)
byrow(ds::AbstractDataset, ::typeof(count), cols::MultiColumnIndex = :; by = isequal(true), threads = nrow(ds) > Threads.nthreads()*10) = row_count(ds, by, cols; threads =threads)
byrow(ds::AbstractDataset, ::typeof(count), col::ColumnIndex; by = isequal(true), threads = nrow(ds) > Threads.nthreads()*10) = byrow(ds, count, [col], by = by, threads = threads)
# byrow(ds::AbstractDataset, ::typeof(anymissing), cols::MultiColumnIndex = names(ds, Union{Missing, Number})) = row_anymissing(ds, cols)
function expand_Base_Fix(f, f2)
if f isa Base.Fix2
return _bool(x->f.f(f2(x), f.x))
elseif f isa Base.Fix1
return _bool(x->f.f(f.x, f2(x)))
else
return x->f(f2(x))
end
end
_check_missing(x, missings) = ismissing(x) ? missings : x
function expand_Base_Fix(f, f2, missings)
if f isa Base.Fix2
return _bool(x->_check_missing(f.f(f2(x), f.x), missings))
elseif f isa Base.Fix1
return _bool(x->_check_missing(f.f(f.x,f2(x)), missings))
else
return x->_check_missing(f(f2(x)), missings)
end
end
function byrow(ds::AbstractDataset, ::typeof(any), cols::MultiColumnIndex = :; missings = missing, by = isequal(true), threads = nrow(ds) > Threads.nthreads()*10, mapformats = false)
colsidx = multiple_getindex(index(ds), cols)
if by isa AbstractVector
if mapformats
if !ismissing(missings)
by = map((x,y)->expand_Base_Fix(x, getformat(ds, y), missings), by, colsidx)
else
by = map((x,y)->expand_Base_Fix(x, getformat(ds, y)), by, colsidx)
end
else
if !ismissing(missings)
by = map(y -> x -> ismissing(x) ? missings : y(x), by)
end
end
else
if mapformats
if !ismissing(missings)
by = map(y->expand_Base_Fix(by, getformat(ds, y), missings), colsidx)
else
by = map(y->expand_Base_Fix(by, getformat(ds, y)), colsidx)
end
else
if !ismissing(missings)
by = first(map(y -> x -> ismissing(x) ? missings : y(x), [by]))
end
end
end
row_any(ds, by, colsidx, threads = threads)
end
byrow(ds::AbstractDataset, ::typeof(any), col::ColumnIndex; missings = missing, by = isequal(true), threads = nrow(ds) > Threads.nthreads()*10, mapformats = false) = byrow(ds, any, [col]; missings = missings, by = by, threads = threads, mapformats = mapformats)
function byrow(ds::AbstractDataset, ::typeof(all), cols::MultiColumnIndex = :; missings = missing, by = isequal(true), threads = nrow(ds) > Threads.nthreads()*10, mapformats = false)
colsidx = multiple_getindex(index(ds), cols)
if by isa AbstractVector
if mapformats
if !ismissing(missings)
by = map((x,y)->expand_Base_Fix(x, getformat(ds, y), missings), by, colsidx)
else
by = map((x,y)->expand_Base_Fix(x, getformat(ds, y)), by, colsidx)
end
else
if !ismissing(missings)
by = map(y -> x -> ismissing(x) ? missings : y(x), by)
end
end
else
if mapformats
if !ismissing(missings)
by = map(y->expand_Base_Fix(by, getformat(ds, y), missings), colsidx)
else
by = map(y->expand_Base_Fix(by, getformat(ds, y)), colsidx)
end
else
if !ismissing(missings)
by = first(map(y -> x -> ismissing(x) ? missings : y(x), [by]))
end
end
end
row_all(ds, by, colsidx, threads = threads)
end
byrow(ds::AbstractDataset, ::typeof(all), col::ColumnIndex; missings = missing, by = isequal(true), threads = nrow(ds) > Threads.nthreads()*10, mapformats = false) = byrow(ds, all, [col]; missings = missings, by = by, threads = threads, mapformats = mapformats)
byrow(ds::AbstractDataset, ::typeof(isequal), cols::MultiColumnIndex; with = nothing, threads = nrow(ds) > Threads.nthreads()*10) = row_isequal(ds, cols, by = with, threads = threads)
byrow(ds::AbstractDataset, ::typeof(isequal), cols::ColumnIndex; with = nothing, threads = nrow(ds) > Threads.nthreads()*10) = row_isequal(ds, cols, by = with, threads = threads)
if VERSION >= v"1.8"
byrow(ds::AbstractDataset, ::typeof(allequal), cols::MultiColumnIndex; threads = nrow(ds) > Threads.nthreads()*10) = row_isequal(ds, cols, by = nothing, threads = threads)
byrow(ds::AbstractDataset, ::typeof(allequal), cols::ColumnIndex; threads = nrow(ds) > Threads.nthreads()*10) = row_isequal(ds, cols, by = nothing, threads = threads)
end
byrow(ds::AbstractDataset, ::typeof(isless), cols::MultiColumnIndex; with, threads = nrow(ds) > Threads.nthreads()*10, rev::Bool = false, lt = isless) = row_isless(ds, cols, with, threads = threads, rev = rev, lt = lt)
byrow(ds::AbstractDataset, ::typeof(isless), col::ColumnIndex; with, threads = nrow(ds) > Threads.nthreads()*10, rev::Bool = false, lt = isless) = row_isless(ds, [col], with, threads = threads, rev = rev, lt = lt)
byrow(ds::AbstractDataset, ::typeof(in), cols::MultiColumnIndex; item, threads = nrow(ds) > Threads.nthreads()*10, eq = isequal) = row_in(ds, cols, item; threads = threads, eq = eq)
byrow(ds::AbstractDataset, ::typeof(findfirst), cols::MultiColumnIndex; by = identity, threads = nrow(ds) > Threads.nthreads()*10, item = nothing, eq = isequal) = row_findfirst(ds, by, cols; threads = threads, item = item, eq = eq)
byrow(ds::AbstractDataset, ::typeof(findlast), cols::MultiColumnIndex; by = identity, threads = nrow(ds) > Threads.nthreads()*10, item = nothing, eq = isequal) = row_findlast(ds, by, cols; threads = threads, item = item, eq = eq)
byrow(ds::AbstractDataset, ::typeof(select), cols::MultiColumnIndex; with, threads = nrow(ds) > Threads.nthreads()*10) = row_select(ds, cols, with, threads = threads)
byrow(ds::AbstractDataset, ::typeof(fill!), cols::MultiColumnIndex; with , by = ismissing, threads = nrow(ds) > Threads.nthreads()*10, rolling = false) = row_fill!(ds, cols, with, f = by, threads = threads, rolling = rolling)
byrow(ds::AbstractDataset, ::typeof(fill!), col::ColumnIndex; with , by = ismissing, threads = nrow(ds) > Threads.nthreads()*10, rolling = false) = byrow(ds, fill!, [col], with = with, by = by, threads = threads, rolling = rolling)
byrow(ds::AbstractDataset, ::typeof(fill), cols::MultiColumnIndex; with , by = ismissing, threads = nrow(ds) > Threads.nthreads()*10, rolling = false) = row_fill!(copy(ds), cols, with, f = by, threads = threads, rolling = rolling)
byrow(ds::AbstractDataset, ::typeof(fill), col::ColumnIndex; with , by = ismissing, threads = nrow(ds) > Threads.nthreads()*10, rolling = false) = byrow(copy(ds), fill!, [col], with = with, by = by, threads = threads, rolling = rolling)
byrow(ds::AbstractDataset, ::typeof(coalesce), cols::MultiColumnIndex; threads = nrow(ds) > Threads.nthreads()*10) = row_coalesce(ds, cols; threads = threads)
byrow(ds::AbstractDataset, ::typeof(mean), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); by = identity, threads = nrow(ds) > Threads.nthreads()*10) = row_mean(ds, by, cols, threads = threads)
byrow(ds::AbstractDataset, ::typeof(mean), col::ColumnIndex; by = identity, threads = nrow(ds) > Threads.nthreads()*10) = byrow(ds, mean, [col]; by = by, threads = threads)
byrow(ds::AbstractDataset, ::typeof(Base.maximum), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); by = identity, threads = nrow(ds) > Threads.nthreads()*10) = row_maximum(ds, by, cols, threads = threads)
byrow(ds::AbstractDataset, ::typeof(Base.maximum), col::ColumnIndex; by = identity, threads = nrow(ds) > Threads.nthreads()*10) = byrow(ds, maximum, [col]; by = by, threads = threads)
byrow(ds::AbstractDataset, ::typeof(Base.minimum), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); by = identity, threads = nrow(ds) > Threads.nthreads()*10) = row_minimum(ds, by, cols, threads = threads)
byrow(ds::AbstractDataset, ::typeof(Base.minimum), col::ColumnIndex; by = identity, threads = nrow(ds) > Threads.nthreads()*10) = byrow(ds, minimum, [col]; by = by, threads = threads)
byrow(ds::AbstractDataset, ::typeof(Base.argmin), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); by = identity, threads = nrow(ds) > Threads.nthreads()*10) = row_argmin(ds, by, cols, threads = threads)
byrow(ds::AbstractDataset, ::typeof(Base.argmin), col::ColumnIndex; by = identity, threads = nrow(ds) > Threads.nthreads()*10) = byrow(ds, argmin, [col]; by = by, threads = threads)
byrow(ds::AbstractDataset, ::typeof(Base.argmax), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); by = identity, threads = nrow(ds) > Threads.nthreads()*10) = row_argmax(ds, by, cols, threads = threads)
byrow(ds::AbstractDataset, ::typeof(Base.argmax), col::ColumnIndex; by = identity, threads = nrow(ds) > Threads.nthreads()*10) = byrow(ds, argmax, [col]; by = by, threads = threads)
byrow(ds::AbstractDataset, ::typeof(IMD.maximum), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); by = identity, threads = nrow(ds) > Threads.nthreads()*10) = row_maximum(ds, by, cols, threads = threads)
byrow(ds::AbstractDataset, ::typeof(IMD.maximum), col::ColumnIndex; by = identity, threads = nrow(ds) > Threads.nthreads()*10) = byrow(ds, maximum, [col]; by = by, threads = threads)
byrow(ds::AbstractDataset, ::typeof(IMD.minimum), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); by = identity, threads = nrow(ds) > Threads.nthreads()*10) = row_minimum(ds, by, cols, threads = threads)
byrow(ds::AbstractDataset, ::typeof(IMD.minimum), col::ColumnIndex; by = identity, threads = nrow(ds) > Threads.nthreads()*10) = byrow(ds, minimum, [col]; by = by, threads = threads)
byrow(ds::AbstractDataset, ::typeof(IMD.argmin), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); by = identity, threads = nrow(ds) > Threads.nthreads()*10) = row_argmin(ds, by, cols, threads = threads)
byrow(ds::AbstractDataset, ::typeof(IMD.argmin), col::ColumnIndex; by = identity, threads = nrow(ds) > Threads.nthreads()*10) = byrow(ds, argmin, [col]; by = by, threads = threads)
byrow(ds::AbstractDataset, ::typeof(IMD.argmax), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); by = identity, threads = nrow(ds) > Threads.nthreads()*10) = row_argmax(ds, by, cols, threads = threads)
byrow(ds::AbstractDataset, ::typeof(IMD.argmax), col::ColumnIndex; by = identity, threads = nrow(ds) > Threads.nthreads()*10) = byrow(ds, argmax, [col]; by = by, threads = threads)
byrow(ds::AbstractDataset, ::typeof(var), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); by = identity, dof = true, threads = nrow(ds) > Threads.nthreads()*10) = row_var(ds, by, cols; dof = dof, threads = threads)
byrow(ds::AbstractDataset, ::typeof(var), col::ColumnIndex; by = identity, dof = true, threads = nrow(ds) > Threads.nthreads()*10) = byrow(ds, var, [col]; by = by, dof = dof, threads = threads)
byrow(ds::AbstractDataset, ::typeof(std), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); by = identity, dof = true, threads = nrow(ds) > Threads.nthreads()*10) = row_std(ds, by, cols; dof = dof, threads = threads)
byrow(ds::AbstractDataset, ::typeof(std), col::ColumnIndex; by = identity, dof = true, threads = nrow(ds) > Threads.nthreads()*10) = byrow(ds, std, [col]; by = by, dof = dof, threads = threads)
function byrow(ds::AbstractDataset, ::typeof(nunique), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); by = identity, count_missing = true, threads=nrow(ds)>1000)
res = byrow(ds, x->length(Set(Base.Generator(by, x))), cols, threads=threads)
if count_missing
return res
else
return res .- row_any(ds, ismissing, cols)
end
end
byrow(ds::AbstractDataset, ::typeof(nunique), col::ColumnIndex; by = identity, count_missing = true) = byrow(ds, nunique, [col]; by = by, count_missing = count_missing)
byrow(ds::AbstractDataset, ::typeof(Base.cumsum), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = row_cumsum(ds, cols, missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(Base.cumsum), col::ColumnIndex; missings = :ignore, threads = nrow(ds)> Threads.nthreads()) = byrow(ds, cumsum, [col], missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(Base.cumprod!), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = row_cumprod!(ds, cols, missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(Base.cumprod!), col::ColumnIndex; missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = byrow(ds, cumprod!, [col], missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(Base.cumprod), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = row_cumprod(ds, cols, missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(Base.cumprod), col::ColumnIndex; missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = byrow(ds, cumprod, [col], missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(Base.cumsum!), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = row_cumsum!(ds, cols, missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(Base.cumsum!), col::ColumnIndex; missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = byrow(ds, cumsum!, [col], missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(IMD.cumsum), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = row_cumsum(ds, cols, missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(IMD.cumsum), col::ColumnIndex; missings = :ignore, threads = nrow(ds)> Threads.nthreads()) = byrow(ds, cumsum, [col], missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(IMD.cumprod!), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = row_cumprod!(ds, cols, missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(IMD.cumprod!), col::ColumnIndex; missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = byrow(ds, cumprod!, [col], missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(IMD.cumprod), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = row_cumprod(ds, cols, missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(IMD.cumprod), col::ColumnIndex; missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = byrow(ds, cumprod, [col], missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(IMD.cumsum!), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = row_cumsum!(ds, cols, missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(IMD.cumsum!), col::ColumnIndex; missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = byrow(ds, cumsum!, [col], missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(cummin!), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = row_cummin!(ds, cols, missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(cummin!), col::ColumnIndex; missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = byrow(ds, cummin!, [col], missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(cummin), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = row_cummin(ds, cols, missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(cummin), col::ColumnIndex; missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = byrow(ds, cummin, [col], missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(cummax!), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = row_cummax!(ds, cols, missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(cummax!), col::ColumnIndex; missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = byrow(ds, cummax!, [col], missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(cummax), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = row_cummax(ds, cols, missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(cummax), col::ColumnIndex; missings = :ignore, threads = nrow(ds)>Threads.nthreads()*10) = byrow(ds, cummax, [col], missings = missings, threads = threads)
byrow(ds::AbstractDataset, ::typeof(sort), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); threads = true, kwargs...) = threads ? hp_row_sort(ds, cols; kwargs...) : row_sort(ds, cols; kwargs...)
byrow(ds::AbstractDataset, ::typeof(sort), col::ColumnIndex; threads = true, kwargs...) = byrow(ds, sort, [col]; threads = threads, kwargs...)
byrow(ds::AbstractDataset, ::typeof(sort!), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); threads = true, kwargs...) = threads ? hp_row_sort!(ds, cols; kwargs...) : row_sort!(ds, cols; kwargs...)
# byrow(ds::AbstractDataset, ::typeof(sort!), col::ColumnIndex; threads = true, kwargs...) = byrow(ds, sort!, [col]; threads = threads, kwargs...)
byrow(ds::AbstractDataset, ::typeof(issorted), cols::MultiColumnIndex; threads = nrow(ds) > Threads.nthreads()*10, rev = false, lt = isless) = row_issorted(ds, cols; rev = rev, lt = lt, threads = threads)
byrow(ds::AbstractDataset, ::typeof(stdze), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); threads = true) = row_stdze(ds, cols, threads = threads)
byrow(ds::AbstractDataset, ::typeof(stdze!), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); threads = true) = row_stdze!(ds, cols, threads = threads)
function byrow(ds::AbstractDataset, ::typeof(hash), cols::MultiColumnIndex = :; by = identity, mapformats = false, threads = nrow(ds) > Threads.nthreads()*10)
colsidx = multiple_getindex(index(ds), cols)
if mapformats
by = map(y->expand_Base_Fix(by, getformat(ds, y)), colsidx)
end
row_hash(ds, by, cols, threads = threads)
end
byrow(ds::AbstractDataset, ::typeof(hash), col::ColumnIndex; by = identity, mapformats = false, threads = nrow(ds) > Threads.nthreads()*10) = byrow(ds, hash, [col]; by = by, mapformats = mapformats, threads = threads)
byrow(ds::AbstractDataset, ::typeof(join), col::MultiColumnIndex; threads = nrow(ds) > Threads.nthreads()*10, delim = "", last = "") = row_join(ds, col, threads = threads, delim = delim, last = last)
byrow(ds::AbstractDataset, ::typeof(mapreduce), cols::MultiColumnIndex = names(ds, Union{Missing, Number}); op = .+, f = identity, init = _missings(mapreduce(eltype, promote_type, view(_columns(ds),index(ds)[cols])), nrow(ds)), kwargs...) = mapreduce(f, op, eachcol(ds[!, cols]), init = init; kwargs...)
function byrow(ds::AbstractDataset, f::Function, cols::MultiColumnIndex; threads = nrow(ds)>1000)
colsidx = multiple_getindex(index(ds), cols)
length(colsidx) == 1 && return byrow(ds, f, colsidx[1]; threads = threads)
threads ? hp_row_generic(ds, f, cols) : row_generic(ds, f, cols)
end
# TODO do we need to make sure that the result is Union of Missing?
function byrow(ds::AbstractDataset, f::Function, cols::NTuple{N, ColumnIndex}) where N
cols_idx = [index(ds)[cols[i]] for i in 1:length(cols)]
f.(view(_columns(ds), cols_idx)...)
end
function byrow(ds::AbstractDataset, f::Function, col::ColumnIndex; threads = nrow(ds)>1000, allowmissing::Bool = true)
if threads
T = Core.Compiler.return_type(f, Tuple{our_nonmissingtype(eltype(ds[!, col]))})
if allowmissing
res = Vector{Union{Missing, T}}(undef, nrow(ds))
else
res = Vector{T}(undef, nrow(ds))
end
_hp_map_a_function!(res, f, _columns(ds)[index(ds)[col]])
else
T = Core.Compiler.return_type(f, Tuple{our_nonmissingtype(eltype(ds[!, col]))})
if allowmissing
res = Vector{Union{Missing, T}}(undef, nrow(ds))
else
res = Vector{T}(undef, nrow(ds))
end
map!(f, res, _columns(ds)[index(ds)[col]])
end
res
end
# specific path for converting Any to suitable type
byrow(ds::AbstractDataset, ::typeof(identity), col::ColumnIndex) = identity.(_columns(ds)[index(ds)[col]])
# special case for converting the type of a column conveniently
byrow(ds::AbstractDataset, f::Type, col::ColumnIndex) = convert(Vector{Union{Missing, f}}, _columns(ds)[index(ds)[col]])