Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle functors when auto-generating column names #2934

Merged
merged 3 commits into from
Nov 11, 2021

Conversation

bkamins
Copy link
Member

@bkamins bkamins commented Nov 11, 2021

An interesting corner-case fix of:

julia> struct Identity
       end

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

julia> i = Identity()
Identity()

julia> df = DataFrame(x=1:3)
3×1 DataFrame
 Row │ x
     │ Int64
─────┼───────
   1 │     1
   2 │     2
   3 │     3

julia> combine(df, :x => identity∘i)
ERROR: MethodError: no method matching nameof(::Identity)
Closest candidates are:
  nameof(::Module) at reflection.jl:16
  nameof(::DataType) at reflection.jl:214
  nameof(::UnionAll) at reflection.jl:215
  ...
Stacktrace:
 [1] funname(f::Identity)

@bkamins bkamins requested a review from nalimilan November 11, 2021 09:15
@bkamins bkamins added the bug label Nov 11, 2021
@bkamins bkamins added this to the 1.3 milestone Nov 11, 2021
@bkamins
Copy link
Member Author

bkamins commented Nov 11, 2021

Nightly fails because of JuliaLang/julia#42991.

@@ -120,8 +120,13 @@ function gennames(n::Integer)
end

function funname(f)
n = nameof(f)
String(n)[1] == '#' ? :function : n
try
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better use applicable rather than try?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok - changed

@bkamins bkamins merged commit 585a3fc into main Nov 11, 2021
@bkamins bkamins deleted the bk/functors_nameof branch November 11, 2021 19:20
@bkamins
Copy link
Member Author

bkamins commented Nov 11, 2021

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants