From 1e844aed402c3161f1b4fca98c13ea89d0ff2d1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sun, 4 Dec 2022 23:23:30 +0100 Subject: [PATCH 1/9] Add operation kwarg to Cols x-ref https://github.com/JuliaData/DataFrames.jl/pull/3224 --- src/DataAPI.jl | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/DataAPI.jl b/src/DataAPI.jl index 8e13733..d4c80d1 100644 --- a/src/DataAPI.jl +++ b/src/DataAPI.jl @@ -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 @@ -198,17 +198,27 @@ struct All{T<:Tuple} end """ - Cols(cols...) - Cols(f::Function) + Cols(cols...; operation::Symbol=:union) + Cols(f::Function; operation::Symbol=:union) -Select the union of the selections in `cols`. If `cols == ()`, select no columns. +Select a union of the selections 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`. + +If `operation` keyword argument is passed then it can be either `:union` (the default) +or `:intersect`. If it is `:intersect` then an intersection of the selections +in `cols` is selected. """ struct Cols{T<:Tuple} cols::T - Cols(args...) = new{typeof(args)}(args) + operation::Symbol + function Cols(args...; operation::Symbol=:union) + if !(operation == :union || operation == :intersect) + throw(ArgumentError("operation must be `:union` or `:intersect`")) + end + return new{typeof(args)}(args, operation) + end end """ From e6613e06d057c85021ecd1739ba21307c93a037c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sun, 4 Dec 2022 23:23:50 +0100 Subject: [PATCH 2/9] Update Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index d99b22e..81f9310 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "DataAPI" uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" authors = ["quinnj "] -version = "1.13.0" +version = "1.14.0" [compat] julia = "1" From 2b5f76a150577975205d665f6c48ec785c965ba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sun, 4 Dec 2022 23:25:40 +0100 Subject: [PATCH 3/9] Update runtests.jl --- test/runtests.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 72f0691..1d3e6c1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -249,6 +249,9 @@ end (Ref(DataAPI.BroadcastedSelector(v())) .=> [sum, float]) end + @test DataAPI.Cols(:a, operation=:union).operation == :union + @test DataAPI.Cols(:a, operation=:intersect).operation == :intersect + @test_throws ArgumentError DataAPI.Cols(:a, operation=:bad) end @testset "unwrap" begin From 929e42cae3f141a6442f5fbf92708693fa38b700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sun, 11 Dec 2022 18:23:07 +0100 Subject: [PATCH 4/9] Apply suggestions from code review Co-authored-by: Milan Bouchet-Valat --- src/DataAPI.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/DataAPI.jl b/src/DataAPI.jl index d4c80d1..23a1113 100644 --- a/src/DataAPI.jl +++ b/src/DataAPI.jl @@ -201,14 +201,14 @@ end Cols(cols...; operation::Symbol=:union) Cols(f::Function; operation::Symbol=:union) -Select a 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`. -If `operation` keyword argument is passed then it can be either `:union` (the default) -or `:intersect`. If it is `:intersect` then an intersection of the selections -in `cols` is selected. +When multiple `cols` selectors are passed, if `operation=:union` (the default) +all columns matching at least one selector are returned, and if +`operation=:intersect` only columns matching all selectors are returned. """ struct Cols{T<:Tuple} cols::T From 4c589f4ad209d01bc8470de4c0c6adf205ab2bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sun, 11 Dec 2022 23:45:31 +0100 Subject: [PATCH 5/9] Apply suggestions from code review --- src/DataAPI.jl | 20 +++++++++----------- test/runtests.jl | 5 ++--- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/DataAPI.jl b/src/DataAPI.jl index 23a1113..7f5950a 100644 --- a/src/DataAPI.jl +++ b/src/DataAPI.jl @@ -198,26 +198,24 @@ struct All{T<:Tuple} end """ - Cols(cols...; operation::Symbol=:union) - Cols(f::Function; operation::Symbol=:union) + Cols(cols...; operation=union) + Cols(f::Function; operation=union) 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, if `operation=:union` (the default) -all columns matching at least one selector are returned, and if -`operation=:intersect` only columns matching all selectors are returned. +When multiple `cols` selectors are passed then the sets of columns selected by them +are passed to `operation` callable as positional arguments. +`operation` should be a set operation function, like `union`, `intersect`, `setdiff`, and `symdiff` +defined in Base Julia. By default `operation=union` in which case all columns matching +at least one selector are returned. """ struct Cols{T<:Tuple} cols::T - operation::Symbol - function Cols(args...; operation::Symbol=:union) - if !(operation == :union || operation == :intersect) - throw(ArgumentError("operation must be `:union` or `:intersect`")) - end - return new{typeof(args)}(args, operation) + operation + Cols(args...; operation::Symbol=union) = new{typeof(args)}(args, operation) end end diff --git a/test/runtests.jl b/test/runtests.jl index 1d3e6c1..071d55c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -249,9 +249,8 @@ end (Ref(DataAPI.BroadcastedSelector(v())) .=> [sum, float]) end - @test DataAPI.Cols(:a, operation=:union).operation == :union - @test DataAPI.Cols(:a, operation=:intersect).operation == :intersect - @test_throws ArgumentError DataAPI.Cols(:a, operation=:bad) + @test DataAPI.Cols(:a, operation=union).operation == union + @test DataAPI.Cols(:a, operation=intersect).operation == intersect end @testset "unwrap" begin From 2b9d437fdba2cd5ddcb39420df4785fc44b43547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sun, 11 Dec 2022 23:53:36 +0100 Subject: [PATCH 6/9] Update src/DataAPI.jl --- src/DataAPI.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/DataAPI.jl b/src/DataAPI.jl index 7f5950a..ca617dd 100644 --- a/src/DataAPI.jl +++ b/src/DataAPI.jl @@ -216,7 +216,6 @@ struct Cols{T<:Tuple} cols::T operation Cols(args...; operation::Symbol=union) = new{typeof(args)}(args, operation) - end end """ From 4364843a3d2a7e03795c67698ef4b10d7e16fcc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Mon, 12 Dec 2022 00:44:06 +0100 Subject: [PATCH 7/9] Update src/DataAPI.jl --- src/DataAPI.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DataAPI.jl b/src/DataAPI.jl index ca617dd..91379e9 100644 --- a/src/DataAPI.jl +++ b/src/DataAPI.jl @@ -215,7 +215,7 @@ at least one selector are returned. struct Cols{T<:Tuple} cols::T operation - Cols(args...; operation::Symbol=union) = new{typeof(args)}(args, operation) + Cols(args...; operation=union) = new{typeof(args)}(args, operation) end """ From 698f976d9aa55d2ae19c568b072694d0a8c2eeca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Mon, 12 Dec 2022 23:07:33 +0100 Subject: [PATCH 8/9] Apply suggestions from code review --- src/DataAPI.jl | 14 +++++++------- test/runtests.jl | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/DataAPI.jl b/src/DataAPI.jl index 91379e9..324d6ca 100644 --- a/src/DataAPI.jl +++ b/src/DataAPI.jl @@ -198,8 +198,8 @@ struct All{T<:Tuple} end """ - Cols(cols...; operation=union) - Cols(f::Function; operation=union) + Cols(cols...; operator=union) + Cols(f::Function; operator=union) Select columns matching specifications in `cols`. If `cols == ()`, select no columns. @@ -207,15 +207,15 @@ If the only positional argument is a `Function` `f` then select the columns whos 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 `operation` callable as positional arguments. -`operation` should be a set operation function, like `union`, `intersect`, `setdiff`, and `symdiff` -defined in Base Julia. By default `operation=union` in which case all columns matching +are passed to `operator` callable 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 - operation - Cols(args...; operation=union) = new{typeof(args)}(args, operation) + operator + Cols(args...; operator=union) = new{typeof(args)}(args, operator) end """ diff --git a/test/runtests.jl b/test/runtests.jl index 071d55c..00e56ed 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -249,8 +249,8 @@ end (Ref(DataAPI.BroadcastedSelector(v())) .=> [sum, float]) end - @test DataAPI.Cols(:a, operation=union).operation == union - @test DataAPI.Cols(:a, operation=intersect).operation == intersect + @test DataAPI.Cols(:a, operator=union).operator == union + @test DataAPI.Cols(:a, operator=intersect).operator == intersect end @testset "unwrap" begin From 6fc6ae439552f86f11182bd3a3be4058bb734359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Fri, 16 Dec 2022 13:25:46 +0100 Subject: [PATCH 9/9] Update src/DataAPI.jl Co-authored-by: Milan Bouchet-Valat --- src/DataAPI.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DataAPI.jl b/src/DataAPI.jl index 324d6ca..00af0d0 100644 --- a/src/DataAPI.jl +++ b/src/DataAPI.jl @@ -207,7 +207,7 @@ If the only positional argument is a `Function` `f` then select the columns whos 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` callable as positional arguments. +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.