Pass symbol to Julia function
See original GitHub issueI am trying to pass a symbol to the hclust function from http://juliastats.github.io/Clustering.jl/stable/hclust.html
from julia import Clustering as C
result = hclust(costs, linkage=":ward")
I keep getting
TypeError: in #hclust, in typeassert, expected Symbol, got String
I also tried
from julia import Main as M
C.hclust(costs, linkage=M.Symbol('ward'))
but same error. I believe this is because PyCall is converting the symbol to a string before passing it through.
Current work around is:
jl = Julia(compiled_modules=False)
M.costs = costs
ctree=jl.eval('hclust(costs, linkage=:ward)')
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
When should a function accept a symbol as an argument?
I stumbled across two situations where functions accept symbols as arguments, and wonder why they are designed that way.
Read more >Functions · The Julia Language
Julia function arguments follow a convention sometimes called "pass-by-sharing", which means that values are not copied when they are passed to functions.
Read more >Is there a fast way of going from a symbol to a function call ...
In particular, you can just pass around the original function, ... I am relying on the Julia parser to do an initial analysis...
Read more >Introducing Julia/Functions
where the total produced by sum() is passed to the sqrt() function. The equivalent composition is: julia> (sqrt ∘ sum)(1:10) 7.416198487095663.
Read more >How to build a tuple of kwargs to pass to a function in ...
to julia...@googlegroups.com. Hi,. I have a function that takes keyword arguments that I want to call with a macro. I've seen the :kw...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

This is a PyCall issue https://github.com/JuliaPy/PyCall.jl/issues/11
If you need to call
hclustmany times, a slightly better workaround than mutating the global variable inMainis to create a (anonymous) function on the Julia side:@jdupl123 Thank you for the solution. I think using the Main.eval is the best way to go.