Skip to content

Commit 62ef612

Browse files
committed
add vector support for @pivot_longer
1 parent 3d064bb commit 62ef612

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/parsing.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ function parse_tidy(tidy_expr::Union{Expr,Symbol,Number}; # Can be symbol or exp
3232
endindex = QuoteNode(endindex)
3333
end
3434
return :(Between($startindex, $endindex))
35+
elseif @capture(tidy_expr, names_vect)
36+
return Symbol.(names.args)
37+
elseif @capture(tidy_expr, -names_vect)
38+
return Not(Symbol.(names.args))
3539
elseif @capture(tidy_expr, (lhs_ = fn_(args__)) | (lhs_ = fn_.(args__)))
3640
if length(args) == 0
3741
lhs = QuoteNode(lhs)
@@ -499,4 +503,4 @@ function parse_blocks(exprs...)
499503
return (MacroTools.rmlines(exprs[1]).args...,)
500504
end
501505
return exprs
502-
end
506+
end

test/test_pivots.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,27 @@ end
3030
)
3131
test_long3 = @pivot_longer(test_df, -(name:num))
3232
test_long4 = @pivot_longer(test_df, label)
33+
34+
true_long5 = DataFrame(
35+
name = ["A","B","A","B","A","B","A","B"],
36+
variable = ["label","label","label","label","num","num","num","num"],
37+
value = [1,1,2,2,1,2,3,4],
38+
)
39+
test_long5 = @pivot_longer(test_df, [label,num])
40+
41+
true_long6 = DataFrame(
42+
label = [1,1,2,2],
43+
num = [1,2,3,4],
44+
variable = ["name","name","name","name"],
45+
value = ["A","B","A","B"],
46+
)
47+
test_long6 = @pivot_longer(test_df, -[label,num])
48+
3349
@test all(Array(true_long1 .== test_long1))
3450
@test all(Array(true_long1 .== test_long2))
3551
@test all(Array(true_long3 .== test_long3))
3652
@test all(Array(true_long3 .== test_long4))
53+
@test all(Array(true_long5 .== test_long5))
54+
@test all(Array(true_long6 .== test_long6))
3755
end
3856
end

0 commit comments

Comments
 (0)