JuliaPy / JuliaPy/PythonCall.jl

Inconsistency implicit type conversion

未关闭
#536 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
bug
主要语言
Julia
星标
1.1k
派生
86
平均合并
1 天 22 小时
30 天内合并 PR
3

描述

**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!

贡献指南

这个仓库没有索引到贡献指南

调研方向

Start by running the reported Python and Julia reproduction with Julia 1.10.3, Python 3.9.19, juliacall 0.9.21, and PythonCall v0.9.20. Inspect the conversion behavior around test_pyexec_fn, jl.global_res, and jl.jl_add, comparing the reported Py and Float64 results. Done should mean the inconsistency is explained and the intended conversion behavior is fixed or clearly documented.

由索引模型根据 Issue 内容生成。

评估

技术栈
julia, python
领域
backend
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。