Skip to content

Extremely slow output of julia arrays in Python with juliacall #263

Closed
@VPetukhov

Description

@VPetukhov

I'm wrapping a julia package to a python Jupyter notebook with juliacall. But the data obtained from julia can't be properly visualized in Python, as it takes really long. A minimal example below takes 19s to render if ran in console ipython (and even longer in VSCode, for whatever reason):

from juliacall import Main as jl
jl.rand(10000, 1000)

Same goes for large DataFrames.

Julia version 1.8.5, juliacall version 0.9.7 , python v3.8.0.

Update
From what I understand, the problem comes from pyjlany_repr, which calls repr, which interpolates the whole array into a single string:

import juliacall
len(juliacall.PythonCall.repr(jl.rand(10000, 1000)))

Out[12]: 192706630

So, we get linear dependency on array size. On the other hand, calling juliacall.PythonCall.display(jl.rand(10000, 1000)) works perfectly fine and with reasonable speed.

Is there any way to override the behavior? Honestly, I'd be even fine if we can disable input from Julia objects altogether and require them to be converted to Python first. But the current situation is extremely unfriendly to potential users of my package, as any accidental output of a julia object causes the REPL to hang without any possibility to even interrupt it...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions