Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DataAPI"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
authors = ["quinnj <quinn.jacobd@gmail.com>"]
version = "1.13.0"
version = "1.14.0"

[compat]
julia = "1"
Expand Down
19 changes: 13 additions & 6 deletions src/DataAPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ Between(x::Union{Int, Symbol}, y::AbstractString) = Between(x, Symbol(y))
Between(x::AbstractString, y::Union{Int, Symbol}) = Between(Symbol(x), y)

"""
All(cols...)
All()

Select the union of the selections in `cols`. If `cols == ()`, select all columns.
Select all columns.
"""
struct All{T<:Tuple}
cols::T
Expand All @@ -198,17 +198,24 @@ struct All{T<:Tuple}
end

"""
Cols(cols...)
Cols(f::Function)
Cols(cols...; operator=union)
Cols(f::Function; operator=union)

Select the union of the selections in `cols`. If `cols == ()`, select no columns.
Select columns matching specifications in `cols`. If `cols == ()`, select no columns.

If the only positional argument is a `Function` `f` then select the columns whose
names passed to the `f` predicate as strings return `true`.

When multiple `cols` selectors are passed then the sets of columns selected by them
are passed to `operator` as positional arguments.
`operator` should be a set operation function, like `union`, `intersect`, `setdiff`, and `symdiff`
defined in Base Julia. By default `operator=union` in which case all columns matching
at least one selector are returned.
"""
struct Cols{T<:Tuple}
cols::T
Cols(args...) = new{typeof(args)}(args)
operator
Cols(args...; operator=union) = new{typeof(args)}(args, operator)
end

"""
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ end
(Ref(DataAPI.BroadcastedSelector(v())) .=> [sum, float])
end

@test DataAPI.Cols(:a, operator=union).operator == union
@test DataAPI.Cols(:a, operator=intersect).operator == intersect
end

@testset "unwrap" begin
Expand Down