Skip to content

Commit c929f56

Browse files
committed
mapformats for byrow with all/any
1 parent 45017d7 commit c929f56

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

src/byrow/byrow.jl

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,56 @@ byrow(ds::AbstractDataset, ::typeof(count), col::ColumnIndex; by = isequal(true)
1919

2020
# byrow(ds::AbstractDataset, ::typeof(anymissing), cols::MultiColumnIndex = names(ds, Union{Missing, Number})) = row_anymissing(ds, cols)
2121

22-
function byrow(ds::AbstractDataset, ::typeof(any), cols::MultiColumnIndex = :; by = x->isequal(true, x), threads = nrow(ds)>1000)
22+
function expand_Base_Fix(f, f2)
23+
if f isa Base.Fix2
24+
return _bool(x->f.f(f2(x), f.x))
25+
elseif f isa Base.Fix1
26+
return _bool(x->f.f(f.x, f2(x)))
27+
else
28+
return x->f(f2(x))
29+
end
30+
end
31+
32+
function byrow(ds::AbstractDataset, ::typeof(any), cols::MultiColumnIndex = :; by = isequal(true), threads = nrow(ds)>1000, mapformats = false)
2333
colsidx = index(ds)[cols]
2434
if by isa AbstractVector
25-
bys = map(_bool, by)
35+
if mapformats
36+
bys = map((x,y)->_bool(z->x(getformat(ds, y)(z))), by, colsidx)
37+
else
38+
bys = map(_bool, by)
39+
end
2640
threads ? hp_row_any_multi(ds, bys, colsidx) : row_any_multi(ds, bys, colsidx)
2741
else
28-
bys = repeat([_bool(by)], length(colsidx))
42+
if mapformats
43+
bys = map(y->_bool(z->by(getformat(ds, y)(z))), colsidx)
44+
else
45+
bys = repeat([_bool(by)], length(colsidx))
46+
end
2947
threads ? hp_row_any_multi(ds, bys, colsidx) : row_any_multi(ds, bys, colsidx)
3048
end
3149
end
3250

33-
byrow(ds::AbstractDataset, ::typeof(any), col::ColumnIndex; by = x->isequal(true, x), threads = nrow(ds)>1000) = byrow(ds, any, [col]; by = by, threads = threads)
51+
byrow(ds::AbstractDataset, ::typeof(any), col::ColumnIndex; by = isequal(true), threads = nrow(ds)>1000, mapformats = false) = byrow(ds, any, [col]; by = by, threads = threads, mapformats = mapformats)
3452

35-
function byrow(ds::AbstractDataset, ::typeof(all), cols::MultiColumnIndex = :; by = x->isequal(true, x), threads = nrow(ds)>1000)
53+
function byrow(ds::AbstractDataset, ::typeof(all), cols::MultiColumnIndex = :; by = isequal(true), threads = nrow(ds)>1000, mapformats = false)
3654
colsidx = index(ds)[cols]
3755
if by isa AbstractVector
38-
bys = map(_bool, by)
56+
if mapformats
57+
bys = map((x,y)->expand_Base_Fix(x, getformat(ds, y)), by, colsidx)
58+
else
59+
bys = map(_bool, by)
60+
end
3961
threads ? hp_row_all_multi(ds, bys, colsidx) : row_all_multi(ds, bys, colsidx)
4062
else
41-
bys = repeat([_bool(by)], length(colsidx))
63+
if mapformats
64+
bys = map(y->expand_Base_Fix(by, getformat(ds, y)), colsidx)
65+
else
66+
bys = repeat([_bool(by)], length(colsidx))
67+
end
4268
threads ? hp_row_all_multi(ds, bys, colsidx) : row_all_multi(ds, bys, colsidx)
4369
end
4470
end
45-
byrow(ds::AbstractDataset, ::typeof(all), col::ColumnIndex; by = x->isequal(true, x), threads = nrow(ds)>1000) = byrow(ds, all, [col]; by = by, threads = threads)
71+
byrow(ds::AbstractDataset, ::typeof(all), col::ColumnIndex; by = isequal(true), threads = nrow(ds)>1000, mapformats = false) = byrow(ds, all, [col]; by = by, threads = threads, mapformats = mapformats)
4672

4773
byrow(ds::AbstractDataset, ::typeof(isequal), cols::MultiColumnIndex; threads = nrow(ds)>1000) = row_isequal(ds, cols, threads = threads)
4874
byrow(ds::AbstractDataset, ::typeof(findfirst), cols::MultiColumnIndex; by = identity, threads = nrow(ds)> 1000) = row_findfirst(ds, by, cols; threads = threads)

0 commit comments

Comments
 (0)