TypeError for handle Bool values in deep call chain.
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
調査の方向性
提供された sequentialfs と custom_score の例を使って、ネストされた Julia-to-Python callback を再現し、その後 src/pyfncall.jl の 43 行目付近と src/pyeval.jl の 12 行目付近を調べてください。直接の callback と sklearn SequentialFeatureSelector 経路を比較し、失敗する呼び出しチェーンで期待される動作を明らかにしてください。
索引モデルが issue の本文から書いたものです。
説明
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}()
- 主要言語
- Julia
- スター
- 1.5k
- フォーク
- 186
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
JuliaPy/PyCall.jl のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
Meta-Issue: Mutli-threading leads to segfaults対応中かも @topolarity が 212 日前に担当しました。 オープン
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
-
Crashes with Julia 1.12 and Revise.jl対応中かも @topolarity が 212 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
JuliaPy/PyCall.jl の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
oxfordcontrol/COSMO.jl#211 ·
-
documentation
難易度 2/5 半日 初心者へのやさしさ 65/100
メンテナーはふだん 6 日以内に返信
-
ARKODE: callbacks that modify `u` throw MethodError on reinit対応中かも @devmotion が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
SciML/Sundials.jl#575 ·
-
broken links in docsオープン
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Tube(N) builds N TubeBase segments of length L/(N−1): total friction/inertia length is N·L/(N−1)対応中かも @ChrisRackauckas-Claude が 1 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
SciML/ModelingToolkitStandardLibrary.jl#525 ·
メンテナーはふだん 1 日以内に返信