question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pass symbol to Julia function

See original GitHub issue

I 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:open
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
tkfcommented, Jul 12, 2019

This is a PyCall issue https://github.com/JuliaPy/PyCall.jl/issues/11

jl = Julia(compiled_modules=False)
M.costs = costs
ctree=jl.eval('hclust(costs, linkage=:ward)')

If you need to call hclust many times, a slightly better workaround than mutating the global variable in Main is to create a (anonymous) function on the Julia side:

hclust = jl.eval("costs -> hclust(costs, linkage=:ward)")
hclust(costs)
0reactions
sibyjackgrovecommented, Dec 8, 2021

@jdupl123 Thank you for the solution. I think using the Main.eval is the best way to go.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found