-
Notifications
You must be signed in to change notification settings - Fork 55
/
parsing.jl
132 lines (90 loc) · 2.65 KB
/
parsing.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
module TestParsing
using Test
using DataFramesMeta
using Statistics
const ≅ = isequal
macro protect(x)
esc(DataFramesMeta.get_column_expr(x))
end
@testset "Returning column identifiers" begin
v_sym = @protect $[:a, :b]
@test v_sym == [:a, :b]
v_str = @protect $["a", "b"]
@test v_str == ["a", "b"]
qn = @protect :x
@test qn == :x
qn_protect = @protect $:x
@test qn_protect == :x
str_protect = @protect $"x"
@test str_protect == "x"
x = "a"
sym_protect = @protect $x
@test sym_protect === "a"
v = ["a", "b"]
v_protect = @protect $v
@test v === v_protect
b = @protect $(Between(:a, :b))
@test b == Between(:a, :b)
b = @protect $(begin 1 end)
@test b == 1
c = @protect cols(:a)
@test c == :a
i = @protect $1
@test i == 1
n = @protect "hello"
@test n === nothing
n = @protect 1
@test n === nothing
n = @protect begin x end
@test n === nothing
n = @protect x
@test n === nothing
end
@testset "broadcasted binary operators" begin
df = DataFrame(x = [1, 2], y = [3, 4])
df2 = @select df :z = first(:x .+ :y)
@test df2 == DataFrame(z = [4, 4])
df2 = @by df :x :y = first(:y .* :y)
@test df2 == DataFrame(x = [1, 2], y = [9, 16])
df2 = @select df :y = first(last(:y))
@test df2 == DataFrame(y = [4, 4])
df2 = @select df :z = .+(:x)
@test df2 == DataFrame(z = [1, 2])
df2 = @select df :z = .+(first(:x))
@test df2 == DataFrame(z = [1, 1])
df2 = @select df :z = first(.*(:x))
@test df2 == DataFrame(z = 1)
df2 = @select df :z = .+(.*(:x))
@test df2 == DataFrame(z = 1)
df2 = @select df :z = .+(.*(:x, :y))
@test df2 == DataFrame(z = 2)
@test df2 == DataFrame(y = 2)
df = DataFrame(
x = [1, 1, 2, 2, 3, 3],
y = [true, false, true, false, true, false],
z = [true, true, true, false, false, false])
df2 = @by(df,
:x,
:a = maximum(:y .* :z))
@test df2 == DataFrame(x = [1, 2, 3], a = [true, true, false])
end
@testset "caret bug #333" begin
df = DataFrame(a = 1)
res = DataFrame(a = 1, b_sym = :xxx)
df2 = @transform df :b_sym = ^(:xxx)
@test df2 == res
df2 = @select df begin
:a
:b_sym = ^(:xxx)
end
@test df2 == res
df2 = @rsubset df begin ^(true) end
@test df2 == df
@eval df = DataFrame(a = 1)
# Some errors when we don't have keyword arguments, since
# the following gets parsed as (a^b) and we want
# (a, b...) in @subset and (a, b) in @with
@test_throws MethodError @eval @rsubset df ^(true)
@test_throws LoadError @eval @with df ^(true)
end
end # module