Skip to content

Commit 7fa794b

Browse files
authored
Add operator kwarg to Cols (#58)
1 parent 69313ee commit 7fa794b

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DataAPI"
22
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
33
authors = ["quinnj <[email protected]>"]
4-
version = "1.13.0"
4+
version = "1.14.0"
55

66
[compat]
77
julia = "1"

src/DataAPI.jl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ Between(x::Union{Int, Symbol}, y::AbstractString) = Between(x, Symbol(y))
183183
Between(x::AbstractString, y::Union{Int, Symbol}) = Between(Symbol(x), y)
184184

185185
"""
186-
All(cols...)
186+
All()
187187
188-
Select the union of the selections in `cols`. If `cols == ()`, select all columns.
188+
Select all columns.
189189
"""
190190
struct All{T<:Tuple}
191191
cols::T
@@ -198,17 +198,24 @@ struct All{T<:Tuple}
198198
end
199199

200200
"""
201-
Cols(cols...)
202-
Cols(f::Function)
201+
Cols(cols...; operator=union)
202+
Cols(f::Function; operator=union)
203203
204-
Select the union of the selections in `cols`. If `cols == ()`, select no columns.
204+
Select columns matching specifications in `cols`. If `cols == ()`, select no columns.
205205
206206
If the only positional argument is a `Function` `f` then select the columns whose
207207
names passed to the `f` predicate as strings return `true`.
208+
209+
When multiple `cols` selectors are passed then the sets of columns selected by them
210+
are passed to `operator` as positional arguments.
211+
`operator` should be a set operation function, like `union`, `intersect`, `setdiff`, and `symdiff`
212+
defined in Base Julia. By default `operator=union` in which case all columns matching
213+
at least one selector are returned.
208214
"""
209215
struct Cols{T<:Tuple}
210216
cols::T
211-
Cols(args...) = new{typeof(args)}(args)
217+
operator
218+
Cols(args...; operator=union) = new{typeof(args)}(args, operator)
212219
end
213220

214221
"""

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ end
249249
(Ref(DataAPI.BroadcastedSelector(v())) .=> [sum, float])
250250
end
251251

252+
@test DataAPI.Cols(:a, operator=union).operator == union
253+
@test DataAPI.Cols(:a, operator=intersect).operator == intersect
252254
end
253255

254256
@testset "unwrap" begin

0 commit comments

Comments
 (0)