TypeError for handle Bool values in deep call chain.
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Tái hiện callback lồng nhau Julia-to-Python bằng ví dụ sequentialfs và custom_score được cung cấp, sau đó kiểm tra src/pyfncall.jl quanh dòng 43 và src/pyeval.jl quanh dòng 12. So sánh callback trực tiếp với đường đi của sklearn SequentialFeatureSelector và xác định hành vi mong đợi cho chuỗi lệnh gọi bị lỗi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Environment:
- Windows 11
- Julia 1.7.3 (2022-05-06)
- PyCall v1.94.1
Hello, when I use PyCall to pass a Julia function into a Python function, it seems that PyCall does not handle the Bool (true & false) values correctly.
The call chain is seemly like this:
JuliaFunA(JuliaFunB())
|
|->Pythonfun(JuliaFunB())
Specifically, I use Python's sklearn.feature_selection.SequentialFeatureSelector to do some feature selection. and in this selector, it gets an argument scoring which is a callable function. So in my Julia code, I use pystring py""" """ to wrap the selector and pass my Julia function into it. Here is my code:
function sequentialfs(mdl, fun, X, y)
X = Array(X)
y = Array(y)
score = fun(mdl, X, y)
# j = fun(y)
py"""
import sklearn.feature_selection as fs
def test(mdl, fun, X, y):
score = fun(mdl, X, y) # situation 1: the fun can run well if been called from here
return score
# sfs = fs.SequentialFeatureSelector(
# mdl,
# n_features_to_select="auto",
# direction="forward",
# scoring=fun # situation 2: the fun cannot run if been passed deeper.
# )
# sfs.fit(X, y)
# return sfs.get_support(indices=true)
"""
score = py"test"(mdl, fun, X, y)
return score
end
function custom_score(estimator, X, y_true)
y_pred = estimator.predict(X) # Python sklearn predict function
score = 1 - sum(abs.(y_pred - y_true)) / length(y_true)
return score
end
iris_X, iris_y = get_some_data()
mdl = function_return_a_sklearn_classifier(iris_X, iris_y)
sequentialfs(mdl, custom_score, iris_X, iris_y)
In situation 1, if the fun (julia -> julia -> Python and run) could be called well, in situation 2, the fun (julia -> julia -> Python -> Python) does not run well, and there is a Python TypeError:
ERROR: PyError ($(Expr(:escape, :(ccall(#= C:\Users\Public\xxxxxx\.julia\dev\PyCall\src\pyfncall.jl:43 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'NameError'>
NameError("name 'true' is not defined")
File "C:\Users\xxxxxx\TongYuan\.julia\dev\PyCall\src\pyeval.jl", line 12, in test
ns = PyDict{String,PyObject}()
- Ngôn ngữ chính
- Julia
- Star
- 1.5k
- Fork
- 186
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của JuliaPy/PyCall.jl
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Meta-Issue: Mutli-threading leads to segfaultsCó thể đã có người làm @topolarity đã nhận 211 ngày trước. Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
-
Crashes with Julia 1.12 and Revise.jlCó thể đã có người làm @topolarity đã nhận 211 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
Tất cả issue của JuliaPy/PyCall.jl
Issue tương tự
-
Chains resumed from `initial_state` take `num_warmup + 1` warm-up stepsCó thể đã có người làm @thevolatilebit đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
TuringLang/AbstractMCMC.jl#220 ·
-
found-by-agent
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
exanauts/SparseDirectSolver.jl#92 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
NumericalEarth/Breeze.jl#1051 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
lu_instance/qr_instance run a full factorization for FixedSizeArraysCó thể đã có người làm @devmotion đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
JuliaArrays/ArrayInterface.jl#510 ·