@tkf I use joinpath()
as you suggested, and that worked great. So I will use that from now on. At least now I am getting the code to run and it returns a dataframe in raw form :). I am now trying to use the Pandas
package to get the dataframe to return a Dataframe to python, but I am getting a conversion error.
I don’t mean to pull you into debugging my code, but I can post the stacktrace in case you can quickly see what the problem is. To my simple eyes it seems like there is an error when converting to Pandas where the convert method for ::Type{Union{}}
seems to have trouble converting to float. Does the way that this error is written suggest that the Union{}
is ambiguous or Any
since there are no types specified within the Union? NOTE, there are some text fields in the Julia Dataframe–since I needed to remind myself what I did. There are missing values in many of the columns of the Julia DataFrame, and that did not seem to cause any issues when computing on the Julia side–only when doing the Pandas.jl conversion of the Julia Dataframe.
Traceback (most recent call last):
File "test_pythonfile.py", line 50, in <module>
a = Main.run_julia_model(initial_values, 10, 20)
RuntimeError: Julia exception: MethodError: convert(::Type{Union{}}, ::Float64) is ambiguous. Candidates:
convert(::Type{Union{}}, x) in Base at essentials.jl:169
convert(::Type{T}, x::Number) where T<:Number in Base at number.jl:7
convert(::Type{T}, arg) where T<:VecElement in Base at baseext.jl:8
convert(::Type{T}, x::Number) where T<:AbstractChar in Base at char.jl:179
Possible fix, define
convert(::Type{Union{}}, ::Number)
Stacktrace:
[1] setindex!(::Array{Union{},1}, ::Float64, ::Int64) at ./array.jl:825
[2] _construct_pandas_from_iterabletable(::DataFrame) at /home/krishnab/.julia/packages/Pandas/rAPmB/src/tabletraits.jl:37
[3] DataFrame at /home/krishnab/.julia/packages/Pandas/rAPmB/src/Pandas.jl:457 [inlined]
[4] run_julia_model(::Dict{Any,Any}, ::Int64, ::Int64) at /media/krishnab/lakshmi/sandbox/julia/pyjulia/test_julia.jl:6
[5] invokelatest(::Any, ::Any, ::Vararg{Any,N} where N; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at ./essentials.jl:712
[6] invokelatest(::Any, ::Any, ::Vararg{Any,N} where N) at ./essentials.jl:711
[7] _pyjlwrap_call(::Function, ::Ptr{PyCall.PyObject_struct}, ::Ptr{PyCall.PyObject_struct}) at /home/krishnab/.julia/packages/PyCall/zqDXB/src/callback.jl:28
[8] pyjlwrap_call(::Ptr{PyCall.PyObject_struct}, ::Ptr{PyCall.PyObject_struct}, ::Ptr{PyCall.PyObject_struct}) at /home/krishnab/.julia/packages/PyCall/zqDXB/src/callback.jl:49
Here are the original Julia file and Python files.
#test_julia.jl
using DemoInertia
using DataFrames
import Pandas
function run_julia_model(iv::Dict, runs, duration)
Pandas.DataFrame(DemoInertia.get_summaries(iv, runs, duration))
end
The python code. Note that I abbreviated the initial_values
dictionary, as it is actually larger.
# test_python.py
import julia
jl = julia.Julia(compiled_modules=False)
jl.include('test_julia.jl') # my file with functions
from julia import Main
initial_values = {"a": 1,
"b" : "text",
"c" : 3.2}
a = Main.run_julia_model(initial_values, 10, 20)
print(a)