Use this guide to help with migrating code from v0.9 to v1.
Comparisons (==, <, etc.) between Python objects Py, or between Py and Number,
used to return Py but now return Bool. The old behaviour was a pun but broke the
Base API behaviour of these functions. These comparisons will now raise an error if the
underlying Python operation does not return bool.
- Instead of
pytruth(Py(3) < Py(5))usePy(3) < Py(5). - Instead of
Py(3) < Py(5)usePy(Py(3) < Py(5)). - Instead of
np.array([1,2,3]) < Py(3)usepylt(np.array([1,2,3]), Py(3)). This is because comparisons on numpy arrays return arrays ofboolrather than a singlebool. - Instead of
pylt(Bool, Py(3), Py(5))you can usePy(3) < Py(5).
This submodule has been changed to closer mimic the Base.GC API.
- Instead of
PythonCall.GC.enable()usePythonCall.GC.enable(true). - Instead of
PythonCall.GC.disable()usePythonCall.GC.enable(false).
PyArray has been reparametrised from PyArray{T,N,L,M,R} to PyArray{T,N,F} where
F is a Tuple of Symbol flags replacing L (now :linear) and M
(now :mutable). The R parameter (the underlying raw type) is removed and now implied
by T.
- Instead of
PyArray{Int,2,true,true,Int}usePyArray{Int,2,(:mutable,:linear)}. - Instead of
PyArray{Bool,1,false,false,Bool}usePyArray{Bool,1,()}. - Instead of
PyArray{Py,2,false,false,PythonCall.Wrap.UnsafePyObject}usePyArray{Py,2,()}.
Because the R parameter is removed, if the underlying array is of Python objects, the
PyArray must have eltype Py. Previously you could construct a PyArray{String} from
such a thing and the elements would be automatically pyconvert(String, element)-ed for
you.
- Instead of
PyArray{String}(x)usepyconvert.(String, PyArray{Py}(x))if you are OK with taking a copy. Or usemappedarray(x->pyconvert(String, x), PyArray{Py}(x))from MappedArrays.jl to emulate the old behaviour. - Same comments for
pyconvert(PyArray{String}, x).
The wrapper types have been renamed.
- Instead of
juliacall.AnyValueusejuliacall.Jl(but see below). - Instead of
juliacall.ArrayValueusejuliacall.JlArray. - Instead of
juliacall.DictValueusejuliacall.JlDict.
Most methods on the Jl class return a Jl now instead of an arbitrary Python object
converted from the Julia return value. This makes generic programming easier and
more closely reflects the behaviour of Py.
- Instead of
jl.seval("1+2")usejl.jl_eval("1+2").jl_to_py(). - Instead of
jl.rand(5)[0]usejl.rand(5)[1].jl_to_py(). Note the shift from 0-based to 1-based indexing - previouslyjl.rand(5)was ajuliacall.VectorValuewhich supported Python 0-based indexing, but nowjl.rand(5)is ajuliacall.Jlwhich supports indexing by passing the arguments directly to Julia, which is 1-based.
Some wrapper types have been removed and can mostly be replaced with Jl.
- Instead of
juliacall.RawValueusejuliacall.Jl, since this behaves much the same now. - Instead of
juliacall.IntegerValue(and other number types) useint,float,complexor other numeric types as appropriate. Alternatively usejuliacall.Jlwhich supports the basic arithmetic and comparison operators, but is not strictly a number. - Instead of
juliacall.ModuleValueusejuliacall.Jl. The only benefit ofModuleValuewas itssevalmethod, which is nowJl.jl_eval. - Instead of
juliacall.TypeValueusejuliacall.Jl. The only benefit ofTypeValuewas that indexing syntax (jl.Vector[jl.Type]) was converted to Julia's curly syntax (Vector{Type}) butJldoes this now (for types).
Methods with the _jl_ prefix are renamed with the jl_ prefix:
- Instead of
x._jl_help()usex.jl_help(). - Instead of
x._jl_display()usex.jl_display().
The seval function is now called jl_eval:
- Instead of
juliacall.Main.seval("1+2")usejuliacall.Main.jl_eval("1+2").
Other methods, functions and attributes removed:
- Instead of
x._jl_raw()usex(if already aJl) orJl(x). This is because the oldAnyValueandRawValueare replaced byJl. - Instead of
juliacall.convert(type, value)usejuliacall.Jl(value, type). - Instead of
juliacall.Pkgyou must import import it yourself, such asjuliacall.Main.jl_eval("using Pkg; Pkg").
On the Julia side, the pyjl function now always returns a Jl, whereas before it
would return one of the more specific wrappers (now called JlDict, JlArray, etc.).
- Instead of
pyjl([1, 2, 3])usepyjlarray([1, 2, 3])if you need aJlArray. - Instead of
pyjl(Dict())usepyjldict(Dict())if you need aJlDict. - Instead of
pyjl(Set())usepyjlset(Set())if you need aJlSet. - Continue to use
pyjlif you are OK with the result being aJl. - Note that
Py([1, 2, 3])still returns aJlArray, etc., onlypyjlitself changed.