Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency implicit type conversion #536

Open
UBCYujia opened this issue Aug 5, 2024 · 0 comments
Open

Inconsistency implicit type conversion #536

UBCYujia opened this issue Aug 5, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@UBCYujia
Copy link

UBCYujia commented Aug 5, 2024

Affects: Both PythonCall and JuliaCall

Describe the bug
I am encountering inconsistent behavior with implicit type conversion when calling a Python function from Julia within a Python file. Specifically, I have observed that the variable 'global_res' is of type 'Julia Float64', whereas res is of type 'Py'. I expected both to be of the same type—Julia Float64—since they are both ultimately handled on the Julia side, where I assumed implicit conversion would occur uniformly. Here is the problematic code segment:

from juliacall import Main as jl

jl.seval("""
using PythonCall
    """)

jl.global_res = 0

def my_test(x):
    jl.global_res = x+1
    return x+1

jl.test_pyexec_fn = my_test

jl.seval("""
        function jl_add(x::Float64)
            res = test_pyexec_fn(x)
            println("typeof res:",typeof(res)) #typeof res:Py
            println("typeof global_res:",typeof(global_res)) #typeof global_res:Float64
            return res
        end
        """)

x = jl.jl_add(2.0)

Your system
Information about my system:

  • The operating system: Linux
  • The versions:
  • Julia:1.10.3,
  • Python:3.9.19,
  • juliacall: 0.9.21,
  • PythonCall v0.9.20

Thank you so much in advance!

@UBCYujia UBCYujia added the bug Something isn't working label Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant