Skip to content

Commit 8da136b

Browse files
committed
Add Select/Reject constructors with vector
1 parent b1e426f commit 8da136b

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/transforms/select.jl

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ end
1515
Select(cols::NTuple{N,AbstractString}) where {N} =
1616
Select(Symbol.(cols))
1717

18+
Select(cols::AbstractVector) = Select(Tuple(cols))
19+
1820
Select(cols...) = Select(cols)
1921

2022
isrevertible(::Type{<:Select}) = true
@@ -84,6 +86,8 @@ end
8486
Reject(cols::NTuple{N,AbstractString}) where {N} =
8587
Reject(Symbol.(cols))
8688

89+
Reject(cols::AbstractVector) = Reject(Tuple(cols))
90+
8791
Reject(cols...) = Reject(cols)
8892

8993
isrevertible(::Type{<:Reject}) = true

test/transforms.jl

+52
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,32 @@
3131
@test Tables.columnnames(n) == (:e, :c, :b, :a)
3232
tₒ = revert(T, n, c)
3333
@test t == tₒ
34+
35+
# selection with tuples
36+
T = Select((:e, :c, :b, :a))
37+
n, c = apply(T, t)
38+
@test Tables.columnnames(n) == (:e, :c, :b, :a)
39+
tₒ = revert(T, n, c)
40+
@test t == tₒ
41+
42+
# selection with vectors
43+
T = Select([:e, :c, :b, :a])
44+
n, c = apply(T, t)
45+
@test Tables.columnnames(n) == (:e, :c, :b, :a)
46+
tₒ = revert(T, n, c)
47+
@test t == tₒ
48+
49+
# selection with strings
50+
T = Select("d", "c", "b")
51+
n, c = apply(T, t)
52+
@test Tables.columnnames(n) == (:d, :c, :b)
53+
tₒ = revert(T, n, c)
54+
@test t == tₒ
55+
56+
# selection with single column
57+
@test (Select(:a) == Select("a") ==
58+
Select((:a,)) == Select(("a",)) ==
59+
Select([:a]) == Select(["a"]))
3460
end
3561

3662
@testset "Reject" begin
@@ -65,6 +91,32 @@
6591
@test Tables.columnnames(n) == (:d, :f)
6692
tₒ = revert(T, n, c)
6793
@test t == tₒ
94+
95+
# rejection with tuples
96+
T = Reject((:e, :c, :b, :a))
97+
n, c = apply(T, t)
98+
@test Tables.columnnames(n) == (:d, :f)
99+
tₒ = revert(T, n, c)
100+
@test t == tₒ
101+
102+
# rejection with vectors
103+
T = Reject([:e, :c, :b, :a])
104+
n, c = apply(T, t)
105+
@test Tables.columnnames(n) == (:d, :f)
106+
tₒ = revert(T, n, c)
107+
@test t == tₒ
108+
109+
# rejection with strings
110+
T = Reject("d", "c", "b")
111+
n, c = apply(T, t)
112+
@test Tables.columnnames(n) == (:a, :e, :f)
113+
tₒ = revert(T, n, c)
114+
@test t == tₒ
115+
116+
# rejection with single column
117+
@test (Reject(:a) == Reject("a") ==
118+
Reject((:a,)) == Reject(("a",)) ==
119+
Reject([:a]) == Reject(["a"]))
68120
end
69121

70122
@testset "Identity" begin

0 commit comments

Comments
 (0)