Skip to content

Commit

Permalink
Correctly handle functors when auto-generating column names (#2934)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkamins authored Nov 11, 2021
1 parent d686720 commit 585a3fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/other/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,13 @@ function gennames(n::Integer)
end

function funname(f)
n = nameof(f)
String(n)[1] == '#' ? :function : n
if applicable(nameof, f)
n = nameof(f)
return String(n)[1] == '#' ? :function : n
else
# handle the case of functors that do not support nameof
return :function
end
end

funname(c::ComposedFunction) = Symbol(funname(c.outer), :_, funname(c.inner))
Expand Down
14 changes: 14 additions & 0 deletions test/select.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2346,4 +2346,18 @@ end
@test_throws ArgumentError DataFrames.broadcast_pair(df, 1:3 .=> sum .=> Between(:x1, :x2))
end

struct Identity
end

function (::Identity)(x)
return x
end

@testset "correct handling of functors" begin
i = Identity()
df = DataFrame(x=1:3)
@test_throws ArgumentError combine(df, :x => i) # i is not Callable
@test combine(df, :x => identityi) == DataFrame(x_identity_function=1:3)
end

end # module

0 comments on commit 585a3fc

Please sign in to comment.