Closed lmiq closed 2 years ago
Indeed, you can see from the error message that the python_list
has been converted to a PyIterable
which is the fallback if conversion to PyArray
fails. And generic iterables do not support setindex!
.
It should indeed be possible to support nested types, but it's fiddly to do in general (e.g. numpy dtypes can use packed or aligned memory layout) so I haven't got around to it yet.
You can now convert numpy arrays with structured dtypes like this to PyArray
(provided the dtype is aligned). This means your code now works:
In [1]: from juliacall import Main as jl
In [2]: jl.seval("""
...: function copy_value(python_list, julia_list)
...: @show python_list julia_list
...: python_list[1] = julia_list[1]
...: end
...: """)
Out[2]: copy_value (generic function with 1 method)
In [3]: import numpy as np
In [4]: python_list = np.array([(0,0.0)], dtype="i,f")
In [5]: julia_list = jl.seval("[(0,0.0)]")
In [6]: python_list[0] = julia_list[0]
In [7]: jl.copy_value(python_list, julia_list)
python_list = Tuple{Int32, Float32}[(0, 0.0)]
julia_list = [(0, 0.0)]
Out[7]: (0, 0.0)
In [8]: python_list
Out[8]: array([(0, 0.)], dtype=[('f0', '<i4'), ('f1', '<f4')])
In [9]: python_list[0] = (1,1.1)
In [10]: python_list
Out[10]: array([(1, 1.1)], dtype=[('f0', '<i4'), ('f1', '<f4')])
In [11]: jl.copy_value(python_list, julia_list)
python_list = Tuple{Int32, Float32}[(1, 1.1)]
julia_list = [(0, 0.0)]
Out[11]: (0, 0.0)
In [12]: python_list
Out[12]: array([(0, 0.)], dtype=[('f0', '<i4'), ('f1', '<f4')])
Assuming tests pass, I'll make a release today.
Minimum example (using
ipython3
).I have a list of tuples
Tuple{Int,Int,Float64}
, and I can copy the values from the julia array to anp.array
of the same type on the python side, but I can't perform this copy of elements on the Julia side, becausesetindex!
is not defined.Would it be possible to support any
isbits
type?